0

I want to create a raster grid in Lambert Azimuth Equal Area projection. I need to work within the raster and sp packages, and I need to work in LAEA projection. However, when creating my raster, my raster cell sizes appear to be the same regardless of what resolution I define. This is not the case if I work in WGS, but it is the case if I work in UTM

library(raster)

## create a raster in LAEA
ras = raster(ext=extent(c(-665870.2, 452829.8, -643224., 357575.7), res=c(10000000, 10000000)))
#Warning message: In extent(c(-665870.2, 452829.8, -643224, 357575.7), res = c(1e+07,  :   more elements than expected (should be 4)
ras[] <- 1
projection(ras) <- "+proj=aeqd +lat_0=-51.71475 +lon_0=-61.313002 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
ras

#class      : RasterLayer 
#dimensions : 180, 360, 64800  (nrow, ncol, ncell)
#resolution : 3107.5, 5559.998  (x, y)
#extent     : -665870.2, 452829.8, -643224, 357575.7  (xmin, xmax, ymin, ymax)
#crs        : +proj=aeqd +lat_0=-51.71475 +lon_0=-61.313002 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs 
#source     : memory
#names      : layer 
#values     : 1, 1  (min, max)

## Now choose a different resolution
ras = raster(ext=extent(c(-665870.2, 452829.8, -643224., 357575.7 ), res=c(10,10))) 
#Warning message:In extent(c(-665870.2, 452829.8, -643224, 357575.7), res = c(10,  :   more elements than expected (should be 4)
ras[] <- 1
projection(ras) <- "+proj=aeqd +lat_0=-51.71475 +lon_0=-61.313002 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
ras

## It's the same!!!
#class      : RasterLayer 
#dimensions : 180, 360, 64800  (nrow, ncol, ncell)
#resolution : 3107.5, 5559.998  (x, y)
#extent     : -665870.2, 452829.8, -643224, 357575.7  (xmin, xmax, ymin, ymax)
#crs        : +proj=aeqd +lat_0=-51.71475 +lon_0=-61.313002 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs 
#source     : memory
#names      : layer 
#values     : 1, 1  (min, max)

Perhaps this is to do with the warning message? The same message appears if I build a raster in UTM. I haven't been able to find out why this warning message shows up; it doesn't appear if I work in WGS, and the rasters are different with different specified resolutions, as you would expect:

library(raster)

## create a raster in WGS
ras = raster(ext=extent(c(-69.5, -56, -56, -49)), res=c(1,1)) 
ras[] <- 1
projection(ras) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
ras

#class      : RasterLayer 
#dimensions : 7, 14, 98  (nrow, ncol, ncell)
#resolution : 1, 1  (x, y)
#extent     : -69.5, -55.5, -56, -49  (xmin, xmax, ymin, ymax)
#crs        : +proj=longlat +datum=WGS84 +no_defs 
#source     : memory
#names      : layer 
#values     : 1, 1  (min, max)

## Now choose a different resolution
ras = raster(ext=extent(c(-69.5, -56, -56, -49)), res=c(0.1,0.1)) 
ras[] <- 1
projection(ras) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
ras

#class      : RasterLayer 
#dimensions : 70, 135, 9450  (nrow, ncol, ncell)
#resolution : 0.1, 0.1  (x, y)
#extent     : -69.5, -56, -56, -49  (xmin, xmax, ymin, ymax)
#crs        : +proj=longlat +datum=WGS84 +no_defs 
#source     : memory
#names      : layer 
#values     : 1, 1  (min, max)
2
  • I'm really having a hard time trying to figure out what you're doing. Can you provide more details?
    – Pointdump
    Jul 23, 2022 at 22:55
  • I am doing a kernel density analysis of seabird tracking data using adehabitatHR package. This analysis should be done in LAEA projection. The inputs for the model is (a) the seabird tracks (b) a smoother, and (c) a grid across which the utilisation distribution is modelled. I want the grid to be at a resolution of 10 km.
    – user303287
    Jul 24, 2022 at 10:07

1 Answer 1

3

If you define the CRS while creating the raster, this issue will be solved.

Try the following code

library(raster)
## create a raster in LAEA
r_ext = extent(c(-665870.2, 452829.8, -643224., 357575.7))
r_res = 10
r_crs = "+proj=aeqd +lat_0=-51.71475 +lon_0=-61.313002 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
ras = raster(ext=r_ext, res=c(r_res, r_res),
             crs = r_crs)
print(ras)
2
  • Oh wow! That certainly seems to do the trick - thank you so much! So just to clarify - a resolution of 10 is 10 m, correct? I found this last night, where I realised that the raster has to be built differently in UTM/LAEA projection. neonscience.org/resources/learning-hub/tutorials/… You have just confirmed this and provided a much more simple answer
    – user303287
    Jul 24, 2022 at 10:13
  • Yes unit of the resolution is same as the unit of projection/CRS being used.
    – S. Thiyaku
    Jul 24, 2022 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.