I have a cube stored as geometry in a PostGIS DB. I get the coordinates using the following SQL:
select ST_AsEWKT(geom) from polyhedral.vol_1 where id = 1
This presents the following result.
POLYHEDRALSURFACE(
((0 1 0,0 0 0,1 0 0,1 1 0,0 1 0)),
((1 -0 1,0 0 1,0 1 1,1 1 1,1 -0 1)),
((1 0 0,1 -0 1,1 1 1,1 1 0,1 0 0)),
((0 0 0,0 0 1,1 -0 1,1 0 0,0 0 0)),
((0 1 0,0 1 1,0 0 1,0 0 0,0 1 0)),
((0 1 1,0 1 0,1 1 0,1 1 1,0 1 1))
)
would like to use this within the Open3D library.
For .ply
files it is simple mesh = read_triangle_mesh(filename.ply)
Any ideas about how I would get the PostGIS output to be compatible with Open3D?
Using the PostGIS python library I can get the result above into python like this.
conn = <connection details>
cur = conn.cursor()
print("connected")
cur.execute('SELECT ST_AsEWKT(geom) FROM polyhedral.vol_1 LIMIT 1')
geom = cur.fetchone()[0]
geom
This parses the query result into a pandas dataframe
s = geom.replace('POLYHEDRALSURFACE', '')
s = s.replace("((","|")
s = s.replace("))","|")
s = s.replace(")","")
s = s.replace("|,|",",")
s = s.replace("|","",1)
s = s.replace("(","")
s = s.replace(s[len(s)-1], '')
s = s.replace(",",";")
s = s.replace(" ",",")
test = s.split(";")
df = pd.DataFrame([sub.split(",") for sub in test], columns=['x','y','z'])
ERROR: lwgeom_to_geojson: 'PolyhedralSurface' geometry type not supported
ST_AsGeoJSON()
will only work if you cast your Polyhedral to aTIN
usingST_Tesselate()
. Which basically breaks your polyhedral into simple triangles. Then you will be able to build a GeoJSON.