-
-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lasmergespatial fails for non-in-memory rasters #285
Comments
Thank you for reporting. I made a reproducible example and I fixed it as you suggested. This line of code was a very old one. I would not have made such error by now. library(lidR)
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las <- readLAS(LASfile)
shp <- system.file("extdata", "lake_polygons_UTM17.shp", package = "lidR")
lakes <- shapefile(shp)
ref = lidR:::rOverlay(las, 1)
f = tempfile(fileext = ".tif")
rlakes.ram = rasterize(lakes, ref)
inMemory(rlakes.ram)
#> [1] TRUE
writeRaster(rlakes.ram, f)
rlakes.disk = raster(f)
inMemory(rlakes.disk)
#> [1] FALSE
las = lasmergespatial(las, rlakes.ram, "rlake.ram")
las = lasmergespatial(las, rlakes.disk, "rlake.disk")
all(is.na(las$rlake.ram))
#> [1] FALSE
all(is.na(las$rlake.disk))
#> [1] TRUE
all.equal(las$rlake.ram, las$rlake.disk)
#> [1] FALSE Created on 2019-10-01 by the reprex package (v0.3.0) |
Ciao JR,
Everything works when I force the load with Just to understand: the desired behaviour from the your persective is "load in memory and do it"? because in that case a specific warning or note in the wiky could help the user in understanding why he gets |
It is expected to work, please open an issue with a reproducible example. |
If you try and
lasmergespatial
with a raster that isn't in-memory, it fails silently returning NAs.This line:
https://github.com/Jean-Romain/lidR/blob/c02abc6345138b10e6cd223c7dccae56e2fbc986/R/lasmergespatial.r#L218
is the culprit because
raster@data@values[cells]
does not contain the data for non-in-memory rasters:the entirety of that element being:
if
inMemory(landcover)
isFALSE
.I think you can extract the data values by indexing directly by cell number:
(yes this raster is all zeroes at those locations)
and I don't think that gives any efficiency loss to in-memory rasters. It might still be slow for large, non-in-memory rasters but that's the story with large rasters. You could test using
raster::inMemory
and print a warning...SO Question that spotted this with (semi-) reproducible example data:
https://gis.stackexchange.com/questions/337359/classify-point-cloud-from-land-cover-raster-values-with-lidr-in-r/337388#337388
The text was updated successfully, but these errors were encountered: