2017-06-13 4 views
0

最近、matplotlibとBasemapを使用してPythonで地図を作成しました。何らかの理由で、.shpが見つからないため、m.readshapefile()を実行するとコードが壊れます。.shpを読み取るreadshapefile()を取得できません

thisの.zipをダウンロードし、デスクトップのC:\ Users \ mattd \ Desktop \ pop \ ne_110m_populated_placesに配置しました。私は入れます

m.readshapefile('C:\Users\mattd\Desktop\pop\ne_110m_populated_places', 
      'populated_places') 

これはファイルを見つけることができないため、破損することはできません。

+0

[最小限で完全で検証可能な例を作成する](https://stackoverflow.com/help/mcve) – Skam

答えて

0

添付したリンクには、populated_places というファイルがありませんでした。ne_110m_populated_places.shpが見つかりました。また、ライブラリに依存するのではなく、自分の変数の名前を自分のコードで行い、サニティチェックを行うのもよい方法です。

from os import path 

shape_dir = 'C:\Users\mattd\Desktop\pop\ne_110m_populated_places' 
shape_file = 'ne_110m_populated_places' 
shape_file_full = shape_file + '.shp' 

# check if we provided valid paths to our file and directory 
if path.isdir(shape_dir) is False: 
    print ("%s does not exist!" % (shape_dir)) 
    quit() 

if path.isfile(shape_file_fill) is False: 
    print ("%s does not exist" % (shape_file_full)) 
    quit() 

# if it makes it here then you know it's an issue with the library 
base_map = Basemap(...) 
base_map.readshapefile(shape_dir, shape_file) 
関連する問題