Created
November 14, 2015 14:38
-
-
Save KrzysztofMadejski/f8e37565c6d72dbe7bd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__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