Reputation: 23
This is the test code I have written:
import 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')
However, it does not work and I am prompted with an error:
Traceback (most recent call last):
File "C:\src\Python\coordinates.py", line 33, in <module>
w = shapefile.Writer(shapefile.POINT) #shapefile.POLYGON)
File "C:\Python39\lib\site-packages\shapefile.py", line 1293, in __init__
self.shp = self.__getFileObj(os.path.splitext(target)[0] + '.shp')
File "C:\Python39\lib\ntpath.py", line 204, in splitext
p = os.fspath(p) TypeError: expected str, bytes or os.PathLike object, not int
What seems to be the problem? I have tried to use other arguments like "shapefile.POLYGON" but the same problem remains.
Upvotes: 2
Views: 775
Reputation: 24243
shapefile.Writer()
expects the filename as first parameter, so what you mean is probably:
w = shapefile.Writer('shapefiles/test/polygon')
and your last line should be instead
w.close()
Upvotes: 1