2

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;

this query works

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;

strange 3DIntersection

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"
1

I took your code and get a closer look to it.

If you add points in your linestring without changing it (by adding the middle of the linestring for example) It works well, you get the 0.5, 0.5, 1 intersection + points you add.

SELECT ST_AsText(ST_3DIntersection(ST_GeomFromText('LINESTRING Z (0.5 0.5 0, 0.5 0.5 0.2, 0.5 0.5 0.8, 0.5 0.5 2)'), "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;

but this is not really satisfying and it looks like a bug to me.

You can try to fill a bug report to make the development team aware of this problem.

I tried to move the points around ( on the border, 1 inside and other outside) it worked as intended in many cases. It's really your edge case that is problematic.

  • thanks very much for checking. i'll file a bug report to the PostGIS team asap – pawarit28 Sep 4 '19 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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