【发布时间】:2017-12-22 23:27:26
【问题描述】:
我目前正在学习 Joel Lawhead 编写的 Python 地理空间分析教程,但在尝试编辑 shapefile 时遇到了错误。
我正在使用的 shapefile 可以通过 http://git.io/vLd8Y 获得。我在 python3 上的 Jupyter Notebook 中运行我的代码。
这是我的代码。我只是将 shapefile 读取为 Reader 对象r,并创建一个新的 Writer 对象w,其 shapetype 与r 相同。然后,我尝试将记录从r 附加到w。
import shapefile
r = shapefile.Reader("NYC_MUSEUMS_GEO")
w = shapefile.Writer(r.shapeType)
w.fields = list(r.fields)
w.records.extend(r.records())
但是,我遇到了这个错误:
AttributeError Traceback (most recent call last)
<ipython-input-151-ceee096fbafa> in <module>()
6 w = shapefile.Writer(r.shapeType)
7 w.fields = list(r.fields)
----> 8 w.records.extend(r.records())
AttributeError: 'Writer' object has no attribute 'records'
有什么想法吗?
【问题讨论】:
-
这是 PyShp 2 的一个变化。我无法使 PyShp 2 编写器对象工作,因此恢复为 pip install
pyshp==1.2.12w.records.extend(r.records())工作。