LoginSignup
1
1

More than 3 years have passed since last update.

UbuntuのPythonでcartopyで地図を描くまでの準備

Last updated at Posted at 2021-03-20

国内任意の緯軽度に×を書くためにcartopyを使おうとしたのですが、一箇所コード修整した末の達成でした。

XXX.png

PROJ.4が必要

Cartopyは、pip install cartopyすればすぐ使わるわけではなく、事前にPROJ.4をインストールしておく必要がありました。PROJ.4のインストール方法は「Compile and Install Ubuntu」に示されている方法を参考にしました。
cartopyの最新版をインストールするためには、PROJ.4は4.9(4.8ではない)にしておく必要が有りました。

$ mkdir ~/temp && cd ~/temp
$ svn co http://svn.osgeo.org/metacrs/proj/branches/4.9/proj/
$ wget http://download.osgeo.org/proj/proj-datumgrid-1.5.zip
$ mv proj-datumgrid-1.5.zip proj/nad
$ cd proj/nad
$ unzip proj-datumgrid-1.5.zip
$ cd ..
# ライブラリはユーザ・ディレクトリ下にインストールする
$ ./configure --prefix=/home/devel/.local
$ make -j4
$ make install
# /etc/ld.so.confに/home/devel/.local/libを追加する
$ sudo ldconfig

ソースを修整

私の手元の環境(末尾に詳細)ではcartopyを利用した地図描画プログラムの実行時に以下のエラーに遭遇しました。

AttributeError: 'FeatureArtist' object has no attribute 'get_axes'

これを避けるためには、一部cartopyのソースを変更する必要がありました。修正方法は、「海洋研究のための Python 〜AttributeError: 'FeatureArtist' object has no attribute 'get_axes'〜」や「AttributeError: 'PolyCollection' object has no attribute 'get_axes' #76」を参考にさせてもらいました。

feature_artist.pyオリジナル(修正前)
ax = self.get_axes()
feature_artist.py修正後
ax = self.axes

参考

環境

  • Ubuntu: 18.04.5 LTS (Bionic Beaver)
  • Python 3.6.9
  • PROJ.4: 4.9.0
$ pip freeze
Cartopy==0.18.0
certifi==2020.12.5
cycler==0.10.0
Cython==0.29.22
kiwisolver==1.3.1
matplotlib==3.3.4
numpy==1.19.5
Pillow==8.1.2
pkg-resources==0.0.0
pyparsing==2.4.7
PyQt5==5.15.4
PyQt5-Qt5==5.15.2
PyQt5-sip==12.8.1
pyshp==2.1.3
python-dateutil==2.8.1
scipy==1.5.4
Shapely==1.7.1
six==1.15.0

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1