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.
Answer
This expands on the answer posted by BradHards:
The error message sounds like pyshp is expecting float
s where it is not getting them. If your coordinate list is a set of int
s, try casting them to float
s:
list = [[1,5],[5,5],[5,1],[3,3],[1,1]]
list = [[float(coord) for coord in pair] for pair in list]
No comments:
Post a Comment