1

I've downloaded a world map and want to change it from the default CRS (EPSG:4326) to the WGS 84 / Pseudo-Mercator projection used in applications like Tableau and Google Maps (EPSG:3857). For some reason, when I attempt the transformation, the longitude and latitude numbers become inflated.

For example, (-95.160, -95.102) becomes (-10593226.108, -10586797.584)

library(rnaturalearth)
library(dplyr)
library(sf)

target_crs <- st_crs(3857)

# Use the United States as an example
US <- ne_countries(scale = 10, type = "countries", returnclass = "sf") %>%
  filter(admin == "United States of America") %>%
  select(admin, geometry) 

head(US)

#Simple feature collection with 1 feature and 1 field
#Geometry type: MULTIPOLYGON
#Dimension:     XY
#Bounding box:  xmin: -179.1435 ymin: 18.90612 xmax: 179.7809 ymax: 71.4125
#CRS:           +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
#                     admin                       geometry
#1 United States of America MULTIPOLYGON (((-95.16057 4...

# Now attempt to transform the CRS
US <- st_transform(US, target_crs)

head(US)

#Simple feature collection with 1 feature and 1 field
#Geometry type: MULTIPOLYGON
#Dimension:     XY
#Bounding box:  xmin: -19942160 ymin: 2143886 xmax: 20013120 ymax: 11544810
#Projected CRS: WGS 84 / Pseudo-Mercator
#                     admin                       geometry
#1 United States of America MULTIPOLYGON (((-10593226 6...

Notice the massive change in the xmin, ymin, xmax, ymax values. I'm not sure what's causing this.

Obed
  • 403
  • 3
  • 12
  • 1
    The values look ok. See this https://epsg.io/3857 – Dave2e Jan 25 '22 at 00:46
  • Maybe `st_crs(US) <- 3857`. – cuttlefish44 Jan 25 '22 at 01:18
  • 1
    @Dave2e, you're right, the values (in meters) are OK. It turns out I was attempting to intersect the 3857 projection with a 4326 projection later in my code. As defuneste mentions in their answer, 3857 is in meters and 4326 is in degrees, so the intersection didn't work. When I properly transformed the 4326 projection then my intersection started working properly. – Obed Jan 25 '22 at 13:46

1 Answers1

2

3857 is in meter and 4326 are in degree. Are you close to peter island ?

You can test your coords here if needed : https://epsg.io/map#srs=3857&x=-10093891.770199&y=-10709420.049722&z=12&layer=streets

defuneste
  • 376
  • 2
  • 7