Export as geoJSON
It is likely that you'll want to view these NaPTAN stops on a map. The
naptan.export_geojson
function generates a geoJSON
file — providing a handy file format that can be readily consumed and mapped by
a variety of platforms or software.
You can pass in the result of either naptan.get_all_stops
, naptan.get_area_stops
or naptan.get_specific_stops
to the function. Also, provide the path and name
of the output file to the path
parameter.
Copied!
import naptan
# Get the active stops for Cornwall (area = 80)
cornish_stops = naptan.get_area_stops([80])
# and export
naptan.export_geojson(cornish_stops, path='cornish_stops.json')
import naptan
# Get the active stops for Cornwall (area = 80)
cornish_stops = naptan.get_area_stops([80])
# and export
naptan.export_geojson(cornish_stops, path='cornish_stops.json')
A snippet of the result is below:
# cornish_stops.json
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-5.531304582273736,
50.121656549309954
]
},
"properties": {
"ATCOCode": "0800COD40021",
"NaptanCode": "coradwpm",
"PlateCode": NaN,
"CleardownCode": NaN,
"CommonName": "Penzance Bus Station",
"CommonNameLang": NaN,
"ShortCommonName": NaN,
"ShortCommonNameLang": NaN,
"Landmark": NaN,
"LandmarkLang": NaN,
"Street": NaN,
"StreetLang": NaN,
"Crossing": NaN,
"CrossingLang": NaN,
"Indicator": "S-bound",
"IndicatorLang": NaN,
"Bearing": "S",
"NptgLocalityCode": "E0044623",
"LocalityName": "Penzance",
"ParentLocalityName": NaN,
"GrandParentLocalityName": NaN,
"Town": NaN,
"TownLang": NaN,
"Suburb": NaN,
"SuburbLang": NaN,
"LocalityCentre": "false",
"GridType": "UKOS",
"Easting": 147678,
"Northing": 30593,
"Longitude": -5.531304582273736,
"Latitude": 50.121656549309954,
"StopType": "BCT",
"BusStopType": "MKD",
"TimingStatus": "OTH",
"DefaultWaitTime": NaN,
"Notes": NaN,
"NotesLang": NaN,
"AdministrativeAreaCode": 73,
"CreationDateTime": "2006-05-18T00:00:00",
"ModificationDateTime": "2015-04-25T12:22:36",
"RevisionNumber": 0,
"Modification": "delete",
"Status": "inactive"
}
},
...