rgeospatialrastershapefileextent

Change a shapefile from longitude display (-180, 180) to (0, 360) in R


I am trying to crop a raster file (ERA dataset) (9x9 km grid on an hourly basis for the entire world) by the extents of the shapefile of Chile.

The raster has a longitude display of (0,360) and the shapefile has a longitude display of (-180,180); this means that the extents don't match and therefore I have to change either one of these files. I tried to use raster::rotate to change the extents of the raster but it is taking a lot of time.

I thought that a faster way would be to instead change the extents of the shapefile. Could you please tell me how I can switch the shapefile extents of the longitudes from (-180,180) to (0,360)?

For reference:

extent(ch_shp)
#class      : Extent 
#xmin       : -109.455 
#xmax       : -66.41472 
#ymin       : -55.98403 
#ymax       : -17.50755 

extent(ras)
#class      : Extent 
#xmin       : -0.05 
#xmax       : 359.95 
#ymin       : -90.05 
#ymax       : 90.05 

Thank you!


Solution

  • With terra, you can adjust the vector data with shift, or the more general rotate.

    library(terra)
    v <- vect("chile.shp")
    s <- shift(v, 360)
    

    or

    r <- rotate(v, left=FALSE)