Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

R expanding the extent of a raster causes problems with gdal

$
0
0

I have a set of rasters created from geotiff files with code like the following

fileName <- "data/xxx.yyy.tif"
rasterOutput <- brick(fileName)

Most of the the resulting rasterbricks have an extent of

extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)

But some, such as a RasterBrick called tmax.small, have an extent of

extent : -180, 180, -59.5, 83.5 (xmin, xmax, ymin, ymax)

I'd like to do some math with these but get warning messages about mismatched extents. So I attempt to make them the same.

I create an new extent file globeExtent <- extent(c(-180, 180, -90, 90))

and then run

tmax.observed <- setExtent(tmax.small, ext = globeExtent, keepres = TRUE, snap = TRUE)

The contents of tmax.observed now appear to have the correct extent

tmax.observed

 class      : RasterBrick 
dimensions : 360, 720, 259200, 12  (nrow, ncol, ncell, nlayers)
resolution : 0.5, 0.5  (x, y)
extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)

but when I try to do a math operation such as tmax.observed - [other raster] with another raster having seemingly identical attributes, I get the following error message

Error in rgdal::getRasterData(con, offset = offs, region.dim = reg, band = b) : Failure during raster IO

Next I try gdalinfo(tmax.observed) to see if I can get more info on this message. I get the following error message. I can't figure out what file or directory it is looking for.

ERROR 4: brick(ncol=720, nrow=360, nl=12, xmn=-180, xmx=180, ymn=-90, ymx=90, crs='+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0'): No such file or directory
gdalinfo failed - unable to open 'brick(ncol=720, nrow=360, nl=12, xmn=-180, xmx=180, ymn=-90, ymx=90, crs='+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0')'.
character(0)
attr(,"status")
[1] 1
Warning message:
In system(cmd, intern = TRUE) :
  running command '"/usr/local/Cellar/gdal/2.4.2_3/bin/gdalinfo""brick(ncol=720, nrow=360, nl=12, xmn=-180, xmx=180, ymn=-90, ymx=90, crs='+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0')"' had status 1

I'm feeling a certain amount of floundering. Any advice greatly appreciated!

Session info added below

R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.2

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] data.table_1.12.8   sf_0.8-0            rgeos_0.5-2         gdalUtils_2.0.1.14  rgdal_1.4-8        
 [6] ncdf4.helpers_0.3-3 PCICt_0.5-4.1       ncdf4_1.17          raster_3.0-7        sp_1.3-2           
[11] devtools_2.2.1      usethis_1.5.1      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3             compiler_3.6.1         class_7.3-15           R.methodsS3_1.7.1-9000
 [5] R.utils_2.9.2          iterators_1.0.12       prettyunits_1.0.2      remotes_2.1.0         
 [9] tools_3.6.1            testthat_2.3.1         digest_0.6.23          pkgbuild_1.0.6        
[13] pkgload_1.0.2          memoise_1.1.0          lattice_0.20-38        rlang_0.4.2           
[17] foreach_1.4.7          DBI_1.0.0              cli_2.0.0              rstudioapi_0.10       
[21] parallel_3.6.1         e1071_1.7-3            withr_2.1.2            desc_1.2.0            
[25] fs_1.3.1               classInt_0.4-2         rprojroot_1.3-2        grid_3.6.1            
[29] glue_1.3.1             R6_2.4.1               processx_3.4.1         fansi_0.4.0           
[33] sessioninfo_1.1.1      callr_3.4.0            magrittr_1.5           units_0.6-5           
[37] backports_1.1.5        ps_1.3.0               codetools_0.2-16       ellipsis_0.3.0        
[41] assertthat_0.2.1       KernSmooth_2.23-16     crayon_1.3.4           R.oo_1.23.0           
> 

Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>