LoginSignup
2
3

More than 5 years have passed since last update.

Pythonで世界地図-19(世界の町のシェープファイルを取得)

Last updated at Posted at 2018-07-17

参考
osmnx/osmnxTest.py
https://github.com/smnra/osmnx/blob/master/osmnxTest.py

get_city_shp.py
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import osmnx as ox
import matplotlib.pyplot as plt
import sys

args = sys.argv
argc = len(args) # 引数の個数

if (argc != 2):   # 引数がない場合
    print ('./get_city_shp.py 目的地の名称')
    quit()


cityName = args[1] #'HigashiOsaka','tokyo,Japan'
city = ox.gdf_from_place(cityName)
city.plot()

ox.save_gdf_shapefile(city,cityName,'./data') #dataフォルダに保存

plt.show()

$ ./get_city_shp.py HigashiOsaka

image.png

実行したフォルダのdataフォルダにHigashiOsakaフォルダが作成され、
HigashiOsaka.cpg HigashiOsaka.prj HigashiOsaka.shx
HigashiOsaka.dbf HigashiOsaka.shp
が保存される。

引数cityNameの例
HigashiOsaka
Tokyo,Japan
雁塔区,西安,中国
"Manhattan, New York, USA"
引数にスペースが含まれる場合は、コーテーションマークで括る

上記で取得したシェープファイルを利用する
#!/usr/bin/python3
# coding: UTF-8

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import japan_border2 as jb2 #都府県境界線

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

lon1 = 135.50
lat1 = 34.5
lon2 = 1.0
lat2 = 1.0

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

map.drawcoastlines() #海岸線

jb2.prefectural_bound(map = map) #都府県境界線

map.readshapefile('/home/ty/python/map/OSMnx/data/HigashiOsaka/HigashiOsaka', 'counties', color ='m')

lon = 135.6009
lat = 34.6793
plt.plot(lon, lat, 'ro', markersize=2, color='red')
plt.text(lon, lat, " 東大阪市役所", fontsize=12, color='red', **font)

print(map.counties)

plt.show()

image.png

2
3
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
2
3