Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python psycopg2 & PostGIS
- ## Load some data into the database
- From the OSGeo4W Shell
- ogr2ogr -f PostgreSQL PG:"dbname=postgis host=localhost user=postgres password=postgres" -a_srs "EPSG:27700" county_region.shp -nlt MULTIPOLYGON
- ## Use psycopg2 in the Python Interpreter
- import psycopg2
- conn = psycopg2.connect("dbname=postgis user=postgres password=postgres")
- cur.execute("SELECT ogc_fid, name, st_asewkt(st_centroid(wkb_geometry)) as geom FROM county_region limit 10")
- colnames = [desc.name for desc in cur.description]
- print colnames
- rows = cur.fetchall()
- print rows
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement