Plot shapefile city borders on top of cartopy map

前端 未结 1 709
别跟我提以往
别跟我提以往 2021-01-03 12:40

I\'m trying to plot the outline of Bay Area city/town borders on top of a cartopy terrain map using a shapefile obtained here and following this example. For some reason, th

相关标签:
1条回答
  • 2021-01-03 13:00

    As @ImportanceOfBeingErnest and @swatchai suggest, the CRS (coordinate reference system) parameter in ShapelyFeature cartopy.feature.ShapelyFeature() was incorrect.

    The proper EPSG (European Petroleum Survey Group?) code can be found in one of the .xml files included with the shapefile:

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

    and passing this as the second parameter in ShapelyFeature() is all it takes to get the shapefile to plot the city borders properly:

    # 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()
    

    0 讨论(0)
提交回复
热议问题