Advertisement
Guest User

Untitled

a guest
Mar 17th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. # Python psycopg2 & PostGIS
  2.  
  3. ## Load some data into the database
  4.  
  5. From the OSGeo4W Shell
  6.  
  7. ogr2ogr -f PostgreSQL PG:"dbname=postgis host=localhost user=postgres password=postgres" -a_srs "EPSG:27700" county_region.shp -nlt MULTIPOLYGON
  8.  
  9. ## Use psycopg2 in the Python Interpreter
  10.  
  11. import psycopg2
  12.  
  13. conn = psycopg2.connect("dbname=postgis user=postgres password=postgres")
  14.  
  15. cur.execute("SELECT ogc_fid, name, st_asewkt(st_centroid(wkb_geometry)) as geom FROM county_region limit 10")
  16.  
  17. colnames = [desc.name for desc in cur.description]
  18. print colnames
  19.  
  20. rows = cur.fetchall()
  21. print rows
  22.  
  23. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement