Create closed polygon from boundary points

后端 未结 3 1984
盖世英雄少女心
盖世英雄少女心 2021-01-13 02:45

I have an array of longitude-latitude points that defines the boundaries of an area. I would like to create a polygon based on these points and plot the polygon on a map and

3条回答
  •  迷失自我
    2021-01-13 03:35

    There is a blog post here which talks about shapefiles and basemap: http://www.geophysique.be/2013/02/12/matplotlib-basemap-tutorial-10-shapefiles-unleached-continued/

    If you're keen to try it out, cartopy might also be an option. Plotting data from a shapefile is designed to be fairly easy:

    import matplotlib.pyplot as plt
    
    import cartopy.crs as ccrs
    import cartopy.io.shapereader as shpreader
    
    # pick a shapefile - Cartopy makes it easy to access Natural Earth
    # shapefiles, but it could be anything
    shapename = 'admin_1_states_provinces_lakes_shp'
    states_shp = shpreader.natural_earth(resolution='110m',
                                          category='cultural', name=shapename)
    

    .

    # states_shp is just a filename to a shapefile
    >>> print states_shp
    /Users/pelson/.local/share/cartopy/shapefiles/natural_earth/cultural/110m_admin_1_states_provinces_lakes_shp.shp
    

    .

    # Create the mpl axes of a PlateCarree map
    ax = plt.axes(projection=ccrs.PlateCarree())
    
    # Read the shapes from the shapefile into a list of shapely geometries.
    geoms = shpreader.Reader(states_shp).geometries()
    
    # Add the shapes in the shapefile to the axes
    ax.add_geometries(geoms, ccrs.PlateCarree(),
                      facecolor='coral', edgecolor='black')
    
    plt.show()
    

    output

提交回复
热议问题