Create a map
Now to get interactive!
The naptan package makes it really easy to view the returned NaPTAN data.
There are two functions (naptan.create_map
, naptan.view_map
) that allow us
to do so. Which one to use depends on your use case.
Both have the same parameters passed in and both produce an interactive map. The maps can be panned, zoomed and specific stops can be found easily with the included search bar.
naptan.create_map
¶
You're more likely to use this function if you're working in a notebook (like this), or you want to do something extra with the returned folium.Map object.
For example, let's take a look at all the active stops within Glasgow:
import naptan
# 609 = Glasgow atco area code
glasgow_stops = naptan.get_area_stops([609])
# the folium.Map object
glasgow_map = naptan.create_map(glasgow_stops)
type(glasgow_map)
folium.folium.Map
To view the map in a notebook, just run the cell with the map object in it. The map object is then displayed and can be interacted with.
glasgow_map
naptan.view_map
¶
If you're not in a notebook, or you want to view the map on a larger screen, or even share the map, then this function creates a temporary .html file which is then opened by your browser.
import naptan
# 290 Norfolk atco area code
norfolk_stops = naptan.get_area_stops([290])
naptan.view_map(norfolk_stops)
The result of the above code can be seen here.