I have tried multiple times to obtain the 3D Intersection between a 3D linestring and a solid cube in both PostGIS 2.5.2 and 2.5.3 with the SFCGAL backend.
Below is a query that works as expected and returns the correct result in 3DIntersection:
SELECT ST_AsText(ST_3DIntersection(ST_GeomFromText('LINESTRING Z (0.5 0.5 0.0, 0.5 0.5 1.0)'), "cube")) as "3DIntersection",
ST_AsText("cube") as "cube_WKT",
ST_IsClosed("cube") as "cube_isclosed",
ST_IsSolid("cube") as "cube is solid"
FROM (
SELECT
ST_Extrude(ST_GeomFromText('POLYGON Z ((1 0 0, 1 1 0, 0 1 0, 0 0 0, 1 0 0))'), 0, 0, 1) as "cube"
) as subquery;
However, a slight change to the Z coordinates of the linestring now gives a very strange result for "3DIntersection" (point instead of linestring!):
SELECT ST_AsText(ST_3DIntersection(ST_GeomFromText('LINESTRING Z (0.5 0.5 0.0, 0.5 0.5 2.0)'), "cube")) as "3DIntersection",
ST_AsText("cube") as "cube_WKT",
ST_IsClosed("cube") as "cube_isclosed",
ST_IsSolid("cube") as "cube is solid"
FROM (
SELECT
ST_Extrude(ST_GeomFromText('POLYGON Z ((1 0 0, 1 1 0, 0 1 0, 0 0 0, 1 0 0))'), 0, 0, 1) as "cube"
) as subquery;
Ideally, the intersecting portion of the linestring should not change. However, when one of the points of the linestring is above the cube, only the botton intersecting point is returned.
Could somebody please explain what's going on? And perhaps how to obtain the intersecting portion of the linestring?
Here is my PostGIS version:
"POSTGIS="2.5.3 r17699" [EXTENSION] PGSQL="110" GEOS="3.7.2-CAPI-1.11.0 3.7.2" SFCGAL="1.3.2" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.2.4, released 2018/03/19" LIBXML="2.7.8" LIBJSON="0.12" LIBPROTOBUF="1.2.1" RASTER"