簡體   English   中英

geopandas 世界地圖的極地立體投影

[英]Polar Stereographic projection of geopandas world map

我想使用 geopandas 包含的低分辨率世界地圖(見這里)作為我的數據的背景。 只要我使用例如“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',)

知道極地立體投影是否根本不適用於這張地圖(如果是,為什么?)還是我做錯了什么?

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

在此處輸入圖片說明

這乍一看有點奇怪(中間的南極洲很小),但這似乎是意料之中的(參見https://scitools.org.uk/cartopy/docs/latest/crs/projections.html#southpolarstereo ) .

一般來說,請參閱文檔中關於結合 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