I want to plot the location information of GTFS Realtime on Jupyter! (With balloon)

Introduction

The current location of the bus can be seen from Google Map, but let's map it by yourself. Let's display it on python using a web map display plugin called folium. The map icon is clickable and can also display detailed information.

Implementation

realtimebus.py3


from google.transit import gtfs_realtime_pb2
import urllib.request, urllib.error
import folium
import pandas as pd

#GTFS-Public URL of RT(Uno Bus)
url ='http://www3.unobus.co.jp/GTFS/GTFS_RT-VP.bin'
#Declaration of column name
list_df = pd.DataFrame(columns=['id' , 'vehicle_id', 'trip_id','vehicle_timestamp','longitude','latitude','occupancy_status'])
feed = gtfs_realtime_pb2.FeedMessage()

#Data download and format conversion
with urllib.request.urlopen(url) as res: #Data download
    feed.ParseFromString(res.read()) #Deserialize protocol buffers
    for entity in feed.entity:
        tmp_se = pd.Series( [
              entity.id,                         #Vehicle ID
              entity.vehicle.vehicle.id,         #Vehicle number
              entity.vehicle.trip.trip_id,       #Route number?
              entity.vehicle.timestamp,          #Vehicle time
              entity.vehicle.position.longitude, #Vehicle latitude
              entity.vehicle.position.latitude,  #Vehicle longitude
              entity.vehicle.occupancy_status   #Congestion degree
        ], index=list_df.columns )
        list_df = list_df.append( tmp_se, ignore_index=True )

#Calculate the center point of the map
average_pos = list_df.mean()
#Create a map near the center coordinates
m = folium.Map(location=[average_pos['latitude'], average_pos['longitude']], zoom_start=11)
#Plot each bus(The color is blue)
list_df.apply(lambda row:
             folium.Marker(
                 location=[row['latitude'], row['longitude']],
                 popup='<table border="1"><tr><th>occupancy_status</th></tr><tr><td>'
                 +str(row['occupancy_status'])
                 +'</td></tr></table>',
                 icon=folium.Icon(color='blue',icon='bus', prefix='fa')
             ).add_to(m), axis=1)
m

result

The downloaded real-time location information is plotted on the map

スクリーンショット 2020-08-08 22.43.47.png

The timing of execution is past 22:30, but the bus is still running. .. ..

Recommended Posts

I want to plot the location information of GTFS Realtime on Jupyter! (With balloon)
I tried to get the location information of Odakyu Bus
I want to get the operation information of yahoo route
[Python] I want to make a 3D scatter plot of the epicenter with Cartopy + Matplotlib!
I want to output the beginning of the next month with Python
I want to check the position of my face with OpenCV!
I want to blog with Jupyter Notebook
I want to express my feelings with the lyrics of Mr. Children
I want to stop the automatic deletion of the tmp area with RHEL7
I tried to get the movie information of TMDb API with Python
When generating a large number of graphs with matplotlib, I do not want to display the graph on the screen (jupyter environment)
I want to customize the appearance of zabbix
I want to use Python in the environment of pyenv + pipenv on Windows 10
Library for "I want to do that" of data science on Jupyter Notebook
I'm an amateur on the 14th day of python, but I want to try machine learning with scikit-learn
I want to grep the execution result of strace
Add information to the bottom of the figure with Matplotlib
Drawing on Jupyter using the plot function of pandas
I want to inherit to the back with python dataclass
I want to fully understand the basics of Bokeh
I tried to visualize the spacha information of VTuber
I want to AWS Lambda with Python on Mac!
I want to increase the security of ssh connections
I want to take a screenshot of the site on Docker using any font
I tried to visualize the characteristics of new coronavirus infected person information with wordcloud
I tried to make it easy to change the setting of authenticated Proxy on Jupyter
The 15th offline real-time I tried to solve the problem of how to write with python
I tried to find the entropy of the image with python
I want to specify another version of Python with pyvenv
Memo to get the value on the html-javascript side with jupyter
I tried to find the average of the sequence with TensorFlow
I wrote the basic grammar of Python with Jupyter Lab
I want to start a jupyter environment with one command
I want to use only the normalization process of SudachiPy
I want to change the Japanese flag to the Palau flag with Numpy
I want to color black-and-white photos of memories with GAN
[Python] I want to use the -h option with argparse
I want to judge the authenticity of the elements of numpy array
I want to use a virtual environment with jupyter notebook!
I want to know the features of Python and pip
Keras I want to get the output of any layer !!
I want to know the legend of the IT technology world
I wrote the basic operation of matplotlib with Jupyter Lab
I want to change the symbolic link destination of / lib64 from / usr / lib64 to / my-lib64 on CentOS
I want to manually assign the training parameters of the [Pytorch] model
I want to know the weather with LINE bot feat.Heroku + Python
Become familiar with (want to be) around the pipeline of spaCy
I tried to automate the watering of the planter with Raspberry Pi
I want to extract an arbitrary URL from the character string of the html source with python
I want to read the html version of "OpenCV-Python Tutorials" OpenCV 3.1 version
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
I studied with Kaggle Start Book on the subject of kaggle [Part 1]
I tried to get started with Bitcoin Systre on the weekend
I wrote the basic operation of Pandas with Jupyter Lab (Part 1)
How to use Jupyter on the front end of supercomputer ITO
I tried to expand the size of the logical volume with LVM
For the time being, I want to convert files with ffmpeg !!
I want to do ○○ with Pandas
I checked the image of Science University on Twitter with Word2Vec.
I want to know the population of each country in the world.
I tried to improve the efficiency of daily work with Python