Advertisement
Guest User

json2geojson.py

a guest
Oct 10th, 2013
1,909
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None
  1. from sys import argv
  2. from os.path import exists
  3. import simplejson as json
  4.  
  5. script, in_file, out_file = argv
  6.  
  7. data = json.load(open(in_file))
  8.  
  9. geojson = {
  10.     "type": "FeatureCollection",
  11.     "features": [
  12.     {
  13.         "type": "Feature",
  14.         "geometry" : {
  15.             "type": "Point",
  16.             "coordinates": [d["lon"], d["lat"]],
  17.             },
  18.         "properties" : d,
  19.      } for d in data]
  20. }
  21.  
  22.  
  23. output = open(out_file, 'w')
  24. json.dump(geojson, output)
  25.  
  26. print geojson
Advertisement
RAW Paste Data Copied
Advertisement