Pythonで日本地図の作成に挑戦します。
かなり長編になりますので、
時間のない方は最後まで飛んでいただいて結構です。
国土数値情報ダウンロードサイトから、
全国の行政区域データを入手します。

(下にスクロール)

(行政区域を選択)

(下にスクロール)

(全国をダウンロード)

import geopandas as gpd
gdf = gpd.read_file("/home/yasube873/Python/weather/map/N03-20220101_GML/N03-22_220101.shp")
display(gdf)
最新版(令和4年)をダウンロードしたら、
北海道の支庁区分が表示されないようです。
(N03_002に表示なし)

import geopandas as gpd
gdf = gpd.read_file("/home/yasube873/Python/weather/map/N03-20210101_GML/N03-21_210101.shp")
display(gdf)
表示されました。
(N03_002に表示あり)
Pythonで都道県境と北海道の支庁を表示させるように試みたのですが、
どうにもうまくいかず。
QGISを使うことにします。
インストールしているQGISは、
GMT対応のためバージョンが古いので、
最新のものをインストールします。
(QGISのインストールについては割愛します)

赤枠(四角)ボタンを押下し、
『SHP files(*.shp)』を選択し、
『N03-21_210101』を右クリックし、
マウスカーソルをエクスポートに移動、
『新規ファィルに地物を保存』を選択します。
デスクトップに保存されたgeojsonファイルを
デスクトップのQGISのアイコンにドラッグ&ドロップします。
(地図が表示されるのに、かなり時間がかかります)
以後は繰り返しの作業ですが、
念のため記述します。

エクスプローラーが表示されますので、
指定のフォルダに名前とファイル形式を選択して保存します。
(この段階では保存されません)
(この段階で最初に作業したQGISが開いたままだった場合は閉じてください)
import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
japan = gpd.read_file("/home/yasube873/Python/weather/map/japan_map.shp", encoding='utf-8')
display(japan)
japan = japan[['N03_001','N03_002','N03_007','geometry']]
display(japan)
fig, ax = plt.subplots(figsize = (20,16))
japan.plot(ax=ax, facecolor='white', edgecolor='black', linewidth=0.5)
plt.show()

できました。
琵琶湖や霞ケ浦がないのが気になりますが、
とりあえずここまでで良しとします。
0 件のコメント:
コメントを投稿