Created
April 24, 2020 11:19
-
-
Save bertt/a2c50af49af066b42eccbd224547526e to your computer and use it in GitHub Desktop.
Read PolyhedralSurfaceZ from PostGIS with Python and OGR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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