GeoPandasでの座標参照系(CRS)の扱い

Pythonで扱う地理空間データ

Joris Van den Bossche

Open source software developer and teacher, GeoPandas maintainer

GeoPandasのCRS情報

GeoDataFrame/GeoSeries の .crs 属性:

import geopandas
gdf = geopandas.read_file("countries.shp")
print(gdf.crs)
{'init': 'epsg:4326'}
Pythonで扱う地理空間データ

CRSを手動で設定する

gdf_noCRS = geopandas.read_file("countries_noCRS.shp")
print(gdf_noCRS.crs)
{}

crs にCRS情報を追加:

# Option 1
gdf.crs = {'init': 'epsg:4326'}

# Option 2
gdf.crs = {'proj': 'longlat', 'datum': 'WGS84', 'no_defs': True}
Pythonで扱う地理空間データ

別のCRSへ変換する

import geopandas
gdf = geopandas.read_file("countries_web_mercator.shp")
print(gdf.crs)
{'init': 'epsg:3857', 'no_defs': True}

to_crs() メソッド:

# Option 1
gdf2 = gdf.to_crs({'proj': 'longlat', 'datum': 'WGS84', 'no_defs': True})

# Option 2 gdf2 = gdf.to_crs(epsg=4326)
Pythonで扱う地理空間データ

なぜCRSを変換するのか?

1) 異なるCRSのデータ源

df1 = geopandas.read_file(...)
df2 = geopandas.read_file(...)

df2 = df2.to_crs(df1.crs)
Pythonで扱う地理空間データ

なぜCRSを変換するのか?

1) 異なるCRSのデータ源

2) 地図化(形状・距離の歪み)

Pythonで扱う地理空間データ

なぜCRSを変換するのか?

1) 異なるCRSのデータ源

2) 地図化(形状・距離の歪み)

3) 距離・面積などの計算

Pythonで扱う地理空間データ

どのCRSを選ぶべきか?

ヒント:

  • データの地域に適した投影を使用する
  • 多くの国に標準CRSがある

参考サイト:

Pythonで扱う地理空間データ

まとめ

  • 別のCRSへ変換: to_crs() メソッド
  • 複数データは同一CRSに揃える
  • 距離・面積の計算時は、必ず投影CRSを使う

参考サイト:

Pythonで扱う地理空間データ

練習してみましょう!

Pythonで扱う地理空間データ

Preparing Video For Download...