LoginSignup
6
8

More than 1 year has passed since last update.

geopandas で 世界地図を表示

Last updated at Posted at 2019-12-16

Pythonで地図にプロットしたりしたいなー、と思っていたのですが、先日、geopandasというものがあるのを知りました。私のノートPC(Windows10, Visual Studio Code, python3)にインストールして動いた感じなのでメモします。

naturalearth-lowres.png

Geopandas インストール

最初、pip3 install geopandas としましたが、エラーが出てインストールできず。

  • pip3 を使う。いろいろ問題がありましたが、こちらからエラーが起きたモジュールを入れました。私は、エラーが出たモジュールについて、こちら(Unofficial Windows Binaries for Python Extension Packages)のサイトで最新のものをインストールしました。GDAL, Fiano, Shapely をインストールしました。

  • 実はgeopandas のサイトでインストール方法を調べると、conda を使うように書いてありました。conda はanaconda と関係があるようで、私は初めて知りました。pip でインストールした後、いろいろ提案されるとおりにしたところ、動きました。

$ python -m pip install conda
$ conda update -n base -c defaults conda
$ conda create -n geopandas
$ conda activate geopandas

テスト

以下のプログラムで地図が出てきました。元ネタはこちらです。

import geopandas
import matplotlib.pyplot as plt

world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
print(world.head())
world.plot()
plt.show()

world.head() で以下が出力されます。この world は class geopandas.geodataframe.GeoDataFrame です。

     pop_est      continent                      name iso_a3  gdp_md_est                                           geometry
0     920938        Oceania                      Fiji    FJI      8374.0  MULTIPOLYGON (((180.00000 -16.06713, 180.00000...
1   53950935         Africa                  Tanzania    TZA    150600.0  POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
2     603253         Africa                 W. Sahara    ESH       906.5  POLYGON ((-8.66559 27.65643, -8.66512 27.58948...
3   35623680  North America                    Canada    CAN   1674000.0  MULTIPOLYGON (((-122.84000 49.00000, -122.9742...
4  326625791  North America  United States of America    USA  18560000.0  MULTIPOLYGON (((-122.84000 49.00000, -120.0000...

このファイル(test.py)を python3 test.py とすると、冒頭の画像が表示されました。
いろいろ使えそう。わくわく。(^^)/

以下を参考にさせていただきました。

6
8
1

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
6
8