Skip to main content
edited tags
Link
Aaron
  • 51.8k
  • 29
  • 157
  • 322
Edit code formatting
Source Link

I have tried to check whether making a stackstack would work:

grid_snap <- stack(habi_sdw, Pop_sdw)

grid_snap <- stack(habi_sdw, Pop_sdw)

show(habi_sdw) class : RasterLayer dimensions : 9187, 9717, 89270079 (nrow, ncol, ncell) resolution : 0.00892857, 0.00892857 (x, y) extent : -28.83706, 57.92186, -36.02464, 46.00214 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs data source : C:\Users\di39\AppData\Local\Temp\R_raster_di39\raster_tmp_2015-08-12_172902_12860_17067.grd names : layer values : 0, 333707.6 (min, max)

show(habi_sdw)
# class       : RasterLayer 
# dimensions  : 9187, 9717, 89270079  (nrow, ncol, ncell)
# resolution  : 0.00892857, 0.00892857  (x, y)
# extent      : -28.83706, 57.92186, -36.02464, 46.00214  (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs 
# data source : C:\Users\di39\AppData\Local\Temp\R_raster_di39\raster_tmp_2015-08-12_172902_12860_17067.grd 
# names       : layer 
# values      : 0, 333707.6  (min, max)

show(Pop_sdw)
# class       : RasterLayer 
# dimensions  : 10143, 8858, 89846694  (nrow, ncol, ncell)
# resolution  : 0.008333333, 0.008333333  (x, y)
# extent      : -17.53524, 56.28143, -46.97893, 37.54607  (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
# data source : C:\Users\di39\AppData\Local\Temp\R_raster_di39\raster_tmp_2015-08-12_170421_12860_12760.grd 
# names       : pop2010ppp 
# values      : 0, 128925.9  (min, max)

show(Pop_sdw) class : RasterLayer dimensions : 10143, 8858, 89846694 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -17.53524, 56.28143, -46.97893, 37.54607 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 data source : C:\Users\di39\AppData\Local\Temp\R_raster_di39\raster_tmp_2015-08-12_170421_12860_12760.grd names : pop2010ppp values : 0, 128925.9 (min, max) Using alignExtent() in the raster package seems not to be the correct approach.

Using alignExtent() in the raster package seems not to be the correct approach.

I have tried to check whether making a stack would work:

grid_snap <- stack(habi_sdw, Pop_sdw)

show(habi_sdw) class : RasterLayer dimensions : 9187, 9717, 89270079 (nrow, ncol, ncell) resolution : 0.00892857, 0.00892857 (x, y) extent : -28.83706, 57.92186, -36.02464, 46.00214 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs data source : C:\Users\di39\AppData\Local\Temp\R_raster_di39\raster_tmp_2015-08-12_172902_12860_17067.grd names : layer values : 0, 333707.6 (min, max)

show(Pop_sdw) class : RasterLayer dimensions : 10143, 8858, 89846694 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -17.53524, 56.28143, -46.97893, 37.54607 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 data source : C:\Users\di39\AppData\Local\Temp\R_raster_di39\raster_tmp_2015-08-12_170421_12860_12760.grd names : pop2010ppp values : 0, 128925.9 (min, max) Using alignExtent() in the raster package seems not to be the correct approach.

I have tried to check whether making a stack would work:

grid_snap <- stack(habi_sdw, Pop_sdw)
show(habi_sdw)
# class       : RasterLayer 
# dimensions  : 9187, 9717, 89270079  (nrow, ncol, ncell)
# resolution  : 0.00892857, 0.00892857  (x, y)
# extent      : -28.83706, 57.92186, -36.02464, 46.00214  (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs 
# data source : C:\Users\di39\AppData\Local\Temp\R_raster_di39\raster_tmp_2015-08-12_172902_12860_17067.grd 
# names       : layer 
# values      : 0, 333707.6  (min, max)

show(Pop_sdw)
# class       : RasterLayer 
# dimensions  : 10143, 8858, 89846694  (nrow, ncol, ncell)
# resolution  : 0.008333333, 0.008333333  (x, y)
# extent      : -17.53524, 56.28143, -46.97893, 37.54607  (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
# data source : C:\Users\di39\AppData\Local\Temp\R_raster_di39\raster_tmp_2015-08-12_170421_12860_12760.grd 
# names       : pop2010ppp 
# values      : 0, 128925.9  (min, max)

Using alignExtent() in the raster package seems not to be the correct approach.

Source Link
DI1
  • 311
  • 1
  • 2
  • 4

Snapping raster grids in R

I am trying to align two raster grids in R. Once aligned I would like to be able to add them together.

I have tried to check whether making a stack would work:

grid_snap <- stack(habi_sdw, Pop_sdw)

And I get the following error:

Error in compareRaster(x) : different extent

The raster grids have the following properties:

show(habi_sdw) class : RasterLayer dimensions : 9187, 9717, 89270079 (nrow, ncol, ncell) resolution : 0.00892857, 0.00892857 (x, y) extent : -28.83706, 57.92186, -36.02464, 46.00214 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs data source : C:\Users\di39\AppData\Local\Temp\R_raster_di39\raster_tmp_2015-08-12_172902_12860_17067.grd names : layer values : 0, 333707.6 (min, max)

show(Pop_sdw) class : RasterLayer dimensions : 10143, 8858, 89846694 (nrow, ncol, ncell) resolution : 0.008333333, 0.008333333 (x, y) extent : -17.53524, 56.28143, -46.97893, 37.54607 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 data source : C:\Users\di39\AppData\Local\Temp\R_raster_di39\raster_tmp_2015-08-12_170421_12860_12760.grd names : pop2010ppp values : 0, 128925.9 (min, max) Using alignExtent() in the raster package seems not to be the correct approach.

Do I need to resample because the resolutions are slightly different?

(0.00892857 x 0.00892857) vs (0.008333333 vs 0.008333333)