Skip to content

Instantly share code, notes, and snippets.

@ptwobrussell
Created January 3, 2014 18:49
Show Gist options
  • Save ptwobrussell/8243923 to your computer and use it in GitHub Desktop.
Save ptwobrussell/8243923 to your computer and use it in GitHub Desktop.
A little script for converting tweets with geocoords to geojson format. (The script assumes that you've flattened the tweets down to a CSV format with the field format described in the tuple of the "for" loop, which is easy enough to do.)
import geojson
import sys
lines = [line.strip().split("\t") for line in open(sys.argv[1]).readlines()]
features = []
for (x, y, _id, text, screen_name, utc) in lines:
props = dict(text=text, screen_name=screen_name, utc=utc)
features.append( geojson.Feature(id=_id, geometry=geojson.Point(coordinates=(x,y)), properties=props) )
feature_collection = geojson.FeatureCollection(features)
print geojson.dumps(feature_collection, indent=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment