Accessing equal earth projection with sf

Viewed 88

I'm a little confused why I'm not able to iplement the equal earth projection using sf in R, or how to diagnose why this is.

When I check my crs options with sf_proj_info("proj") it appears as an option.

But if whenever I try to implement it with st_crs("+proj=eqearth") or st_crs("eqearth") I'm told that it is an invalid crs.

Am I misunderstanding whether this is an available option? implementing it incorrectly for transforming/projecting? Or all of the above?

Just trying to display the whole earth without grossly distorting areas near the poles...

2 Answers

It works for me using sp, give or take some warnings:

> library(sf)
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1; sf_use_s2() is TRUE
> library(sp)
> library(rnaturalearth)
> coast = ne_coastline(returnclass="sp")
> 
> coast_eq = spTransform(coast, "+proj=eqearth")
Warning messages:
1: In spTransform(xSP, CRSobj, ...) :
  NULL source CRS comment, falling back to PROJ string
2: In wkt(obj) : CRS object has no comment
> plot(coast_eq)

And one glitchy coordinate that has popped over to the wrong side of the -180 line:

enter image description here

You could then convert this to an sf class with coast_sf = st_as_sf(coast_eq).

But I don't understand the root cause yet...

You may want to update your PROJ version; I am running this code with 8.2.1 and it seems to work as expected...

library(sf)
library(giscoR) # for the world dataset

sf_extSoftVersion()
#          GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H           PROJ 
#      "3.10.2"        "3.4.1"        "8.2.1"         "true"         "true"        "8.2.1" 

world <- gisco_countries %>% 
  st_geometry() # no data are required...

# ugly!
plot(world)

enter image description here

a_better_world <- world %>% 
  st_transform(crs = "+proj=eqearth")

# much nicer!
plot(a_better_world)

enter image description here

Related