[PostGIS] #5817: CG_3DIntersection gives wrong result with LINESTRING and Solid

PostGIS trac at osgeo.org
Thu Jan 9 03:47:45 PST 2025


#5817: CG_3DIntersection gives wrong result with LINESTRING and Solid
-----------------------+---------------------------
  Reporter:  nbvfgh    |      Owner:  lbartoletti
      Type:  defect    |     Status:  new
  Priority:  critical  |  Milestone:  PostGIS 3.6.0
 Component:  sfcgal    |    Version:  3.5.x
Resolution:            |   Keywords:
-----------------------+---------------------------
Changes (by nbvfgh):

 * milestone:  PostGIS 3.5.2 => PostGIS 3.6.0


Old description:

> {{{
> SELECT ST_IsClosed('POLYHEDRALSURFACE Z (
> ((-1 1 -1,1 1 -1,1 -1 -1,-1 -1 -1,-1 1 -1)),
> ((-1 1 1,-1 -1 1,1 -1 1,1 1 1,-1 1 1)),
> ((-1 1 -1,-1 1 1,1 1 1,1 1 -1,-1 1 -1)),
> ((1 1 -1,1 1 1,1 -1 1,1 -1 -1,1 1 -1)),
> ((1 -1 -1,1 -1 1,-1 -1 1,-1 -1 -1,1 -1 -1)),
> ((-1 -1 -1,-1 -1 1,-1 1 1,-1 1 -1,-1 -1 -1)))');
>
> -- result:{true}
> }}}
> Then we make the closed POLYHEDRALSURFACE a Solid, and use
> CG_3DIntersection to get the Interaction with the Solid and Linestring,
> which we get the unexpected result.
> {{{
> WITH solid AS (
>     SELECT
>         CG_MakeSolid('POLYHEDRALSURFACE Z (
>                 ((-1 1 -1,1 1 -1,1 -1 -1,-1 -1 -1,-1 1 -1)),
>                 ((-1 1 1,-1 -1 1,1 -1 1,1 1 1,-1 1 1)),
>                 ((-1 1 -1,-1 1 1,1 1 1,1 1 -1,-1 1 -1)),
>                 ((1 1 -1,1 1 1,1 -1 1,1 -1 -1,1 1 -1)),
>                 ((1 -1 -1,1 -1 1,-1 -1 1,-1 -1 -1,1 -1 -1)),
>                 ((-1 -1 -1,-1 -1 1,-1 1 1,-1 1 -1,-1 -1 -1)))')
>      geom
> )
> SELECT
>         ST_AsText(CG_3DIntersection(
>         'LINESTRING (-2 0 0, 2 0 2)'::geometry,
>         solid.geom
>         )),
>         ST_AsText(CG_3DIntersection(
>         'LINESTRING (-2 0 0,0 0 1,2 0 2)'::geometry,
>         solid.geom
>         ))
> FROM solid;
>
> -- expected: {{LINESTRING Z (-1 0 0.5,0 0 1)},{LINESTRING Z (-1 0 0.5,0 0
> 1)}}
> -- actual  : {{POINT Z (-1 0 0.5)},{LINESTRING Z (-1 0 0.5,0 0 1)}}
> }}}
>
> To verify that the issue is not caused by differences in the two
> Linestrings, we ran the following query:
>
> {{{
> SELECT
>     ST_AsText(CG_3DIntersection(
>         'LINESTRING (-2 0 0,2 0 2)'::geometry,
>         'POLYHEDRALSURFACE Z (((-1 1 -1,1 1 -1,1 -1 -1,-1 -1 -1,-1 1
> -1)),((-1 1 1,-1 -1 1,1 -1 1,1 1 1,-1 1 1)),((-1 1 -1,-1 1 1,1 1 1,1 1
> -1,-1 1 -1)),((1 1 -1,1 1 1,1 -1 1,1 -1 -1,1 1 -1)),((1 -1 -1,1 -1 1,-1
> -1 1,-1 -1 -1,1 -1 -1)),((-1 -1 -1,-1 -1 1,-1 1 1,-1 1 -1,-1 -1 -1)))'
>     )),
>     ST_AsText(CG_3DIntersection(
>         'LINESTRING (-2 0 0,0 0 1,2 0 2)'::geometry,
>         'POLYHEDRALSURFACE Z (((-1 1 -1,1 1 -1,1 -1 -1,-1 -1 -1,-1 1
> -1)),((-1 1 1,-1 -1 1,1 -1 1,1 1 1,-1 1 1)),((-1 1 -1,-1 1 1,1 1 1,1 1
> -1,-1 1 -1)),((1 1 -1,1 1 1,1 -1 1,1 -1 -1,1 1 -1)),((1 -1 -1,1 -1 1,-1
> -1 1,-1 -1 -1,1 -1 -1)),((-1 -1 -1,-1 -1 1,-1 1 1,-1 1 -1,-1 -1 -1)))'
>     ));
> -- expected: {{MULTIPOINT Z ((-1 0 0.5),(0 0 1))},{MULTIPOINT Z ((-1 0
> 0.5),(0 0 1))}
> -- actual  : {{MULTIPOINT Z ((-1 0 0.5),(0 0 1))},{MULTIPOINT Z ((-1 0
> 0.5),(0 0 1))}
> }}}
> The intersection between the original POLYHEDRALSURFACE and these two
> linestrings yielded the same result, so there should be some bugs in the
> operation of the intersection between Solid and Linestring.

New description:

 {{{
 SELECT ST_IsClosed('POLYHEDRALSURFACE Z (
 ((-1 1 -1,1 1 -1,1 -1 -1,-1 -1 -1,-1 1 -1)),
 ((-1 1 1,-1 -1 1,1 -1 1,1 1 1,-1 1 1)),
 ((-1 1 -1,-1 1 1,1 1 1,1 1 -1,-1 1 -1)),
 ((1 1 -1,1 1 1,1 -1 1,1 -1 -1,1 1 -1)),
 ((1 -1 -1,1 -1 1,-1 -1 1,-1 -1 -1,1 -1 -1)),
 ((-1 -1 -1,-1 -1 1,-1 1 1,-1 1 -1,-1 -1 -1)))');

 -- result:{true}
 }}}
 Then we make the closed POLYHEDRALSURFACE a Solid, and use
 CG_3DIntersection to get the Interaction with the Solid and Linestring,
 which we get the unexpected result.
 {{{
 WITH solid AS (
     SELECT
         CG_MakeSolid('POLYHEDRALSURFACE Z (
                 ((-1 1 -1,1 1 -1,1 -1 -1,-1 -1 -1,-1 1 -1)),
                 ((-1 1 1,-1 -1 1,1 -1 1,1 1 1,-1 1 1)),
                 ((-1 1 -1,-1 1 1,1 1 1,1 1 -1,-1 1 -1)),
                 ((1 1 -1,1 1 1,1 -1 1,1 -1 -1,1 1 -1)),
                 ((1 -1 -1,1 -1 1,-1 -1 1,-1 -1 -1,1 -1 -1)),
                 ((-1 -1 -1,-1 -1 1,-1 1 1,-1 1 -1,-1 -1 -1)))')
      geom
 )
 SELECT
         ST_AsText(CG_3DIntersection(
         'LINESTRING (-2 0 0, 2 0 2)'::geometry,
         solid.geom
         )),
         ST_AsText(CG_3DIntersection(
         'LINESTRING (-2 0 0,0 0 1,2 0 2)'::geometry,
         solid.geom
         ))
 FROM solid;

 -- expected: {{LINESTRING Z (-1 0 0.5,0 0 1)},{LINESTRING Z (-1 0 0.5,0 0
 1)}}
 -- actual  : {{POINT Z (-1 0 0.5)},{LINESTRING Z (-1 0 0.5,0 0 1)}}
 }}}

 To verify that the issue is not caused by differences in the two
 Linestrings, we ran the following query:

 {{{
 SELECT
     ST_AsText(CG_3DIntersection(
         'LINESTRING (-2 0 0,2 0 2)'::geometry,
         'POLYHEDRALSURFACE Z (((-1 1 -1,1 1 -1,1 -1 -1,-1 -1 -1,-1 1
 -1)),((-1 1 1,-1 -1 1,1 -1 1,1 1 1,-1 1 1)),((-1 1 -1,-1 1 1,1 1 1,1 1
 -1,-1 1 -1)),((1 1 -1,1 1 1,1 -1 1,1 -1 -1,1 1 -1)),((1 -1 -1,1 -1 1,-1 -1
 1,-1 -1 -1,1 -1 -1)),((-1 -1 -1,-1 -1 1,-1 1 1,-1 1 -1,-1 -1 -1)))'
     )),
     ST_AsText(CG_3DIntersection(
         'LINESTRING (-2 0 0,0 0 1,2 0 2)'::geometry,
         'POLYHEDRALSURFACE Z (((-1 1 -1,1 1 -1,1 -1 -1,-1 -1 -1,-1 1
 -1)),((-1 1 1,-1 -1 1,1 -1 1,1 1 1,-1 1 1)),((-1 1 -1,-1 1 1,1 1 1,1 1
 -1,-1 1 -1)),((1 1 -1,1 1 1,1 -1 1,1 -1 -1,1 1 -1)),((1 -1 -1,1 -1 1,-1 -1
 1,-1 -1 -1,1 -1 -1)),((-1 -1 -1,-1 -1 1,-1 1 1,-1 1 -1,-1 -1 -1)))'
     ));
 -- expected: {{MULTIPOINT Z ((-1 0 0.5),(0 0 1))},{MULTIPOINT Z ((-1 0
 0.5),(0 0 1))}
 -- actual  : {{MULTIPOINT Z ((-1 0 0.5),(0 0 1))},{MULTIPOINT Z ((-1 0
 0.5),(0 0 1))}
 }}}
 The intersection between the original POLYHEDRALSURFACE and these two
 linestrings yielded the same result, so there should be some bugs in the
 operation of the intersection between Solid and Linestring.

 Version:{{{POSTGIS="3.6.0dev 3.5.0-91-g593df9088" [EXTENSION] PGSQL="170"
 GEOS="3.13.0-CAPI-1.19.0" SFCGAL="SFCGAL 1.5.2, CGAL 5.6.1, BOOST
 1.84.0"}}}

--
-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5817#comment:2>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list