This article was written as the 17th day article of ISer Advent Calendar 2020.
It can be downloaded from the following national land numerical information download site. https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-N05-v1_3.html
Draw a route map using N05-19_RailroadSection2.geojson in the folder.
Use the Python module json. It will parse automatically. Super convenient.
import json
import numpy as np
import matplotlib.pyplot as plt
json_open = open('N05-19_RailroadSection2.geojson', 'r', encoding = 'utf_8_sig')
json_load = json.load(json_open)
For the time being, this time we will only target Tokyo Metro lines.
Of the lines whose operating company is the Tokyo subway, it pulls the data in coordinates. This is the data showing the route as a polygonal line.
rc = {
    'Line 2 Hibiya Line' : '#b5b5ac',
    'Line 3 Ginza Line' : '#ff9500',
    'Line 4 Marunouchi Line' : '#f62e36',
    'Line 4 Marunouchi Line Branch Line' : '#f62e36',
    'Line 5 Tozai Line' : '#009bbf',
    'Line 7 Namboku Line' : '#00ac9b',
    'Line 8 Yurakucho Line' : '#c1a470',
    'Line 9 Chiyoda Line' : '#00bb85',
    'Line 11 Hanzomon Line' : '#8f76d6',
    'Line 13 Fukutoshin Line' : '#9c5e31'
}
for railway_data in json_load['features']:
    if  railway_data['properties']['Operating company'] == 'Tokyo subway':
        segments = railway_data['geometry']['coordinates']
        x, y = [], []
        for xy in segments:
            x.append(xy[0])
            y.append(xy[1])
        plt.plot(np.array(x), np.array(y), color = rc[railway_data['properties']['Route name']])
The route map created in this way is here.

-Read JSON in Python -Subway symbol color Metro Colors
Recommended Posts