[PostGIS] #2574: Have ST_3DDWithin to recognize Triangle as a type
PostGIS
trac at osgeo.org
Fri Oct 24 05:51:36 PDT 2025
#2574: Have ST_3DDWithin to recognize Triangle as a type
----------------------------+-----------------------------
Reporter: smathermather | Owner: colivier
Type: enhancement | Status: closed
Priority: medium | Milestone: PostGIS Fund Me
Component: postgis | Version: 2.1.x
Resolution: fixed | Keywords:
----------------------------+-----------------------------
Changes (by komzpa):
* resolution: => fixed
* status: new => closed
Comment:
Works
{{{
POSTGIS="3.7.0dev 3.6.0rc2-157-g385a9ff4e" [EXTENSION] PGSQL="180"
GEOS="3.14.0-CAPI-1.20.4" PROJ="9.7.0 NETWORK_ENABLED=OFF
URL_ENDPOINT=https://cdn.proj.org USER_WRITABLE_DIRECTORY=/tmp/proj
DATABASE_PATH=/usr/share/proj/proj.db" (compiled against PROJ 9.7.0)
GDAL="GDAL 3.12.0beta1 "Chicoutimi", released 2025/10/20" LIBXML="2.15.1"
LIBJSON="0.18" LIBPROTOBUF="1.5.1" WAGYU="0.5.0 (Internal)" RASTER
16:50:48 [kom] >
-- Helpers: two triangles and a few other geoms
-- tri_a: near origin, XY plane at z=0
WITH
tri_a AS (
SELECT 'TRIANGLE Z ((0 0 0, 1 0 0, 0 1 0, 0 0 0))'::geometry AS g
),
-- tri_b_xy: translated along +X by 10, same plane z=0
-- shortest 3D distance to tri_a is exactly 9 (from x=1 to x=10)
tri_b_xy AS (
SELECT 'TRIANGLE Z ((10 0 0, 11 0 0, 10 1 0, 10 0 0))'::geometry AS g
),
-- tri_b_xyz: same footprint as tri_b_xy but raised to z=8
-- true 3D shortest distance to tri_a is sqrt(9^2 + 8^2) = sqrt(145) ≈
12.0415945788
tri_b_xyz AS (
SELECT 'TRIANGLE Z ((10 0 8, 11 0 8, 10 1 8, 10 0 8))'::geometry AS g
),
pt_inside_tri_a AS (
SELECT ST_MakePoint(0.25, 0.25, 0.0)::geometry AS g
),
poly_near_tri_a AS (
-- simple square polygon hovering 0.5 units above tri_a in Z
SELECT 'POLYGON Z ((0.2 0.2 0.5, 0.8 0.2 0.5, 0.8 0.8 0.5, 0.2 0.8 0.5,
0.2 0.2 0.5))'::geometry AS g
)
-- 1) REPRO of current pre-fix failure (expected to ERROR today; should
PASS after fix):
-- If your build still errors with "Unsupported geometry type:
Triangle",
-- these SELECTs will fail right here. After the fix, they return
booleans.
SELECT
'tri vs tri (XY, d=8) expect false' AS test,
ST_3DDWithin((SELECT g FROM tri_a), (SELECT g FROM tri_b_xy), 8.0) AS ok
UNION ALL
SELECT
'tri vs tri (XY, d=9) expect true',
ST_3DDWithin((SELECT g FROM tri_a), (SELECT g FROM tri_b_xy), 9.0)
UNION ALL
SELECT
'tri vs tri (XYZ, d=12) expect false',
ST_3DDWithin((SELECT g FROM tri_a), (SELECT g FROM tri_b_xyz), 12.0)
UNION ALL
SELECT
'tri vs tri (XYZ, d=12.05) expect true',
ST_3DDWithin((SELECT g FROM tri_a), (SELECT g FROM tri_b_xyz), 12.05)
UNION ALL
SELECT
'tri vs point (inside, d=0) expect true',
ST_3DDWithin((SELECT g FROM tri_a), (SELECT g FROM pt_inside_tri_a),
0.0)
UNION ALL
SELECT
'tri vs polygon (hovering at z=0.5, d=0.5) expect true',
ST_3DDWithin((SELECT g FROM tri_a), (SELECT g FROM poly_near_tri_a),
0.5);
┌───────────────────────────────────────────────────────┬────┐
│ test │ ok │
├───────────────────────────────────────────────────────┼────┤
│ tri vs tri (XY, d=8) expect false │ f │
│ tri vs tri (XY, d=9) expect true │ t │
│ tri vs tri (XYZ, d=12) expect false │ f │
│ tri vs tri (XYZ, d=12.05) expect true │ t │
│ tri vs point (inside, d=0) expect true │ t │
│ tri vs polygon (hovering at z=0.5, d=0.5) expect true │ t │
└───────────────────────────────────────────────────────┴────┘
(6 rows)
Time: 0,629 ms
}}}
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/2574#comment:6>
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