Skip to content

Instantly share code, notes, and snippets.

@KrzysztofMadejski
Created November 14, 2015 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KrzysztofMadejski/f8e37565c6d72dbe7bd7 to your computer and use it in GitHub Desktop.
Save KrzysztofMadejski/f8e37565c6d72dbe7bd7 to your computer and use it in GitHub Desktop.
__author__ = 'kmadejski'
# python 3
import csv
from geojson import LineString, FeatureCollection, Feature
import geojson
from dateutil.parser import parse as parse_date
features = []
with open('trips-GOP-05.11.2015.csv', 'r', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile, delimiter=';', quotechar='"')
for trip in reader:
line = LineString([(float(trip['start lon']), float(trip['start lat'])), (float(trip['end lon']), float(trip['end lat']))])
tripdate = parse_date(trip['\ufeffdate'], dayfirst=True)
features.append(Feature(geometry=line, properties={'datetime': tripdate.strftime('%Y-%m-%dT%H:%M')}))
fc = FeatureCollection(features=features)
with open('trips.geojson', 'w', encoding='utf-8') as out:
out.write(geojson.dumps(fc, indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment