简体   繁体   English

geopandas 世界地图的极地立体投影

[英]Polar Stereographic projection of geopandas world map

I want to use the geopandas included low resolution world map (see here ) as a background for my data.我想使用 geopandas 包含的低分辨率世界地图(见这里)作为我的数据的背景。 This works fine as long as I use eg 'PlateCarree' projection.只要我使用例如“PlateCarree”投影,这就可以正常工作。

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)我的代码看起来像这样(使用 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?知道极地立体投影是否根本不适用于这张地图(如果是,为什么?)还是我做错了什么?

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 ):使用特定的 cartopy 投影进行绘图时,最好使用 cartopy 实际创建 matplotlib 图形和轴,以确保它知道投影(在技术术语中:确保它是GeoAxes ,请参阅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:使用 cartopy add_geometries方法,这更好地尊重范围:

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 ).这乍一看有点奇怪(中间的南极洲很小),但这似乎是意料之中的(参见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一般来说,请参阅文档中关于结合 GeoPandas 和 cartopy 的示例: https ://geopandas.readthedocs.io/en/latest/gallery/cartopy_convert.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM