I want to compute surface areas of a large CityGML data set. However, I ran into some issues, which I could not resolve or fully understand.
The error message is the following:
Polygon is invalid : points don't lie in the same plane
Minimal examples:
SELECT st_3darea( ST_SetSrid(ST_GeometryFromText( 'POLYGON Z ((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0))' ),4258))/*<- This works fine */SELECT st_3darea( ST_SetSrid(ST_GeometryFromText( 'POLYGON Z ((0 0 0, 0 11, 1 1 0, 1 0 0, 0 0 0))' ),4258))/*<- This does not work: Error Polygon is invalid : points don't lie in the same plane */SELECT st_3darea( ST_SetSrid(ST_GeometryFromText( 'POLYGON Z ((0 0 0, 0 11, 1 11, 1 0 0, 0 0 0))' ),4258))/*<- This works fine again */SELECT st_3darea( ST_SetSrid(ST_GeometryFromText( 'POLYGON Z ((0 0 0, 0 1 1, 1 0 0, 0 0 0))' ),4258))/*<- This works fine, removed one point */
From my understanding in 2), the function is not able to transform the coordinates into a flat plane to proceed with its calculations. Somehow, I am not sure if it is a bug or a feature (is the polygons in 2) invalid, why?)
As answered by@geozelot, its not a bug, but PostGIS does not support curved geometries.
My idea for a solution:
Is there a generic workflow/function to split polygons (e.g. 2)) in a form like in 4) triangles and then add the sums of the areas?
I would need it automated for the CityGML data set, which I do not know how to do e.g. non-automated
SELECT st_3darea( ST_SetSrid(ST_GeometryFromText( 'POLYGON Z ((0 0 0, 0 1 1, 1 0 0, 0 0 0))' ),4258)) + SELECT st_3darea( ST_SetSrid(ST_GeometryFromText( 'POLYGON Z ((0 1 1, 1 1 1, 1 0 0, 0 1 1))' ),4258))
ST_Tesselateand dump the resulting TINs.ST_DelaunayTriangles(GEOS) orST_ConstrainedDelaunayTriangles(SFCGAL) will create triangular Polyons, but have a deterministic order of vertex usage that cannot be influenced. – geozelot Jun 09 '21 at 11:06ST_Tesselatewould not work with the same error: "Polygon is invalid : points don't lie in the same plane". ForST_DelaunayTriangles(GEOS) an empty geometerycollection is returned andST_ConstrainedDelaunayTriangles(SFCGAL) returns a wrong and very small polygon. – fx-9750G PLUS Jul 07 '21 at 08:34