In [21]:
import psycopg2 as pg
cnx = pg.connect('dbname=cityview user=cityview password=testthis host=localhost')
crs = cnx.cursor()
crs.execute("select name,st_asgeojson(geom) from neigborhoods;")
results = crs.fetchall()
In [25]:
import geojson
import json
features = [ (r[0],json.loads(r[1])) for r in results]
features = [ geojson.Feature(properties={'name': f[0]},geometry=f[1]) for f in features]
neighborhoods = geojson.FeatureCollection(features)
Out[25]:
In [29]:
fh = open('/home/larry/code/cityview/web/html/data/neighborhoods_geo.json','w')
nb = geojson.dumps(neighborhoods)
fh.write(nb)
fh.close()