1

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
    Commented Oct 18, 2016 at 4:03
  • Use the edit link below your question to add extra information, rather than in a comment
    – Midavalo
    Commented Oct 18, 2016 at 6:28

2 Answers 2

2

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
    Commented Nov 1, 2016 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
    Commented Nov 1, 2016 at 3:55
  • I've added an example about rotation in the answer
    – tilt
    Commented Nov 1, 2016 at 10:30
  • @tilt : could you describe the process for creating more irregular shapes, such as a pyramid or a cube? thanks!
    – vagvaf
    Commented Oct 13, 2017 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
    Commented Oct 15, 2017 at 8:57
0

I realize that this has long been answered, and well, but I wanted to provide a bit more information, because I recently struggled with a similar issue. This is an application of the Right Hand Rule.

As I understand, a polyhedral is considered closed if its face vectors point outward. A face vector is the vector that is perpendicular to a face of the surface. The convention is for the face vector to point away from the surface according to the Right Hand Rule. (Although this is for another application, the explanation helps.)

To apply the Right Hand Rule, imagine curling your fingers of the palm of your right hand and placing the flat of your hand (opposite the thumb) against the face so that your thumb points away from the face. If your thumb is pointing away from you, the fingers are curled clockwise.

You can see this with the cube in the image in the prior post. Place your imaginary right hand against a face, and the curl of the fingers shows how to order the points.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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