{"id":397,"date":"2021-04-22T14:45:49","date_gmt":"2021-04-22T21:45:49","guid":{"rendered":"https:\/\/blogs.ubc.ca\/tdeenik\/?p=397"},"modified":"2021-04-27T12:26:07","modified_gmt":"2021-04-27T19:26:07","slug":"calculating-grid-statistics-with-lidr","status":"publish","type":"post","link":"https:\/\/blogs.ubc.ca\/tdeenik\/2021\/04\/22\/calculating-grid-statistics-with-lidr\/","title":{"rendered":"Calculating Grid Statistics with lidR"},"content":{"rendered":"<p style=\"text-align: center;\">So far I have been working only with the LiDAR-derived DEM for calculating my topographic indices (TWI and TPI). For the <strong>Grid Statistics<\/strong>, I will be using the raw LiDAR point cloud (.las or in my case .laz files since they are compressed). There are many ways we can summarize this data and what I need to figure out is which are useful for mapping wetlands. Here is a list of grid statistics previously used for mapping wetlands or characterizing vegetation (note: z = elevation, i = intensity, std = standard deviation, max = maximum, and min = minimum):<\/p>\n<p style=\"text-align: center;\">Corcoran et al. (2015) used z-std, z-max, z-min and z-mean as well as i-std, i-max, i-min, and i-mean for their wetland classification. Intensity can been used as a correlation between wetness and soil moisture. Their results showed that <strong>z-std, z-max, i-mean, i-min and i-deviation<\/strong> ranked particularly high for variable importance.<\/p>\n<p style=\"text-align: center;\">In a study by Millard and Richardson (2013), they used standard deviation of all hits to approximate for height of vegetation; standard deviation of ground hits as a proxy for hummocky peatlands; the ratio between all hits and ground hits to indicate canopy density; ground hit intensity for flat surfaces\/open water; and the density of all hits for their model. They found <strong>z-std, ratio of all hits to ground hits, and the density of all hits (d)<\/strong> to rank high in importance. They also concluded that intensity could not be used to distinguish between wetland classes.<\/p>\n<p style=\"text-align: center;\">In Hopkinson et al. study from 2006, these authors suggest that <strong>z-std<\/strong> provided an important metric for estimating vegetation height. In forest environments, there is a greater standard deviation due to distribution of returns from LiDAR (Millard and Richardson 2013). Millard and Richardson (2013) also found reduced standard deviation within bogs containing little\/no tall vegetation.<\/p>\n<p style=\"text-align: center;\">The<strong> coefficient of variation<\/strong> (standard deviation divided by the mean) can be used as a measure of texture, which can reveal landscape structural patterns that are characteristic of different wetland types.<\/p>\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><strong>Calculating grid metrics from LiDAR data using lidR in R<\/strong><\/span><\/p>\n<p style=\"text-align: center;\">Grid statistics are an area-based calculation for each pixel. I used the package lidR in R to calculate the following grid statistics: zmin, zmax, zmean, zstd, imin, imax, imean, istd. I chose to start with these simpler calculations to get a handle on how the package worked before calculating more complicated metrics such as the ratio of all hits to ground hits, coefficient of variation and density.<\/p>\n<p style=\"text-align: center;\">In order to run grid metrics using the lidR package, you must specify the resolution (in this case I used 10m), the data you are using (z, i, classification, return number, etc.), and the output file name (more on this later as it outputs as a data stack).<\/p>\n<p style=\"text-align: center;\">There are several important settings to understand when using the lidR package and working with a large las catalogue. My notes and R-code can be viewed <a href=\"https:\/\/blogs.ubc.ca\/tdeenik\/files\/2021\/04\/Grid-stats-r-markdown_html.pdf\"><span style=\"color: #ff00ff;\">here<\/span>.<\/a> In addition, some useful documents and online help pages can be found at the links below.<\/p>\n<p style=\"text-align: center;\"><strong>LiDAR basics:<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.neonscience.org\/resources\/learning-hub\/tutorials\/lidar-basics\">https:\/\/www.neonscience.org\/resources\/learning-hub\/tutorials\/lidar-basics<\/a><\/p>\n<p style=\"text-align: center;\"><strong>LiDAR BC specs:<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www2.gov.bc.ca\/assets\/gov\/data\/geographic\/digital-imagery\/geobc_lidar_specifications_v40.pdf\">https:\/\/www2.gov.bc.ca\/assets\/gov\/data\/geographic\/digital-imagery\/geobc_lidar_specifications_v40.pdf<\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.asprs.org\/wp-content\/uploads\/2010\/12\/LAS_1_4_r13.pdf\">https:\/\/www.asprs.org\/wp-content\/uploads\/2010\/12\/LAS_1_4_r13.pdf<\/a><\/p>\n<p style=\"text-align: center;\"><strong>LAS catalogue how to:<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/jean-romain.github.io\/lidRbook\/engine.html\">https:\/\/jean-romain.github.io\/lidRbook\/engine.html<\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/rdrr.io\/cran\/lidR\/man\/catalog_retile.html\">https:\/\/rdrr.io\/cran\/lidR\/man\/catalog_retile.html<\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/gis.stackexchange.com\/questions\/308843\/calculating-standard-metrics-in-multiple-lidar-files-with-lidr-2-0\">https:\/\/gis.stackexchange.com\/questions\/308843\/calculating-standard-metrics-in-multiple-lidar-files-with-lidr-2-0<\/a><\/p>\n<p style=\"text-align: center;\"><strong>lidR package:<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/cran.r-project.org\/web\/packages\/lidR\/lidR.pdf\">https:\/\/cran.r-project.org\/web\/packages\/lidR\/lidR.pdf<\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/github.com\/Jean-Romain\/lidR\/blob\/master\/vignettes\/lidR-LAS-class.Rmd\">https:\/\/github.com\/Jean-Romain\/lidR\/blob\/master\/vignettes\/lidR-LAS-class.Rmd<\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/jean-romain.github.io\/lidRbook\/engine2.html\">https:\/\/jean-romain.github.io\/lidRbook\/engine2.html<\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/cran.r-project.org\/web\/packages\/lidR\/vignettes\/lidR-LAScatalog-class.html\">https:\/\/cran.r-project.org\/web\/packages\/lidR\/vignettes\/lidR-LAScatalog-class.html<\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/cran.r-project.org\/web\/packages\/lidR\/vignettes\/lidR-LAScatalog-engine.html#filter-points\">https:\/\/cran.r-project.org\/web\/packages\/lidR\/vignettes\/lidR-LAScatalog-engine.html#filter-points<\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/jean-romain.github.io\/lidRbook\/aba.html\">https:\/\/jean-romain.github.io\/lidRbook\/aba.html<\/a><\/p>\n<p style=\"text-align: center;\"><strong>Overlapping scans:<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/gis.stackexchange.com\/questions\/270961\/open-source-approach-to-classifying-and-removing-lidar-points-from-overlapping-s\">https:\/\/gis.stackexchange.com\/questions\/270961\/open-source-approach-to-classifying-and-removing-lidar-points-from-overlapping-s<\/a><\/p>\n<p style=\"text-align: center;\"><strong>Future package:<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.r-bloggers.com\/2020\/09\/future-1-19-1-making-sure-proper-random-numbers-are-produced-in-parallel-processing\/\">https:\/\/www.r-bloggers.com\/2020\/09\/future-1-19-1-making-sure-proper-random-numbers-are-produced-in-parallel-processing\/<\/a><\/p>\n<p style=\"text-align: center;\"><strong>Parallel computing:<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/rdrr.io\/cran\/lidR\/man\/lidR-parallelism.html\">https:\/\/rdrr.io\/cran\/lidR\/man\/lidR-parallelism.html<\/a><\/p>\n<p style=\"text-align: center;\"><strong>Trying to understand random numbers:<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/stackoverflow.com\/questions\/61781599\/why-random-number-generation-using-parallel-processing-makes-different-results-e\">https:\/\/stackoverflow.com\/questions\/61781599\/why-random-number-generation-using-parallel-processing-makes-different-results-e<\/a><\/p>\n<p style=\"text-align: center;\"><strong>Grid metrics:\u00a0<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/rdrr.io\/cran\/lidR\/man\/grid_metrics.html\">https:\/\/rdrr.io\/cran\/lidR\/man\/grid_metrics.html<\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.rdocumentation.org\/packages\/lidR\/versions\/1.2.1\/topics\/grid_metrics\">https:\/\/www.rdocumentation.org\/packages\/lidR\/versions\/1.2.1\/topics\/grid_metrics<\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/gis.stackexchange.com\/questions\/310834\/filtering-lasfilter-on-huge-lidar-dataset\/310847#310847\">https:\/\/gis.stackexchange.com\/questions\/310834\/filtering-lasfilter-on-huge-lidar-dataset\/310847#310847<\/a><\/p>\n<p style=\"text-align: center;\"><strong>Naming each metric:<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/gis.stackexchange.com\/questions\/347064\/keeping-name-of-metrics-as-band-names-when-using-grid-metrics-lidr\">https:\/\/gis.stackexchange.com\/questions\/347064\/keeping-name-of-metrics-as-band-names-when-using-grid-metrics-lidr<\/a><\/p>\n<p style=\"text-align: center;\"><strong>Working with rasters in R:<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.neonscience.org\/resources\/learning-hub\/workshops\/work-lidar-derived-rasters-r\">https:\/\/www.neonscience.org\/resources\/learning-hub\/workshops\/work-lidar-derived-rasters-r<\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.neonscience.org\/resources\/learning-hub\/workshops\/hands-primer-working-big-data-r-introduction-hierarchical-data\">https:\/\/www.neonscience.org\/resources\/learning-hub\/workshops\/hands-primer-working-big-data-r-introduction-hierarchical-data<\/a><\/p>\n<p style=\"text-align: center;\"><strong>References<\/strong>:<\/p>\n<p style=\"text-align: center;\">Corcoran, J., Knight, J., Pelletier, K., Rampi, L., &amp; Wang, Y. (2015). The Effects of Point or Polygon Based Training Data on RandomForest Classification Accuracy of Wetlands. <em>Remote Sensing<\/em>, <em>7<\/em>(4), 4002\u20134025. https:\/\/doi.org\/10.3390\/rs70404002.<\/p>\n<div class=\"csl-bib-body\">\n<div class=\"csl-entry\" style=\"text-align: center;\">Hopkinson, C., Chasmer, L., Lim, K., Treitz, P., &amp; Creed, I. (2006). Towards a universal lidar canopy height indicator. <i>Canadian Journal of Remote Sensing<\/i>, <i>32<\/i>(2), 139\u2013152.<\/div>\n<\/div>\n<p style=\"text-align: center;\">Jean-Romain Roussel and David Auty (2021). Airborne LiDAR Data Manipulation and Visualization for Forestry Applications. R package version 3.1.0. https:\/\/cran.r-project.org\/package=lidR<\/p>\n<p style=\"text-align: center;\">Millard, K., &amp; Richardson, M. (2013). Wetland mapping with LiDAR derivatives, SAR polarimetric decompositions, and LiDAR\u2013SAR fusion using a random forest classifier. <em>Canadian Journal of Remote Sensing<\/em>, <em>39<\/em>(4), 290\u2013307.<\/p>\n<p style=\"text-align: center;\">Roussel, J.R., Auty, D., Coops, N. C., Tompalski, P., Goodbody, T. R. H., S\u00e1nchez Meador, A., Bourdon, J.F., De Boissieu, F., Achim, A. (2020). lidR : An R package for analysis of Airborne Laser Scanning (ALS) data. Remote Sensing of Environment, 251 (August), 112061. doi:10.1016\/j.rse.2020.112061.<\/p>\n<p style=\"text-align: center;\">\n","protected":false},"excerpt":{"rendered":"<p>So far I have been working only with the LiDAR-derived DEM for calculating my topographic indices (TWI and TPI). For the Grid Statistics, I will be using the raw LiDAR point cloud (.las or in my case .laz files since<span class=\"ellipsis\">&hellip;<\/span><\/p>\n<div class=\"read-more\"><a href=\"https:\/\/blogs.ubc.ca\/tdeenik\/2021\/04\/22\/calculating-grid-statistics-with-lidr\/\">Read more &#8250;<\/a><\/div>\n<p><!-- end of .read-more --><\/p>\n","protected":false},"author":70819,"featured_media":486,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-397","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs"],"_links":{"self":[{"href":"https:\/\/blogs.ubc.ca\/tdeenik\/wp-json\/wp\/v2\/posts\/397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ubc.ca\/tdeenik\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ubc.ca\/tdeenik\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/tdeenik\/wp-json\/wp\/v2\/users\/70819"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/tdeenik\/wp-json\/wp\/v2\/comments?post=397"}],"version-history":[{"count":17,"href":"https:\/\/blogs.ubc.ca\/tdeenik\/wp-json\/wp\/v2\/posts\/397\/revisions"}],"predecessor-version":[{"id":571,"href":"https:\/\/blogs.ubc.ca\/tdeenik\/wp-json\/wp\/v2\/posts\/397\/revisions\/571"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/tdeenik\/wp-json\/wp\/v2\/media\/486"}],"wp:attachment":[{"href":"https:\/\/blogs.ubc.ca\/tdeenik\/wp-json\/wp\/v2\/media?parent=397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ubc.ca\/tdeenik\/wp-json\/wp\/v2\/categories?post=397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ubc.ca\/tdeenik\/wp-json\/wp\/v2\/tags?post=397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}