I tried to draw a route map with Python

This article was written as the 17th day article of ISer Advent Calendar 2020.

raw data

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.

Read JSON

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)

Route map output

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. tokyometro.png

reference

-Read JSON in Python -Subway symbol color Metro Colors

Recommended Posts

I tried to draw a route map with Python
I tried to automatically generate a password with Python3
[Patent analysis] I tried to make a patent map with Python without spending money
I tried a functional language with Python
I made a Hex map with Python
[5th] I tried to make a certain authenticator-like tool with python
[2nd] I tried to make a certain authenticator-like tool with python
[3rd] I tried to make a certain authenticator-like tool with python
[Python] A memo that I tried to get started with asyncio
I tried to create a list of prime numbers with python
I tried to make a periodical process with Selenium and Python
I tried to make a 2channel post notification application with Python
I tried to make a todo application using bottle with python
[4th] I tried to make a certain authenticator-like tool with python
[1st] I tried to make a certain authenticator-like tool with python
Try to draw a life curve with python
I want to make a game with Python
I tried to get CloudWatch data with Python
I tried to output LLVM IR with Python
I tried to automate sushi making with python
I want to write to a file with Python
I tried fp-growth with python
I tried scraping with Python
Python: I tried to make a flat / flat_map just right with a generator
I tried to communicate with a remote server by Socket communication with Python.
I tried to draw a system configuration diagram with Diagrams on Docker
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
I tried to discriminate a 6-digit number with a number discrimination application made with python
[Outlook] I tried to automatically create a daily report email with Python
I tried gRPC with Python
I tried scraping with python
I tried to build a Mac Python development environment with pythonz + direnv
I tried to create a table only with Django
[Python] How to draw a line graph with Matplotlib
I tried to implement Minesweeper on terminal with python
I tried to get started with blender python script_Part 01
I tried to touch the CSV file with Python
I tried to solve the soma cube with python
I tried to implement a pseudo pachislot in Python
I tried to get started with blender python script_Part 02
I tried to implement an artificial perceptron with python
I want to work with a robot in python.
I tried to solve the problem with Python Vol.1
I tried to analyze J League data with Python
I want to run a quantum computer with Python
[Python] How to draw a scatter plot with Matplotlib
I tried to draw a configuration diagram using Diagrams
I tried to solve AOJ's number theory with Python
I tried to make a periodical process with CentOS7, Selenium, Python and Chrome
I tried to make a simple mail sending application with tkinter of Python
When I tried to create a virtual environment with Python, it didn't work
[ES Lab] I tried to develop a WEB application with Python and Flask ②
I tried to easily create a fully automatic attendance system with Selenium + Python
I tried to touch Python (installation)
I tried web scraping with python.
I made a fortune with Python.
I want to debug with Python
I tried running prolog with python 3.8.2.
I made a daemon with Python
I tried SMTP communication with Python
Easily draw a map with matplotlib.basemap