2017-12-22 39 views
0

저는 현재 Joel Lawhead의 Python 지형 공간 분석 자습서를보고 있는데 쉐이프 파일을 편집하려고 할 때 오류가 발생합니다.새로운 Writer 객체를 통해 Python의 쉐이프 파일을 편집 할 수 없습니다.

사용중인 shapefile은 http://git.io/vLd8Y입니다. Jupyter Notebook에서 python3으로 코드를 실행하고 있습니다.

이것은 내 코드입니다. 나는 단순히 셰이프 파일을 Reader 개체 r으로 읽고, wr 같은 셰이프 유형을 가진 새로운 Writer 개체를 만듭니다. 그런 다음 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' 

어떤 아이디어 왜?

답변

0

설명 된 문제를 재현 할 수 없습니다. 나는 시작 :

$ python 
Python 3.5.4 (default, Oct 9 2017, 12:07:29) 
>>> 

그리고 pyshp 모듈 설치 :

$ pip install pyshp 
... 
Successfully installed pyshp-1.2.12 

그리고 지금 :

$ python 
Python 2.7.13 (default, Dec 1 2017, 09:21:53) 
[GCC 6.4.1 20170727 (Red Hat 6.4.1-1)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import shapefile 
>>> r = shapefile.Reader("NYC_MUSEUMS_GEO") 
>>> w = shapefile.Writer(r.shapeType) 
>>> w.fields = list(r.fields) 
>>> w.records.extend(r.records()) 
>>> len(w.records) 
130 

당신은 내가 무엇을 사용하고 일치 작업중인 pythonpyshp 버전 수행을? 그렇지 않다면 환경의 특정 세부 사항을 포함하도록 질문을 업데이트 할 수 있습니까?