Geographic Information Systems Asked on January 3, 2021
i am using terra::raster 0.9-1
and, specifically terra::resample
, but whenever i resample/reproject a surface, i get what appears to be the minimum floating point value as the default fill/NA value
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
other attached packages:
[1] terra_0.9-1 gdalUtils_2.0.3.2 geosphere_1.5-10 data.table_1.13.0 ggplot2_3.3.2 dplyr_1.0.2
[9] rgdal_1.5-16 rgeos_0.5-3 stringr_1.4.0 raster_3.3-13 sp_1.4-4 devtools_2.3.1
# as i cannot make a dummy rast, due to being unable to set values, you'll have to take my word for it
# https://gis.stackexchange.com/questions/377839/r-terra-and-error-in-xptrgeometrynlyrs-could-not-find-valid-method
r <- rast("C:/Path/BNG_raster.tif")
crs(r) <- "epsg:27700"
latlon.grid <- rast(xmin = 0, xmax = 5, ymin = 50, ymax = 55, resolution = 0.01, crs = "epsg:4326", vals = NA)
r.resam <- terra::resample(r, latlon.grid, method="cubic")
> r.resam
class : SpatRaster
dimensions : 50, 50, 1 (nrow, ncol, nlyr)
resolution : 0.01, 0.01 (x, y)
extent : 0, 5, 50, 55 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs
data source : memory
names : my_reprojected_raster
min values : -3.4e+38
max values : 95.97936
you can see the min value defaults to the minimum floating point value. The following do not change that;
terra::resample(r, uk.latlon.grid.wkt, method="cubic", background=NA)
terra::resample(r, uk.latlon.grid.wkt, method="cubic", wopt=list(NAflag=NA))
terra::resample(r, uk.latlon.grid.wkt, method="cubic", wopt=list(NAflag=0))
That in itself is ok but then subsequent raster algebra operations recognize the -3.4e+38 as a value. Is there a best practice for dealing with NA in terra? i was used to raster
in which NA was just NA.
the best result i have is to write out at the raster at the same time (similar to gdalwarp);
test <- terra::resample(r, uk.latlon.grid.wkt, method="cubic", filename="E:/samT/dump/eire_S3_LL_terra.tif", wopt=list(NAflag=NA), overwrite=T, wopt=list(gdal=c("COMPRESS=LZW")))
> test
class : SpatRaster
dimensions : 50, 50, 1 (nrow, ncol, nlyr)
resolution : 0.01, 0.01 (x, y)
extent : 0, 5, 50, 55 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs
data source : memory
names : my_reprojected_raster
min values : -5.59
max values : 95.97936
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP