Home > Back-end >  st_crop on pacific centred naturalearth world map
st_crop on pacific centred naturalearth world map

Time:11-18

Im trying to crop a pacific centred world map using the naturalearth maps data as an sf object. The map was created following pacific centered map

I would like to crop to an area of interest covering the Indian and Pacific Oceans (like this screenshot taken from the "maps" world2 projection):

desired crop extent

To crop, I tried the following:


world4 <- st_crop(world3, c(xmin= 30, ymin = -40, xmax = 230, ymax = 40))


However, the code above produces the incorrect crop with crazy small lat/long increments:

ggplot(data = world3, aes(group = admin))  
  geom_sf(fill = "grey")

too small?!

If anyone can help me to figure out how to crop using lat and long to define the area for this pacific centred map it would be greatly apriciated. I know that there are other ways to obtain a pacific centred map but the future planned analysis for this project requires it to be an rnaturalearth map.

CodePudding user response:

The problem with your code is that you need to define the bbox for the crop filter using the same CRS as the world3 object. For example:

world4 <- st_crop(
  x = world3, 
  y = st_as_sfc(
    st_bbox(c(xmin= 30, ymin = -40, xmax = 230, ymax = 40), crs = 4326)
  ) %>% st_transform(target_crs)
)
#> Warning: attribute variables are assumed to be spatially constant throughout all
#> geometries
ggplot(data = world4, aes(group = admin))  
  geom_sf(fill = "grey")

  • Related