繁体   English   中英

在Cartopy地图上绘制shapefile城市边界

[英]Plot shapefile city borders on top of cartopy map

我正在尝试使用在此处获得的shapefile并在此示例之后,在Cartopy地形图的顶部绘制湾区城市/城镇边界的轮廓。 由于某些原因,即使我通过zorder指定边框位于顶部,边框也不会显示。 我想念什么吗?

# import functions
import matplotlib.pyplot as plt
import cartopy.io.img_tiles as cimgt
import cartopy.crs as ccrs
from cartopy.io.shapereader import Reader
from cartopy.feature import ShapelyFeature

# Create a Stamen terrain background instance
stamen_terrain = cimgt.Stamen('terrain-background')
fig = plt.figure(figsize = (10, 10))
ax = fig.add_subplot(1, 1, 1, projection=stamen_terrain.crs)

# Set range of map, stipulate zoom level
ax.set_extent([-122.7, -121.5, 37.15, 38.15], crs=ccrs.Geodetic())
ax.add_image(stamen_terrain, 12, zorder = 0)

# Add city borders - not working
filename = r'./shapefile/ba_cities.shp' # from https://earthworks.stanford.edu/catalog/stanford-vj593xs7263
shape_feature = ShapelyFeature(Reader(filename).geometries(), ccrs.PlateCarree(), edgecolor='black')
ax.add_feature(shape_feature, zorder = 1)
plt.show()

没有shapefile边框!为什么?

正如@ImportanceOfBeingErnest和@swatchai所建议的那样, ShapelyFeature cartopy.feature.ShapelyFeature()中的CRS(坐标参考系统)参数不正确。

可以在shapefile随附的.xml文件之一中找到正确的EPSG(欧洲石油调查组织?)代码:

   <gco:CharacterString>26910</gco:CharacterString>
</code>
<codeSpace>
   <gco:CharacterString>EPSG</gco:CharacterString>

并将其作为ShapelyFeature()的第二个参数传递,即可获取shapefile正确绘制城市边界:

# Add city borders
filename = r'./shapefile/ba_cities.shp'
shape_feature = ShapelyFeature(Reader(filename).geometries(), ccrs.epsg(26910), 
                               linewidth = 1, facecolor = (1, 1, 1, 0), 
                               edgecolor = (0.5, 0.5, 0.5, 1))
ax.add_feature(shape_feature)
plt.show()

现在绘制城市边界

暂无
暂无

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

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