0

I am trying to turn a polyhedralsurface object into solid using ST_MakeSolid() SFCGAL function in PostGIS.

SELECT 
ST_Volume(ST_MakeSolid(ST_GeomFromEWKT('SRID=4326;PolyhedralSurface(
        ((-1.36301 -5.98377 -57.9449 , -1.36302 -5.98389 -58.0362 , -1.36308 -5.98388 -57.9985 , -1.36307 -5.98377 -57.9072, -1.36301 -5.98377 -57.9449 )), 
        ((-1.36298 -5.98374 -65.0797 , -1.363 -5.98392 -65.2304 , -1.36311 -5.98391 -65.1682 , -1.36309 -5.98373 -65.0175, -1.36298 -5.98374 -65.0797 )),
        ((-1.36301 -5.98377 -57.9449 , -1.36298 -5.98374 -65.0797 , -1.36309 -5.98373 -65.0175, -1.36307 -5.98377 -57.9072, -1.36301 -5.98377 -57.9449 )),
        ((-1.36301 -5.98377 -57.9449 , -1.36298 -5.98374 -65.0797 , -1.363 -5.98392 -65.2304 , -1.36302 -5.98389 -58.0362 , -1.36301 -5.98377 -57.9449 )),
        ((-1.36302 -5.98389 -58.0362 , -1.363 -5.98392 -65.2304 , -1.36311 -5.98391 -65.1682 , -1.36308 -5.98388 -57.9985 , -1.36302 -5.98389 -58.0362 )),
        ((-1.36308 -5.98388 -57.9985 , -1.36311 -5.98391 -65.1682 , -1.36309 -5.98373 -65.0175, -1.36307 -5.98377 -57.9072, -1.36308 -5.98388 -57.9985 ))
        )')));

However, when i try to find its volume, an error occurs that the solid is invalid.

ERROR:  Solid is invalid : PolyhedralSurface (shell) 0 is invalid: Polygon 2 is invalid: points don't lie in the same plane : SOLID((((-1534612832025565/1125899906842624 -842140760695961/140737488355328 -8155019689000645/140737488355328,-6138496364098533/45035996

Note that the input geometry must be a closed Polyhedral Surface to obtain a valid solid with ST_MakeSolid(). I checked the polyhedralsurface using ST_IsClosed() and it turns out to be a closed surface. I also checked each of the polygon surfaces making up the polyhedralsurface for validity using ST_Dump() and ST_IsValid() and all turned out to be valid.

Can you please take a look at my solid and help me figure out why is it invalid and how i can resolve this error?

2
  • This solid throws an error as well ST_Volume(ST_MakeSolid('POLYHEDRALSURFACE Z (((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)), ((0 0 0,0 1 0,0 1 1,0 0 1,0 0 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)), ((1 1 1,1 0 1,0 0 1,0 1 1,1 1 1)),((1 1 1,1 0 1,1 0 0,1 1 0,1 1 1)), ((1 1 1,1 1 0,0 1 0,0 1 1,1 1 1)))'::geometry)) ERROR: Solid is invalid : PolyhedralSurface (shell) 0 is invalid: not connected – zrvr Oct 18 '16 at 4:03
  • Use the edit link below your question to add extra information, rather than in a comment – Midavalo Oct 18 '16 at 6:28
1

The problem is in the ordering of your points. The front and the back of a face are determined by whether the points turn clock or counter-clockwise. Make sure you'r points all rotate the same direction otherwise the polyhedral surface is invalid. Here are two examples. First one works, second one doesn't. I've attached an image that shows their respective rotations.

SELECT ST_Volume(ST_MakeSolid('POLYHEDRALSURFACE Z (
((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),
((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)),
((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),
((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)),
((1 1 0,1 1 1,1 0 1,1 0 0,1 1 0)),
((1 0 0,1 0 1,0 0 1,0 0 0,1 0 0)))'))

SELECT ST_Volume(ST_MakeSolid('POLYHEDRALSURFACE Z (
((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)), 
((0 0 0,0 1 0,0 1 1,0 0 1,0 0 0)),
((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)), 
((1 1 1,1 0 1,0 0 1,0 1 1,1 1 1)),
((1 1 1,1 0 1,1 0 0,1 1 0,1 1 1)), 
((1 1 1,1 1 0,0 1 0,0 1 1,1 1 1)))')

Ordering of vertices in polyhedral

Furthermore I doubt whether your coordinates are correct. Is it really latitude=-1.36301 -, longitude=5.98377 and depth = -57.9449 ?

5
  • Thanks tilt. Can you please explain why one order is valid and not the other? It'll give me an insight into how i should re-order my points. – zrvr Nov 1 '16 at 3:53
  • Yes, the GPS points were output from a program that processes camera position and view frustum details in WSG-84, and these were not correct. I've changed them but the issue still remains. – zrvr Nov 1 '16 at 3:55
  • I've added an example about rotation in the answer – tilt Nov 1 '16 at 10:30
  • @tilt : could you describe the process for creating more irregular shapes, such as a pyramid or a cube? thanks! – vagvaf Oct 13 '17 at 13:18
  • afaik the above example is a cube. And it wouldn't matter because in all examples the winding order for surfaces would have the same rule (inside->clockwise, outside -> counterclockwise) – tilt Oct 15 '17 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.