Cartopy中的县边界

10
你如何在Cartopy中绘制美国县边界?
绘制州和国家边界非常简单。
ax.add_feature(cfeature.BORDERS.with_scale('50m'))
ax.add_feature(cfeature.STATES.with_scale('50m'))

但是我似乎找不到与添加县界限类似的方法。这是Basemap中的一个不错的特点。

1个回答

12

考虑到cartopy可以绘制shapefile,这个问题基本上归结为“我在哪里可以找到美国县的轮廓?”。

自然地球论坛上曾经有一个类似的问题http://www.naturalearthdata.com/forums/topic/u-s-county-shape-file/。它指向了http://nationalatlas.gov/mld/countyp.html,但不幸的是,这个网站已经出现了一些问题。一个快速的谷歌搜索建议现在可以在以下位置找到:

https://nationalmap.gov/small_scale/atlasftp.html?openChapters=chpbound#chpbound

我决定下载其中一个县级行政区划文件:

https://prd-tnm.s3.amazonaws.com/StagedProducts/Small-scale/data/Boundaries/countyl010g_shp_nt00964.tar.gz

有了这个设置,我使用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()

US counties

这是从https://scitools.org.uk/cartopy/docs/v0.14/examples/feature_creation.html示例中衍生出来的,该示例构建了一个NaturalEarthFeature而不是ShapelyFeature,但原则上基本相同。
希望对您有用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接