Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for EPSG:3857 #924

Open
maxnoe opened this issue Aug 15, 2017 · 7 comments
Open

Support for EPSG:3857 #924

maxnoe opened this issue Aug 15, 2017 · 7 comments

Comments

@maxnoe
Copy link

maxnoe commented Aug 15, 2017

http://wiki.openstreetmap.org/wiki/EPSG:3857

This would be really usefull.

@ajdawson
Copy link
Member

I thought that was what cartopy.crs.Mercator.GOOGLE was? Do you need something different?

(see: https://github.com/SciTools/cartopy/blob/master/lib/cartopy/crs.py#L1008)

@maxnoe
Copy link
Author

maxnoe commented Aug 16, 2017

Then it's a matter of documentation

@maxnoe
Copy link
Author

maxnoe commented Aug 16, 2017

How should I as a user have found this?

@ajdawson
Copy link
Member

That's a good question. It is not well documented... Probably worth opening a ticket for this to be documented better.

Another option is to use the cartopy.crs.epsg function (which requires an internet connection) to generate the correct projection directly from the EPSG code:

import cartopy.crs as ccrs
import matplotlib.pyplot as plt

proj = ccrs.epsg(3857)
ax = plt.axes(projection=proj)
ax.coastlines()
plt.show()

@Timothy-W-Hilton
Copy link

Stumbled across this while troubleshooting plotting polygons from a shape file. It appears to me that cartopy.crs.Mercator.GOOGLE and cartopy.crs.epsg(3857) are not the same thing, despite a lot of places on the web stating that the "google projection", "mercator web projection" and EPSG 3857 are one and the same. On my system:

import cartopy.crs as ccrs

print('ccrs.epsg(3857)')
print(ccrs.epsg(3857).proj4_params)

print('ccrs.Mercator.GOOGLE')
print(ccrs.Mercator.GOOGLE.proj4_params)

results in

ccrs.epsg(3857)
{'a': '6378137', 'lat_ts': '0.0', 'lon_0': '0.0', '': None, 'b': '6378137', 'nadgrids': '@null', 'x_0': '0.0', 'wktext': None, 'units': 'm', 'proj': 'merc', 'y_0': '0', 'k': '1.0', 'ellps': 'WGS84', 'no_defs': None}
ccrs.Mercator.GOOGLE
{'a': 6378137.0, 'lon_0': 0.0, 'units': 'm', 'b': 6378137.0, 'k': 1, 'nadgrids': '@null', 'proj': 'merc'}

More significantly, this shape file shows up in slightly different locations depending on which projection I use in this code:

"""modified from https://gis.stackexchange.com/questions/259831/shapefiles-wont-display-with-cartopy
"""

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.io.shapereader as shpreader
import matplotlib.pyplot as plt

fname = r'/Users/tim/work/Data/Redwoods/Redwood_SequoiaSempervirens_extentNorthAmerica/data/commondata/data0/sequsemp.shp'
rw_shapes = list(shpreader.Reader(fname).geometries())

# these two lines cause the shapes to show up in slightly different locations.  ccrs.Mercator.GOOGLE plots correctly; ccrs.epsg(3857) does not.
# proj = ccrs.epsg(3857)
proj = ccrs.Mercator.GOOGLE

fig = plt.figure(figsize=(12, 12))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines(resolution='10m')
states_provinces = cfeature.NaturalEarthFeature(
    category='cultural',
    name='admin_1_states_provinces_lines',
    scale='10m',
    facecolor='none')
ax.add_feature(states_provinces, edgecolor='grey')
ax.add_geometries(geoms=rw_shapes, crs=proj,
                  edgecolor='blue', facecolor='blue')
ax.set_extent((-125, -118, 32, 49.2))
plt.show()

@aurelgriesser
Copy link

aurelgriesser commented Aug 18, 2021

Is there any workaround to not having an internet connection to use cartopy.crs.epsg()? Like with the features (coastlines and such) one can download them manually...

Ta.

@snowman2
Copy link
Contributor

Is there any workaround to not having an internet connection to use cartopy.crs.epsg()?

With #1808, an internet connection is no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants