Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 1.67 KB

Create a pie shaped object in shapely and export to gis polygon object.md

File metadata and controls

45 lines (33 loc) · 1.67 KB

from create a pie shaped object in shapely and export to gis polygon object

You should use Fiona and the mapping function of shapely

    from shapely.geometry import mapping
    import fiona
    # schema of the shapefile (or GeoJSON file, or...) for the lines
    schema = {'geometry': 'LineString','properties': {'test': 'int'}}
    with fiona.open('lines.shp','w','ESRI Shapefile', schema) as e:
       for i in lines:
           e.write({'geometry':mapping(i), 'properties':{'test':1}})

Result:

enter image description here

You can do the same thing with the buffers but you'll never get a ring polygon as result with your solution (only a superposition of polygons)

You need to use the solution given by MappaGnosis in Does shapely within function identify inner holes?

    one = list(buffers[1].exterior.coords)
    interior = LinearRing(one)
    exterior = LinearRing(list(buffers[2].exterior.coords)
    ring = Polygon(exterior,[interior])
    #  new schema
    schema = {'geometry': 'Polygon','properties': {'test': 'int'}}
    # write the shapefile
    with fiona.open('ring.shp','w','ESRI Shapefile', schema) as e:
        e.write({'geometry':mapping(ring), 'properties':{'test':1}})

Result: enter image description here