Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我无法使用Python将坐标导出到shapefile。我的代码中是否存在问题,或者问题是否存在于模块中?_Python_Module_Shapefile - Fatal编程技术网

我无法使用Python将坐标导出到shapefile。我的代码中是否存在问题,或者问题是否存在于模块中?

我无法使用Python将坐标导出到shapefile。我的代码中是否存在问题,或者问题是否存在于模块中?,python,module,shapefile,Python,Module,Shapefile,这是我编写的测试代码: 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') 但是,它不起作用,

这是我编写的测试代码:

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')
但是,它不起作用,我收到一个错误提示:

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
回溯(最近一次呼叫最后一次):
文件“C:\src\Python\coordinates.py”,第33行,在
w=shapefile.Writer(shapefile.POINT)#shapefile.POLYGON)
文件“C:\Python39\lib\site packages\shapefile.py”,第1293行,在\uuu init中__
self.shp=self.\u getFileObj(os.path.splitext(目标)[0]+'.shp')
splitext中第204行的文件“C:\Python39\lib\ntpath.py”
p=os.fspath(p)TypeError:应为str、bytes或os.PathLike对象,而不是int
有什么问题吗?我曾尝试使用其他参数,如“shapefile.POLYGON”,但仍然存在相同的问题。

shapefile.Writer()
希望文件名作为第一个参数,因此您的意思可能是:

w = shapefile.Writer('shapefiles/test/polygon')
你的最后一行应该是

w.close()

是的,如果有效的话,我用的是过时的文档