Opened 4 days ago
Last modified 43 hours ago
#5827 new defect
ST_3DDFullyWithin gives wrong result
Reported by: | nbvfgh | Owned by: | pramsey |
---|---|---|---|
Priority: | critical | Milestone: | PostGIS 3.6.0 |
Component: | postgis | Version: | 3.5.x |
Keywords: | Cc: |
Description
When translating the Point, Linestring, and Polygon by 1 unit on the x and y axes on the plane Z=1 and tested them separately with ST_DFullyWithin and ST_3DDFullyWithin, obtaining inconsistent results.
SELECT ST_DFullyWithin(a, a_translate, 2), ST_3DDFullyWithin(a, a_translate, 2) FROM (SELECT ST_POINTS(ST_GeomFromText('POINT Z(0 0 1)')) AS a, ST_POINTS(ST_GeomFromText('POINT Z(1 1 1)')) AS a_translate); -- result:{t, t} SELECT ST_DFullyWithin(a, a_translate, 2), ST_3DDFullyWithin(a, a_translate, 2) FROM (SELECT ST_POINTS(ST_GeomFromText('MULTIPOINT Z(0 0 1, 1 1 1)')) AS a, ST_POINTS(ST_GeomFromText('MULTIPOINT Z(1 1 1, 2 2 1)')) AS a_translate); -- result:{t, f} SELECT ST_DFullyWithin(a, a_translate, 2), ST_3DDFullyWithin(a, a_translate, 2) FROM (SELECT ST_GeomFromText('LINESTRING Z(0 0 1, 0 1 1, 1 1 1, 1 0 1, 0 0 1)') AS a, ST_GeomFromText('LINESTRING Z(1 1 1, 1 2 1, 2 2 1, 2 1 1, 1 1 1)') AS a_translate); -- result:{t, f} SELECT ST_DFullyWithin(a, a_translate, 2), ST_3DDFullyWithin(a, a_translate, 2) FROM (SELECT ST_GeomFromText('POLYGON Z((0 0 1, 0 1 1, 1 1 1, 1 0 1, 0 0 1))') AS a, ST_GeomFromText('POLYGON Z((1 1 1, 1 2 1, 2 2 1, 2 1 1, 1 1 1))') AS a_translate); -- result:{t, f}
Each point in geometry a should be translated to its corresponding point in geometry a_translate, and the distance between each pair of points should be √(2). Therefore, to make DFullyWithin and 3DDFullyWithin true, setting the parameter distance to √(2) is completely sufficient.
SELECT ST_DFullyWithin(a, a_translate, sqrt(2)), ST_3DDFullyWithin(a, a_translate, sqrt(2)) FROM (SELECT ST_GeomFromText('POLYGON Z((0 0 1, 0 1 1, 1 1 1, 1 0 1, 0 0 1))') AS a, ST_GeomFromText('POLYGON Z((1 1 1, 1 2 1, 2 2 1, 2 1 1, 1 1 1))') AS a_translate); -- result{t, f}
Version Info:
POSTGIS="3.5.0 3.5.0" [EXTENSION] PGSQL="170" GEOS="3.13.0-CAPI-1.19.0" SFCGAL="SFCGAL 1.5.2, CGAL 5.6.1, BOOST 1.84.0"
Attachments (1)
Change History (6)
by , 4 days ago
comment:1 by , 3 days ago
comment:2 by , 3 days ago
Milestone: | PostGIS 3.5.2 → PostGIS 3.6.0 |
---|
comment:3 by , 2 days ago
I know we changed the behavior in ST_DFullyWithin in 3.5.0 as noted in https://git.osgeo.org/gitea/postgis/postgis/src/branch/stable-3.5/NEWS#L90
I guess we didn't change the behavior of ST_3DDFullyWithin
comment:4 by , 2 days ago
Since there is currently no implementation of 3DContains or 3DWithin (at least I haven't seen it in the documentation), I have a simple suggestion. For ST_3DDFullyWithin (a, b, dis), you can use ST_3DClosestPoint(a. b) to first calculate the cloest point from geometry a to geometry b, then use ST_3DMaxDistance(p, b) to calculate the maximum distance from the point p to geometry b, and finally compare the obtained distance with dis.
That is, ST_3DDFullyWithin (A, B, R) ⇔ ST_3DMaxDistance(ST_3DClosestPoint(A, B), B) ⇐ R && ST_3DMaxDistance(ST_3DClosestPoint(B, A), A) ⇐ R The same applies to 2D.
This issue also exists in the unreleased version 3.6.0. Version Info:
POSTGIS="3.6.0dev 3.5.0-91-g593df9088" [EXTENSION] PGSQL="170" GEOS="3.13.0-CAPI-1.19.0"