Skip to content

Instantly share code, notes, and snippets.

@twolfson
Forked from tmcw/foursquare_to_geojson.py
Created December 20, 2018 04: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 twolfson/6fc4bb8ac05a4b501472c867a7b016bd to your computer and use it in GitHub Desktop.
Save twolfson/6fc4bb8ac05a4b501472c867a7b016bd to your computer and use it in GitHub Desktop.
Turn your Foursquare Data Archive into a GeoJSON file
checkins/
checkins.geojson
import glob, json
# this script loves this script
# https://gist.github.com/3350235
points = []
vids = set()
places = glob.glob("checkins/*.json")
for p in places:
pj = json.load(open(p))
if pj['venue']['id'] not in vids:
vids.add(pj['venue']['id'])
coords = [
pj['venue']['location']['lng'],
pj['venue']['location']['lat']]
points.append({
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': coords
},
'properties': {
'name': pj['venue']['name'],
'id': pj['venue']['id']
}
})
json.dump({ 'type': 'FeatureCollection', 'features': points }, open('checkins.geojson', 'w'), indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment