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

I would like to create a pie chart-shaped polygon with concentric layers like so: I can create this simple object with:

``````from math import sin, cos, radians
from shapely.geometry import Point,LineString

#variables for buffers
coordinates = (0,0)
point = Point(coordinates)
buffers=[]
numberOfCircles=5
pi=3.1415

#create the buffers

#variables for linestrings
centerX = coordinates
centerY = coordinates
coordX=[]
coordY=[]
lines=[]

#create linestrings for circles
for i in xrange(1,361,45):
coordX.append(xCoord)
coordY.append(yCoord)
line = LineString([(centerX,centerY),(xCoord,yCoord)])
lines.append(line)
``````

My question is this:

How can I take multiple shapely objects of different geometries and create a geofile (geojson, shapefile, etc...) so that each section of the "pie" is treated as a separate polygon.

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: 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.exterior.coords)
interior = LinearRing(one)
exterior = LinearRing(list(buffers.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: • Interesting feature of the library, thanks for your help. – camdenl Jan 27 '14 at 21:56