2017-12-22 19 views
0

現在、Joel LawheadのPython地理空間解析チュートリアルの本を読んでいます。シェイプファイルを編集しようとするとエラーが発生します。新しいWriterオブジェクトを使ってPythonのシェープファイルを編集していません。

私が使用しているシェイプファイルはhttp://git.io/vLd8Yです。私はPython3のJupyter Notebookで自分のコードを実行しています。

これは私のコードです。私は単純にシェイプファイルをReaderオブジェクトrとして読み込み、新しいライターオブジェクトwを同じシェイプタイプ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' 

任意のアイデアはなぜですか?

答えて

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バージョンを行いますか?そうでない場合、環境の特定の詳細を含めるように質問を更新できますか?

関連する問題