In this Python snippet we use stations (geographic) from the Swiss public transportation and convert the data to a GeoJSON (http://geojson.org/) file.
iconv -f ISO-8859-1 -t UTF-8 bfkoordgeo.csv > out.csv
Note: The data is from the Open Data Platform Swiss Public Transport, https://opentransportdata.swiss/en/
In [2]:
import pandas as pd
df = pd.read_csv('data/bfkoordgeo_utf8.csv')
df.head()
Out[2]:
Now we do some data cleaning and remove all rows where Longitude and Latitude are 'null'.
In [3]:
df = df[df['Longitude'].notnull()]
df = df[df['Latitude'].notnull()]
# will display all rows that have null values
#df[df.isnull().any(axis=1)]
In [4]:
import geojson as geojson
values = zip(df['Longitude'], df['Latitude'], df['Remark'])
points = [geojson.Feature(geometry=geojson.Point((v[0], v[1])), properties={'name': v[2]}) for v in values]
geo_collection = geojson.FeatureCollection(points)
print(points[0])
In [5]:
dump = geojson.dumps(geo_collection, sort_keys=True)
'''
with open('stations.geojson', 'w') as file:
file.write(dump)
'''
Out[5]:
In [ ]: