r-lidar-lab / ALSroads

Road corrections and measurements from ALS data
19 stars 4 forks source link

Error: No such slot: extent #61

Closed jfbourdon closed 1 year ago

jfbourdon commented 1 year ago

I have now an error that seems to be linked to the loaded DTM. The issue is with both RasterLayer and SpatRast format. Tested with the current master (d39fc2c), sf 1.0-8 and lidR 4.0.1

dir  <- system.file("extdata", "", package="ALSroads")
road <- system.file("extdata", "j5gr_centerline_971487.gpkg", package="ALSroads")
dtm  <- system.file("extdata", "j5gr_dtm.tif", package="ALSroads")
ctg  <- lidR::readLAScatalog(dir)
road <- sf::st_read(road, "original", quiet = TRUE)

Using RasterLayer:

dtm  <- raster::raster(dtm)
res <- ALSroads::measure_road(ctg, road, dtm = dtm)
# Error in h(simpleError(msg, call)) : 
# erreur d'�valuation de l'argument 'x' lors de la s�lection d'une m�thode pour la fonction 'extent' : ‘srs’ n'est pas un slot de la classe “BasicRaster”

Using SpatRast:

dtm  <- terra::rast(dtm)
res <- ALSroads::measure_road(ctg, road, dtm = dtm)
# Error: No such slot: extent
Jean-Romain commented 1 year ago

Confirmed for terra. It works for raster. In the meantime the document states that dtm must be a RasterLayer

jfbourdon commented 1 year ago

Humm... the error was with raster 3.6-3. I updated to 3.6-14 and the error is now gone but I have instead a deprecation warning: as(<dsCMatrix>, "dgTMatrix") is deprecated since Matrix 1.5-0; do as(as(., "generalMatrix"), "TsparseMatrix") instead. The result seems ok.

I tried with terra because a saw some calls/check for it in rasterize_conductivity.LAS() and transition(). Looking again, it's clear that only RasterLayer is expected everywhere else in the code. So I guess I just need to keep some packages versions in sync.

Jean-Romain commented 1 year ago

I guess deprecation comes from SparseMatrix so it should comes from `gdistance code as far as I can tell. I didn't investigate yet because it works.

Support of terra is something I should do. But honestly I have other project on the table. Something very nice for you btw and I may do a presentation for mffp someday.