Skip to content

Instantly share code, notes, and snippets.

@bertt
Created April 24, 2020 11:19
Show Gist options
  • Save bertt/a2c50af49af066b42eccbd224547526e to your computer and use it in GitHub Desktop.
Save bertt/a2c50af49af066b42eccbd224547526e to your computer and use it in GitHub Desktop.
Read PolyhedralSurfaceZ from PostGIS with Python and OGR
import psycopg2
from osgeo import ogr
connection = psycopg2.connect(user = "postgres",
password = "postgres",
host = "localhost",
port = "5432",
database = "postgres")
cursor = connection.cursor()
print ( connection.get_dsn_parameters(),"\n")
cursor.execute("select st_asbinary(geom_triangle) as geom1 from delaware_buildings limit 10 ")
for row in cursor:
b = bytes(row[0])
polyhedral = ogr.CreateGeometryFromWkb(b)
for i in range(0, polyhedral.GetGeometryCount()):
polygon = polyhedral.GetGeometryRef(i)
for j in range(0, polygon.GetGeometryCount()):
linearring=polygon.GetGeometryRef(j)
for k in range(0, linearring.GetPointCount()):
point=linearring.GetPoint(k)
print(str(point[0]) + ', ' + str(point[1]) + ', ' + str(point[2]))
cursor.close()
connection.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment