12
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonで世界地図-26(各国の県境・市町村境を表示)

Last updated at Posted at 2018-08-08

####各国の国境線・県境・市町村境のダウンロード
https://gadm.org/download_country_v3.html
Country を選択する。
Shapefile をクリックする。

BaseMapの場合

#!/usr/bin/python3
# coding: UTF-8

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

font = {'family':'IPAGothic'} #日本語Fontを指定

#fname = 'gadm36_JPN_shp/gadm36_JPN_0' #国境線のみ
fname1 = 'gadm36_JPN_shp/gadm36_JPN_1' #県境
fname2 = 'gadm36_JPN_shp/gadm36_JPN_2' #市町村境

lon1 = 137.50 #japanの場合
lat1 = 34.5
lon2 = 12.5
lat2 = 12.5

map = Basemap(llcrnrlon=lon1-lon2,llcrnrlat=lat1-lat2,urcrnrlon=lon1+lon2,urcrnrlat=lat1+lat2,resolution='h',projection='cyl', area_thresh = 100.0)

map.drawcoastlines() #海岸線が重複する。他国の国境線・海岸線が必要な時は先頭の#を削除する。resolution='h'にする。(非常に時間がかかる)

#map.drawcountries() #国境線
#map.drawmapboundary(fill_color='aqua')
map.fillcontinents(color='cyan')

map.readshapefile(fname2, 'prefectural_bound2', color='gray', linewidth=.5) #市町村境
map.readshapefile(fname1, 'prefectural_bound1', color='black', linewidth=.8) #県境

plt.title('日本', **font,fontsize=15)

plt.show()

image.png

cartopyの場合

#!/usr/bin/python3
# coding: UTF-8

import cartopy.crs as ccrs
import cartopy.io.shapereader as shpreader
import matplotlib.pyplot as plt

font = {'family':'IPAGothic'} #日本語Fontを指定

#fname = 'gadm36_JPN_shp/gadm36_JPN_0.shp' #国境線のみ
fname1 = 'gadm36_JPN_shp/gadm36_JPN_1.shp' #県境
fname2 = 'gadm36_JPN_shp/gadm36_JPN_2.shp' #市町村境

adm1_shapes = list(shpreader.Reader(fname1).geometries())
adm2_shapes = list(shpreader.Reader(fname2).geometries())

ax = plt.axes(projection=ccrs.PlateCarree())

plt.title('日本', **font)
#ax.coastlines(resolution='10m') #海岸線が重複する。他国の海岸線が必要な時は先頭の#を削除する。

ax.add_geometries(adm2_shapes, ccrs.PlateCarree(),
                  edgecolor='gray', facecolor='cyan',  alpha=0.5) #市町村境
ax.add_geometries(adm1_shapes, ccrs.PlateCarree(),
                  edgecolor='black',alpha=0.5) #県境

ax.set_extent([125, 150, 22, 47], ccrs.PlateCarree()) #[lon1,lon2,lat1,lat2] #japanの場合

plt.show()

image.png

12
7
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
12
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?