[postgis-users] 3D distance functions for lines with identical start points

Michael Dominice michael.dominice at gmail.com
Fri Feb 25 07:32:35 PST 2022


Hi all,

I've been experiencing some interesting behavior attempting to store and
query 3-dimensional data using PostGIS.

>From what I'm seeing, ST_3DDistance and ST_3DShortestLine perform strangely
for line strings that share a start point.

For example, the following expressions are returning null:
ST_3DDistance(ST_GeomFromText('LINESTRING Z (0 0 0, 1 1 0)'),
ST_GeomFromText('LINESTRING Z (0 0 0, -1 -1 0)'))
ST_3DShortestLine(ST_GeomFromText('LINESTRING Z (0 0 0, 1 1 0)'),
ST_GeomFromText('LINESTRING Z (0 0 0, -1 -1 0)'))

If I reverse the positions in the lines such that they share a common final
point, the results seem to be correct:

ST_3DDistance(ST_GeomFromText('LINESTRING Z (1 1 0, 0 0 0)'),
ST_GeomFromText('LINESTRING Z (-1 -1 0, 0 0 0)'))
ST_3DShortestLine(ST_GeomFromText('LINESTRING Z (1 1 0, 0 0 0)'),
ST_GeomFromText('LINESTRING Z (-1 -1 0, 0 0 0)'))

In these cases, the distance is zero, and the reported shortest line is
'LINESTRING Z(0 0 0, 0 0 0)'.

As an additionally interesting note, inserting a point in the middle of the
line string appears to remove the null return, but then the distance
results that don't seem to make sense for me. Using the initial LINESTRING
query, but adding an interpolated midpoint to the geometry:

ST_3DDistance(ST_GeomFromText('LINESTRING Z (0 0 0, 0.5 0.5 0, 1 1 0)'),
ST_GeomFromText('LINESTRING Z (0 0 0, -0.5 -0.5 0, -1 -1 0)'))
ST_3DShortestLine(ST_GeomFromText('LINESTRING Z (0 0 0, 0.5 0.5 0, 1 1
0)'), ST_GeomFromText('LINESTRING Z (0 0 0, -0.5 -0.5 0, -1 -1 0)'))

Results are:
0.7071067811865476   # Remark, this is SQRT(2) / 2, I believe?
LINESTRING Z (0 0 0, -0.5 -0.5 0)

I've tried to post a minimal example here, but this behavior persists
across Z values, and in different projections - sharing the same initial
point seems to be the issue.

I've verified this behavior on PostGIS 3.2 and 3.0, using PG 12 and 13.

Does this sound correct? Thanks in advance.

-- 
Mike Dominice
michael.dominice at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20220225/508bfc35/attachment.html>


More information about the postgis-users mailing list