1

Say I have a cube or more complex closed triangulated object in Blender, how would I be able to store this in postgis?

Postgis stores 3D geometry via well-known text (wkt) as a polyhedral or tin. Is there any way to get a blender object into postgis?

Spatial Digger
  • 1,883
  • 1
  • 19
  • 37

1 Answers1

0

You read blenders data and create insert statements for postgresql. As blender contains a python interpreter, you can run a python script in blender that sends the data to postgresql.

The first step is installing a python postgresql module, such as psycopg that can be used within blender. There are several options for this, including adding a path to sys.path.

Once you can run a python script in blender that can talk to a postgresql server, read blenders mesh data to generate the insert statements.

pg_insert = 'INSERT INTO mytable (v_loc) VALUES ('
for v in obj.data.vertices:
    pg_insert += 'POINT({} {} {}),'.format(v.co.x, v.co.y, v.co.z)
pg_insert += ');'
sambler
  • 6,917
  • 1
  • 16
  • 23
  • I understand what you did there, but this will result in the vertices being stored, which is nice, but not the polyhedral I was looking for. I have a vertices list and a triangles (faces) list in python, but this is not a polyhedral. – Spatial Digger Mar 24 '19 at 13:05
  • 1
    @GaryNobles while the sql gen is simplified, you can take the vertices and polygon list and use it to define [`POLYHEDRALSURFACE`](https://postgis.net/docs/using_postgis_dbmanagement.html) data that is stored in a single field. As a polyhedral is the whole object of multiple polys, you would use the entire polygons list to make the surface data. Each polygon item in blender has a list of vertex indices - `v_idx = obj.data.polygons[f].vertices[v] v_loc = obj.data.vertices[v_idx].co`. – sambler Mar 27 '19 at 07:18