Skip to main content
added 524 characters in body
Source Link
Spatial Digger
  • 533
  • 1
  • 6
  • 19

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'])

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

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'])
Structured, Title adjusted, Tag added
Source Link
Taras
  • 34.1k
  • 4
  • 73
  • 148

Reading PostGIS Selecting geometry from PostGIS compatible with PythonOpen3D

I have a cube stored as a geometry in a PostGIS dbDB. I get the coordinates using the following SQL:

select ST_AsEWKT(geom) from polyhedral.vol_1 where id = 1
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))
)
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.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?{

@@@###EDIT###@@@

 

usingUsing the postgisPostGIS 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
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

Reading PostGIS geometry with Python

I have a cube stored as a 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 how I would get the PostGIS output to be compatible with Open3D?{

@@@###EDIT###@@@

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

Selecting geometry from PostGIS compatible with Open3D

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
added 307 characters in body
Source Link
Spatial Digger
  • 533
  • 1
  • 6
  • 19

I have a cube stored as a 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 how I would get the PostGIS output to be compatible with Open3D?{

@@@###EDIT###@@@

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

I have a cube stored as a 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 how I would get the PostGIS output to be compatible with Open3D?

I have a cube stored as a 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 how I would get the PostGIS output to be compatible with Open3D?{

@@@###EDIT###@@@

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
naming
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65
Loading
naming
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65
Loading
Source Link
Spatial Digger
  • 533
  • 1
  • 6
  • 19
Loading