[GIS] Creating Polygon Shapefile from list of X,Y coordinates using Python

pyshppythonshapefile

I have a list of X,Y coordinates from a csv file, that represent a polygon. I´m trying to create a Polygon-Shapefile from this list. I´ve been trying around and found a possbility to write the list to a Point-Shapefile.

Unfortunately that is not enough for me. Is there any way to get the coordinates in a Polygon-shapefile straight away?

Following Brad´s suggestions I tried the following code:

for i in list:
    w = shapefile.Writer(shapefile.POLYGON)
    w.poly(parts=[list])
    w.field('F_FLD','C','40')
    w.field('S_FLD','C','40')
    w.record('First','Polygon')
    w.save('C:/Users/.../Desktop/Shape')

Unfortunately I´m getting an error message:

ShapefileException: Failed to write shapefile bounding box. Floats required.

Looks like there is a problem saving the shapefile to disk.
This seems to be a similar question, but I couldn´t work out, how to get it going in my case.

Best Answer

From the pyshp documentation page:

>>> # Create a polygon shapefile
>>> w = shapefile.Writer(shapefile.POLYGON)
>>> w.poly(parts=[[[1,5],[5,5],[5,1],[3,3],[1,1]]])
>>> w.field('FIRST_FLD','C','40')
>>> w.field('SECOND_FLD','C','40')
>>> w.record('First','Polygon')
>>> w.save('shapefiles/test/polygon')

Just substitute your list for the parts= argument to Writer.poly, and set whatever fields you would like to associate with your shapefile.