- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如何在 Cartopy 中绘制美国县边界?
绘制州和国家边界非常简单
ax.add_feature(cfeature.BORDERS.with_scale('50m'))
ax.add_feature(cfeature.STATES.with_scale('50m'))
但我似乎找不到类似的方法来添加县界。这是 Basemap 的优点之一。
最佳答案
考虑到 cartopy 绘制 shapefile 的能力,这个问题基本上可以归结为“我在哪里可以找到美国县的轮廓?”。
Natural Earth 论坛上有人提出了类似的问题 http://www.naturalearthdata.com/forums/topic/u-s-county-shape-file/ .它指向一个位置 http://nationalatlas.gov/mld/countyp.html , 不幸的是有一点点腐烂。快速 Google 建议现在可以在以下位置找到它:
https://nationalmap.gov/small_scale/atlasftp.html?openChapters=chpbound#chpbound
我决定下载其中一个县 shapefile:
有了它,我使用了 cartopy 的 shapereader 来获取几何图形,并创建了一个自定义功能,然后可以将其添加到轴上:
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.io.shapereader as shpreader
import matplotlib.pyplot as plt
reader = shpreader.Reader('countyl010g.shp')
counties = list(reader.geometries())
COUNTIES = cfeature.ShapelyFeature(counties, ccrs.PlateCarree())
plt.figure(figsize=(10, 6))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_feature(cfeature.LAND.with_scale('50m'))
ax.add_feature(cfeature.OCEAN.with_scale('50m'))
ax.add_feature(cfeature.LAKES.with_scale('50m'))
ax.add_feature(COUNTIES, facecolor='none', edgecolor='gray')
ax.coastlines('50m')
ax.set_extent([-83, -65, 33, 44])
plt.show()
这是从 https://scitools.org.uk/cartopy/docs/v0.14/examples/feature_creation.html 的例子派生的它构造一个 NaturalEarthFeature
,而不是一个 ShapelyFeature
,但除此之外,原理几乎相同。
希望对你有用。
关于python - Cartopy 县寄宿生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51106763/
我是一名优秀的程序员,十分优秀!