gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 08:03:16 24 4
gpt4 key购买 nike

我想使用 geopandas 包含的低分辨率世界地图(请参阅 here )作为我的数据的背景。只要我使用例如,这就可以正常工作“PlateCarree”投影。

如果我现在想使用极地立体投影

ccrs.NorthPolarStereo()

ccrs.SouthPolarStereo()

它不起作用。

我的代码如下所示(使用 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',)

你知道极地立体投影是否不适用于这张 map (如果是的话为什么?)或者我做错了什么?

最佳答案

使用特定的 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')

但是,这似乎仍然绘制了超出范围的形状。使用 cartopy add_geometries 方法,可以更好地尊重范围:

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

enter image description here

乍一看有点奇怪(中间的南极洲很小),但这似乎是预料之中的(参见 https://scitools.org.uk/cartopy/docs/latest/crs/projections.html#southpolarstereo )。

一般来说,请参阅文档中结合 GeoPandas 和 cartopy 的示例:https://geopandas.readthedocs.io/en/latest/gallery/cartopy_convert.html

关于python - geopandas世界地图的极地立体投影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55646598/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com