Skip to content

Instantly share code, notes, and snippets.

@luqmaan
Created June 7, 2015 15:53
Show Gist options
  • Save luqmaan/4caf8ac7d00e02d362d0 to your computer and use it in GitHub Desktop.
Save luqmaan/4caf8ac7d00e02d362d0 to your computer and use it in GitHub Desktop.
import json
import psycopg2
conn = psycopg2.connect("dbname='bostongreenmap' user='django' host='localhost' password='django'")
cursor = conn.cursor()
with open('./data/city_of_austin_parks.json', 'r') as fh:
data = fh.read()
data = json.loads(data)
crs = data['crs']
for feature in data['features']:
geometry = feature['geometry']
geometry['crs'] = crs
cursor.execute('SELECT ST_AsText(ST_Transform(ST_GeomFromGeoJson(%s), 4326));', (json.dumps(geometry), ))
print(cursor.fetchall())
cursor.close()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment