-1

我目前正在使用 PySal 库,我正在使用 queen_from_shapefile() 函数,并且 Python 会为某些 shp 返回一个错误,而对于其他的则可以完美地工作。所有 shapefile 都以相同的方式创建。它们是区域 shapefile。

有错误:

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    graph(1850,117)
  File "C:\Users\jbeverag\Desktop\graph_queen_fonction.py", line 37, in graph
    qW = ps.queen_from_shapefile(str(planche)+".shp")
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\weights\user.py", line 67, in queen_from_shapefile
    w = Queen.from_shapefile(shapefile, idVariable=idVariable)
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\weights\Contiguity.py", line 255, in from_shapefile
    w = cls(iterable, ids=ids, id_order=id_order, **kwargs)
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\weights\Contiguity.py", line 199, in __init__
    criterion=criterion, method=method)
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\weights\Contiguity.py", line 383, in _build
    neighbor_data = ContiguityWeightsPolygons(polygons, wttype=wttype).w
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\weights\_contW_binning.py", line 68, in __init__
    self.do_weights()
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\weights\_contW_binning.py", line 98, in do_weights
    shpObj = self.collection[i]
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\core\FileIO.py", line 162, in __getitem__
    return self.by_row.__getitem__(key)
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\core\FileIO.py", line 145, in __getitem__
    return self.p.get(key)
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\core\FileIO.py", line 269, in get
    obj = self.__read()
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\core\FileIO.py", line 312, in __read
    row = self._read()
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\core\IOHandlers\pyShpIO.py", line 142, in _read
    rec = self.dataObj.get_shape(self.pos)
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\core\util\shapefile.py", line 362, in get_shape
    return self.shape.unpack(bufferIO(self.fileObj.read(byts)))
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\core\util\shapefile.py", line 633, in unpack
    record = _unpackDict(cls.USTRUCT, dat)
  File "C:\Users\jbeverag\AppData\Local\Programs\Python\Python36\lib\site-packages\pysal\core\util\shapefile.py", line 136, in _unpackDict
    fileObj.read(struct['size']))
struct.error: unpack requires a buffer of 44 bytes

谢谢你的帮助,

拉咖啡

4

1 回答 1

-2

重建 shp 文件解决了问题,但我不知道问题的根源是什么

于 2018-03-20T13:08:42.217 回答