in Education by
I'm trying to convert a ply to a polyhedron stored in postgis. In this example I have a cube from 0,0,0 to 1,1,1 the script below brings in a geometry to postgis, it is there, no problem, however I go to calculate the volume and it gives the following error: query: SELECT ST_Volume(st_geomfromtext) FROM public.test3 error: ERROR: PolyhedralSurface is invalid : inconsistent orientation of PolyhedralSurface detected at edge 1 (4-3) of polygon 11 : POLYHEDRALSURFACE(((1/1 1/1 0/1,1/1 0/1 0/1,0/1 0/1 0/1,1/1 1/1 0/1)),((1/1 0/1 0/1,1/1 0/1 1/1,0/1 0/1 0/1,1/1 0/1 0/1)),((1/1 0/1 0/1,1 SQL state: XX000 The object is a cube 0,0,0 to 1,1,1, here it is as an array of vertices and triangles. vertices: array([[ 1., 1., -0.], [ 1., 0., -0.], [ 0., 0., -0.], [ 0., 1., -0.], [ 1., 1., 1.], [ 0., 1., 1.], [ 0., 0., 1.], [ 1., 0., 1.], [ 1., 1., -0.], [ 1., 1., 1.], [ 1., 0., 1.], [ 1., 0., -0.], [ 1., 0., -0.], [ 1., 0., 1.], [ 0., 0., 1.], [ 0., 0., -0.], [ 0., 0., -0.], [ 0., 0., 1.], [ 0., 1., 1.], [ 0., 1., -0.], [ 1., 1., 1.], [ 1., 1., -0.], [ 0., 1., -0.], [ 0., 1., 1.]]) The triangles are defined as: array([[ 0, 1, 2], [ 0, 2, 3], [ 4, 5, 6], [ 4, 6, 7], [ 8, 9, 10], [ 8, 10, 11], [12, 13, 14], [12, 14, 15], [16, 17, 18], [16, 18, 19], [20, 21, 22], [20, 22, 23]], dtype=int32) I put together this conversion script to take a ply and add it to postgis: import numpy as np from open3d import * import psycopg2 import dbconfig def connect_db(): global connection connection = psycopg2.connect(host=dbconfig.DATABASE_CONFIG['host'], user=dbconfig.DATABASE_CONFIG['user'], password=dbconfig.DATABASE_CONFIG['password'], dbname=dbconfig.DATABASE_CONFIG['dbname']) return connection # mesh = read_triangle_mesh('C:/Users/garyn/PycharmProjects/pointcloudprocessor/tmp/contexts/99.526/396.ply') mesh = read_triangle_mesh('C:/Users/garyn/PycharmProjects/pointcloudprocessor/tmp/contexts/cube3.ply') verts = mesh.vertices verts = np.asarray(verts) tri = mesh.triangles tri = np.asarray(tri) data = '' header = ("'POLYHEDRALSURFACE(") for i in range(len(tri)): # for i in range(0,2): x1 = (tri[i][0]) # 3 y1 = (tri[i][1]) # 44 z1 = (tri[i][2]) # 1 x_coords1 = verts[x1][0] y_coords1 = verts[y1][0] z_coords1 = verts[z1][0] x_coords2 = verts[x1][1] y_coords2 = verts[y1][1] z_coords2 = verts[z1][1] x_coords3 = verts[x1][2] y_coords3 = verts[y1][2] z_coords3 = verts[z1][2] data += "((%s %s %s, %s %s %s, %s %s %s, %s %s %s))," % \ (x_coords1, y_coords1, z_coords1, \ x_coords2, y_coords2, z_coords2, \ x_coords3, y_coords3, z_coords3, \ x_coords1, y_coords1, z_coords1) data = data[:-1] projection = ")',32635)" create_stmt = "CREATE TABLE test3 AS " select_stmt = "SELECT ST_GeomFromText(" polyhedron = header + data + projection query = create_stmt + select_stmt + polyhedron conn = connect_db() cur = conn.cursor() cur.execute(query) conn.commit() cur.close() conn.close() Which results in: CREATE TABLE test3 AS SELECT ST_GeomFromText('POLYHEDRALSURFACE(((1.0 1.0 0.0, 1.0 0.0 0.0, -0.0 -0.0 -0.0, 1.0 1.0 0.0)),((1.0 0.0 0.0, 1.0 0.0 1.0, -0.0 -0.0 -0.0, 1.0 0.0 0.0)),((1.0 0.0 0.0, 1.0 1.0 0.0, 1.0 1.0 1.0, 1.0 0.0 0.0)),((1.0 0.0 1.0, 1.0 0.0 0.0, 1.0 1.0 1.0, 1.0 0.0 1.0)),((1.0 1.0 1.0, 1.0 1.0 0.0, -0.0 1.0 1.0, 1.0 1.0 1.0)),((1.0 1.0 1.0, 1.0 0.0 0.0, -0.0 1.0 -0.0, 1.0 1.0 1.0)),((1.0 1.0 0.0, 0.0 0.0 0.0, -0.0 1.0 1.0, 1.0 1.0 0.0)),((1.0 0.0 0.0, 0.0 0.0 0.0, -0.0 1.0 -0.0, 1.0 0.0 0.0)),((0.0 0.0 0.0, 0.0 0.0 1.0, -0.0 1.0 1.0, 0.0 0.0 0.0)),((0.0 0.0 0.0, 0.0 1.0 1.0, -0.0 1.0 -0.0, 0.0 0.0 0.0)),((1.0 1.0 0.0, 1.0 1.0 1.0, 1.0 -0.0 -0.0, 1.0 1.0 0.0)),((1.0 0.0 0.0, 1.0 1.0 1.0, 1.0 -0.0 1.0, 1.0 0.0 0.0)))',32635) It looks ok to me and postgis accepts it as a polyhedral surface, but how do I make sure the cube is constructed correctly? P.S. and postgis 3D viewers out there, I'm doing this blind. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I solved it, I had the ordering wrong, here is the correct ordering. data = '' header = ("'POLYHEDRALSURFACE(") for i in range(len(tri)): # for i in range(0,2): x1 = (tri[i][0]) # 3 y1 = (tri[i][1]) # 44 z1 = (tri[i][2]) # 1 coords1 = verts[x1][0] coords2 = verts[x1][1] coords3 = verts[x1][2] coords4 = verts[y1][0] coords5 = verts[y1][1] coords6 = verts[y1][2] coords7 = verts[z1][0] coords8 = verts[z1][1] coords9 = verts[z1][2] data += "((%s %s %s, %s %s %s, %s %s %s, %s %s %s))," % \ ( coords1, coords2, coords3, coords4, coords5, coords6, coords7, coords8, coords9, coords1, coords2, coords3 ) data = data[:-1]

Related questions

0 votes
    Following Regular Expression does work in HTML like following example: But if I want to put that pattern in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I have a VBA macro which copies a summary tab from one workbook to another. It works fine in 2010 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I'm currently working on a lottery app and have coded the UI for it. The problem is that my page ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    Ok, this is weird. My terminal (iterm2 with zsh) exits a command with control + m or control + ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
0 votes
    I am new to VSTS and I am trying to get a msbuild task to publish a SQL Server project using a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I have been implementing a Next.js app for a side project of mine. It is a basic brochure-style ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    axios.js throws CONNRESET error (certificate not found in request) but request package works for same p12 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I have a virtual machine (VMware) with Mercury Quick Test Professional 9.2 installed. I have a script ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I have added some code for a "lightbox" effect on one of my images (below) [The website is live] ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    I'm using a lat/long SRID in my PostGIS database (-4326). I would like to find the nearest ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    What is In-process Script Approval and how it works?...
asked Jul 17, 2021 in Technology by JackTerrance
0 votes
    recently i'm working on some project with arm but no OS in it. Now when i compile it, i must ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'm trying to open up a PDF as an image using Wand. If I run the code below in Jupyter Notebook ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I am using Excel where certain fields are allowed for user input and other cells are to be protected. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 18, 2022 in Education by JackTerrance
0 votes
    I am using Excel where certain fields are allowed for user input and other cells are to be protected. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
...