4

Using R software, I want to modify the attached raster in order to visualize it centered on the Pacific Ocean. Indeed, I need to show the entire Oceania: in my opinion I have to shift from (-180,180) to (0,360)...

Coud you provide me the appropriate code?

Plot to modify

  • How did you generate the image in you question? Could you post the R code? – Marco Dec 29 '17 at 12:50
  • The raster was not produced by me, but downloaded from a website holding some raster shapefiles. The image I posted simply derives from the plot() function. If helpful, I can post the summay information of this raster. – Marco Dec 29 '17 at 12:59
  • You need a raster centered on the Pacific Ocean. Please, see my answer. – xunilk Dec 29 '17 at 13:33
5

The raster package has a function rotate for the opposite problem (go from 0 - 360 to -180 - 180), but not for this one. However, you can do it like this:

Example data

library(raster)
library(maptools)
data(wrld_simpl)
r <- rasterize(wrld_simpl, raster())

Cut in two pieces, change the extent of the western hemisphere, and merge again.

x1 <- crop(r, extent(-180, 0, -90, 90))
x2 <- crop(r, extent(0, 180, -90, 90))   
extent(x1) <- c(180, 360, -90, 90)
m <- merge(x1, x2)

This assumes a well behaved global raster with edges at -180, and 180 and the zero meridian being in between two columns.

  • Excellent! It works perfectly. I'm impressed by your solution: rapid, simple and extremely efficient. Thank you – Marco Dec 29 '17 at 21:12
1

Download this png image (world_c.png); that is a Cylindrical Equidistant Projection of world (2048×1024) centered on the Pacific Ocean.

enter image description here

With gdal_translate assign desired projection (latitude: -90, 90; longitude: 0, 360):

gdal_translate -a_srs WGS84 -a_ullr 0 90 360 -90 world_c.png geoworld_c.tif

Afterward in R:

> library(raster)
Loading required package: sp
> geoworld <- raster("geoworld_c.tif")
> plot(geoworld)

and you have raster displayed as centered on the Pacific Ocean.

enter image description here

  • Ok, thank you for your clear answer. I'll try it (I'm not familiar with rgdal, I have to learn it) and I'll inform you very soon about the outcome. But, is not possible to apply a method for my native raster? Many thanks – Marco Dec 29 '17 at 14:11
  • I tried. Unfortunately, I want to show a focus on Oceania continent and the raster has not sufficient resolution form my aims. I would like to convert rasters available at: naturalearthdata.com/downloads/50m-raster-data/… – Marco Dec 29 '17 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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