r-lidar / lidR

Airborne LiDAR data manipulation and visualisation for forestry application
https://CRAN.R-project.org/package=lidR
GNU General Public License v3.0
601 stars 131 forks source link

error with rasterize_terrain on LAScatalog #561

Closed Jean-Romain closed 2 years ago

Jean-Romain commented 2 years ago

Originally posted by JonBatch in https://github.com/r-lidar/lidR/discussions/560 April 4, 2022

Hello, when running the following code:

ctg<-readLAScatalog("datasetsA/king_county_2016/laz/")
TILEdtm <- rasterize_terrain(ctg,res=30,algorithm = tin())

on lidar tiles downloaded from the Washington DNR lidar portal I am getting this error:

ctg<-readLAScatalog("datasetsA/king_county_2016/laz/")
#> Be careful, some tiles seem to overlap each other. lidR may return incorrect outputs with edge artifacts when processing this catalog.
TILEdtm <- rasterize_terrain(ctg,res=30,algorithm = tin())
#> Processing [==================================>-----------------------------------]  50% (1/2) eta: 43s
#> Error in parse(text = x@definition) : <text>:1:1405: unexpected symbol
#> 1: ",north,ORDER[2],LENGTHUNIT["metre",1]],USAGE[SCOPE["Engineering survey, topographic mapping."],AREA["United States (USA) - Washington - counties of Adams; Asotin; Benton; Clark; Columbia; Cow

I had been using grid_terrain and I am trying to update workflows per the suggestions in the lidR documentation however, grid_terrain works and I can't seem to get rasterize_terrain to work on a LAScatalog. Am I missing some additional input required for rasterize_terrain?

I have tried adjacent tiles from 3 different acquisitions on two different machines and I have gotten the same error. I have run this code in the past (using 'grid_terrain') with no issues at all. I assume that perhaps with the recent updates to lidR that something has changed? I also assume that the error is related to user-defined information included in the laz header. To reproduce the error you should be able to download any two adjacent tiles from the 2016 king county lidar aquistion over Seattle.

Jean-Romain commented 2 years ago

Minimal reproducible error without lidR

crs = sf::st_crs(32149)
r = terra::rast(nrows = 10, ncols = 10, xmin = 0, xmax = 100, ymin = 0, ymax = 100)
r = terra::init(r, fun = runif)
terra::crs(r) = "EPSG:32149"
r <- terra::wrap(r)
r <- terra::rast(r)
#> Erreur dans parse(text = x@definition) : <text>:1:1388: symbole inattendu
#> 1: ",north,ORDER[2],LENGTHUNIT["metre",1]],USAGE[SCOPE["Engineering survey, topographic mapping."],AREA["United  States (USA) - Washington - counties of Adams; Asotin; Benton; Clark; Columbia; Cow                          

This is a bug with serialisation in terra. I'll investigate a bit later and report to terra

Jean-Romain commented 2 years ago

Fixed in terra https://github.com/rspatial/terra/issues/602