Polar Stereographic projection of geopandas world map

会有一股神秘感。 提交于 2019-12-14 02:29:38

问题


I want to use the geopandas included low resolution world map (see here) as a background for my data. This works fine as long as I use e.g. 'PlateCarree' projection.

If I now want to use a polar stereographic peojection

ccrs.NorthPolarStereo()

or

ccrs.SouthPolarStereo()

It does not work.

My code looks like this (using python 3)

import geopandas as gpd
import cartopy.crs as ccrs

crs = ccrs.NorthPolarStereo()
crs_proj4 = crs.proj4_init
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
w = world.to_crs(crs_proj4)
w.plot(facecolor='sandybrown', edgecolor='black',)

Any idea if polar stereographic projections simply do not work for this map (if so why?) or am I doing something wrong?


回答1:


When plotting with a specific cartopy projection, it is best to actually create the matplotlib figure and axes using cartopy, to make sure it is aware of the projection (in technical terms: to make sure it is a GeoAxes, see https://scitools.org.uk/cartopy/docs/latest/matplotlib/intro.html):

crs = ccrs.SouthPolarStereo()
crs_proj4 = crs.proj4_init
w = world.to_crs(crs_proj4)

fig, ax = plt.subplots(subplot_kw=dict(projection=crs))
w.plot(ax=ax, facecolor='sandybrown', edgecolor='black')

However, this still seems to plot the shapes that fall outside of the extent. Using the cartopy add_geometries method, this better respects the extent:

fig, ax = plt.subplots(subplot_kw=dict(projection=crs))
ax.add_geometries(w['geometry'], crs=crs, facecolor='sandybrown', edgecolor='black')

This looks a bit strange at first sight (Antartica in the middle is very small), but this seems to be expected (see https://scitools.org.uk/cartopy/docs/latest/crs/projections.html#southpolarstereo).

In general, see the example on combining GeoPandas and cartopy in the docs: https://geopandas.readthedocs.io/en/latest/gallery/cartopy_convert.html



来源:https://stackoverflow.com/questions/55646598/polar-stereographic-projection-of-geopandas-world-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!