Opened 6 months ago

Closed 3 months ago

Last modified 3 months ago

#5580 closed defect (fixed)

ST_3DIntersects fails when encouting a GEOMETRYCOLLECTION with an empty geometry

Reported by: Wenjing Owned by: pramsey
Priority: high Milestone: PostGIS 3.3.6
Component: postgis Version: 3.4.x
Keywords: Cc:

Description (last modified by Wenjing)

Consider this query:

SELECT
ST_3DIntersects(a1, a2)
FROM ST_GeomFromText('GEOMETRYCOLLECTION Z (POINT Z EMPTY, POINT Z (0 0 0))') As a1
, ST_GeomFromText('POINT Z (0 0 0)') As a2;
--expected{t}; actual{f}

Postgis produces a result of false, but I expected it to produce true. I think this is a bug, due to the following 3 reasons:

  1. ST_3DIntersection(a1, a2) returns POINT Z (0 0 0). So the expected result of 3DIntersects is true.
  1. Considering the 2D version function, ST_Intersects(a1, a2) returns true here:
    SELECT
    ST_Intersects(a1, a2)
    FROM ST_GeomFromText('GEOMETRYCOLLECTION(POINT EMPTY, POINT (0 0))') As a1
    , ST_GeomFromText('POINT (0 0)') As a2;
    --expected{t}
    
  1. Making the empty point position behind POINT Z (0 0 0), ST_3DIntersection(a1, a2) returns true.

Version: POSTGIS="3.4.0 0874ea3" [EXTENSION] PGSQL="150" GEOS="3.9.0-CAPI-1.16.2" SFCGAL="1.3.8" PROJ="7.2.1 NETWORK_ENABLED=OFF URL_ENDPOINT=https://cdn. proj.org USER_WRITABLE_DIRECTORY=/var/lib/postgresql/.local/share/proj DATABASE_PATH=/usr/share/proj/proj.db" LIBXML="2.9.10" LIBJSON="0.15" LIBPR OTOBUF="1.3.3" WAGYU="0.5.0 (Internal)" TOPOLOGY

Change History (19)

comment:1 by Wenjing, 6 months ago

Description: modified (diff)
Priority: mediumhigh

comment:2 by Wenjing, 6 months ago

Description: modified (diff)

comment:3 by Wenjing, 6 months ago

Summary: When encounting an empty geometry, potential bug in the ST_3DIntersects functionST_3DIntersects fails when encouting a GEOMETRYCOLLECTION with an empty geometry

comment:4 by Wenjing, 6 months ago

The potential solution is to add some same condition detection in the ST_Intersects function to ST_3DIntersects.🤔

comment:5 by Wenjing, 6 months ago

Description: modified (diff)

comment:6 by Wenjing, 6 months ago

Description: modified (diff)

comment:7 by Wenjing, 6 months ago

Description: modified (diff)

comment:8 by Wenjing, 6 months ago

Description: modified (diff)

comment:9 by robe, 6 months ago

Just a side-note, ST_3DIntersection is an SFCGAL function. ST_3DIntersects is a native. That is not to say this should not be fixed. When there is an empty geometry, many bets are off as to what the right answer should be.

But like I have mentioned before, SFCGAL ships it's own ST_3DIntersects, which gives more correct answers than our native ones, but sadly much slower. I'm going to open up (or check if we have one already), to expose the SFCGAL's ST_3DIntersects as CG_3DIntersects.

comment:10 by robe, 6 months ago

I have ticked #5587 to address the 3DIntersects exposing the SFCGAL variant.

comment:11 by robe, 5 months ago

Milestone: PostGIS 3.4.1PostGIS 3.3.6

comment:12 by Paul Ramsey <pramsey@…>, 3 months ago

In bf6be27/git:

Handle empty collection components in 3d distance, references #5580

comment:13 by Paul Ramsey <pramsey@…>, 3 months ago

In be9cd58/git:

Handle empty collection components in 3d distance, references #5580

comment:14 by Paul Ramsey <pramsey@…>, 3 months ago

In 21eecd6/git:

Handle empty collection components in 3d distance, references #5580

comment:15 by Paul Ramsey <pramsey@…>, 3 months ago

In 790c7bd/git:

Handle empty collection components in 3d distance, references #5580

comment:16 by Paul Ramsey <pramsey@…>, 3 months ago

In 96b7863/git:

Handle empty collection components in 3d distance, references #5580

comment:17 by pramsey, 3 months ago

Resolution: fixed
Status: newclosed

comment:18 by strk, 3 months ago

Paul: any reason for not adding a regression test for this bug ?

comment:19 by Paul Ramsey <pramsey@…>, 3 months ago

In cb1491cc/git:

Handle empty collection components in 3d distance, references #5580

Note: See TracTickets for help on using tickets.