I need to compound several sfcgal expressions to create the overall effect of:
SELECT
ST_Volume(
ST_MakeValid(
ST_MakeSolid(
ST_3DDifference(
ST_3DUnion(PolyhedralSurface1, PolyhedralSurface2),
PolyhedralSurface1)))) ...;
However, the nested functions fail either due to incompatible i/o types, or invalid geometric structures.
SELECT ST_AsText(ST_3DUnion(p1,p2))
FROM
(SELECT
(ST_GeomFromText('POLYHEDRALSURFACEZ(
((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),
((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)),
((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )')) AS p1,
(ST_GeomFromText('POLYHEDRALSURFACEZ(
((0.5 0 0, 0.5 0 1, 0.5 1 1, 0.5 1 0, 0.5 0 0)),
((0.5 0 0, 0.5 1 0, 1.5 1 0, 1.5 0 0, 0.5 0 0)),
((0.5 0 0, 1.5 0 0, 1.5 0 1, 0.5 0 1, 0.5 0 0)),
((1.5 1 0, 1.5 1 1, 1.5 0 1, 1.5 0 0, 1.5 1 0)),
((0.5 1 0, 0.5 1 1, 1.5 1 1, 1.5 1 0, 0.5 1 0)),
((0.5 0 1, 1.5 0 1, 1.5 1 1, 0.5 1 1, 0.5 0 1)) )')) AS p2) AS t:
returns:
"GEOMETRYCOLLECTION Z (TIN Z (
((-0 -0 -0,-0 -0 1,-0 1 1,-0 -0 -0)),
((-0 1 -0,-0 -0 -0,-0 1 1,-0 1 -0)),
((0.5 0.5 -0,-0 1 -0,0.5 1 -0,0.5 0.5 -0)),
((0.5 0.5 -0,-0 -0 -0,-0 1 -0,0.5 0.5 -0)),
((1 1 -0,0.5 0.5 -0,0.5 1 -0,1 1 -0)),
((0.5 -0 -0,-0 -0 -0,0.5 0.5 - (...)"
Then:
SELECT ST_3DDifference(ST_3DUnion(p1,p2),p1)
FROM (SELECT (ST_GeomFromText('POLYHEDRALSURFACEZ(
((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),
((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)),
((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)) )')) AS p1,
(ST_GeomFromText('POLYHEDRALSURFACEZ(
((0.5 0 0, 0.5 0 1, 0.5 1 1, 0.5 1 0, 0.5 0 0)),
((0.5 0 0, 0.5 1 0, 1.5 1 0, 1.5 0 0, 0.5 0 0)),
((0.5 0 0, 1.5 0 0, 1.5 0 1, 0.5 0 1, 0.5 0 0)),
((1.5 1 0, 1.5 1 1, 1.5 0 1, 1.5 0 0, 1.5 1 0)),
((0.5 1 0, 0.5 1 1, 1.5 1 1, 1.5 1 0, 0.5 1 0)),
((0.5 0 1, 1.5 0 1, 1.5 1 1, 0.5 1 1, 0.5 0 1)) )')) AS p2) AS t;
creates the error:
NOTICE: During difference_3d(A,B) :
NOTICE: with A: GEOMETRYCOLLECTION(TIN(
((0/1 0/1 0/1,0/1 0/1 1/1,0/1 1/1 1/1,0/1 0/1 0/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)),
((1/2 1/2 0/1,0/1 1/1 0/1,1/2 1/1 0/1,1/2 1/2 0/1)),
((1/2 1/2 0/1,0/1 0/1 0/1,0/1 1/1 0/1,1/2 1/2 0/1)),
((1/1 1/1 0/1,
NOTICE: and B: POLYHEDRALSURFACE(
((0/1 0/1 0/1,0/1 0/1 1/1,0/1 1/1 1/1,0/1 1/1 0/1,0/1 0/1 0/1)),
((0/1 0/1 0/1,0/1 1/1 0/1,1/1 1/1 0/1,1/1 0/1 0/1,0/1 0/1 0/1)),
((0/1 0/1 0/1,1/1 0/1 0/1,1/1 0/1 1/1,0/1 0/1 1/1,0/1 0/1 0/1)),
((1/1 1/1 0/1,1/1 1/1 1/1,1/1 0/1 1...
ERROR: GeometryCollection is invalid : TriangulatedSurface 0 is invalid: self intersects : GEOMETRYCOLLECTION(TIN
(((0/1 0/1 0/1,0/1 0/1 1/1,0/1 1/1 1/1,0/1 0/1 0/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)),
((1/2 1/2 0/1,0/1 1/1 0/1,1/2 1/1 0/1,1/2 1/...
********** Error **********
ERROR: GeometryCollection is invalid : TriangulatedSurface 0 is invalid: self intersects : GEOMETRYCOLLECTION(TIN(
((0/1 0/1 0/1,0/1 0/1 1/1,0/1 1/1 1/1,0/1 0/1 0/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)),
((1/2 1/2 0/1,0/1 1/1 0/1,1/2 1/1 0/1,1/2 1/
SQL state: XX000
Hence the ST_Union command appears to return a valid result, although this is typed first as a TIN and then as a geometrycollection.
But then these as a direct input to ST_3DDifference is invalid. This seems to imply that the outputs of the inner sfcgal functions are not compatible as inputs to the outer functions ... ???
WITH cube1 (geom) AS (SELECT ST_Extrude(ST_Force3D(ST_Expand(ST_Makepoint(0, 0), 1, 1)), 0,0,2) ) , cube2 (geom) AS (SELECT ST_Translate(geom, 0.5, 0.5, 0.5) FROM cube1) select ST_AsText(ST_3dIntersection(c1.geom, c2.geom)) FROM cube1 c1, cube2 c2;
ie, the intersection of two cubes, one offset from the other, I get a PolyhedralSurface Z back. I don't know why you are getting TINs. It is because they are coincident in certain places?