[GIS] ST_MakeSolid() creating an invalid solid from closed polyhedralsurfaceZ

3dgeometrypolygonpostgis-2.0sfcgal

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?

Best Answer

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 ?

Related Question