<div dir="ltr">Hi all,<div><br></div><div>I've been experiencing some interesting behavior attempting to store and query 3-dimensional data using PostGIS.</div><div><br></div><div>From what I'm seeing, ST_3DDistance and ST_3DShortestLine perform strangely for line strings that share a start point.<br><br>For example, the following expressions are returning null:<br>ST_3DDistance(ST_GeomFromText('LINESTRING Z (0 0 0, 1 1 0)'), ST_GeomFromText('LINESTRING Z (0 0 0, -1 -1 0)'))<br>ST_3DShortestLine(ST_GeomFromText('LINESTRING Z (0 0 0, 1 1 0)'), ST_GeomFromText('LINESTRING Z (0 0 0, -1 -1 0)'))<br><br>If I reverse the positions in the lines such that they share a common final point, the results seem to be correct:<br><br>ST_3DDistance(ST_GeomFromText('LINESTRING Z (1 1 0, 0 0 0)'), ST_GeomFromText('LINESTRING Z (-1 -1 0, 0 0 0)'))</div><div>ST_3DShortestLine(ST_GeomFromText('LINESTRING Z (1 1 0, 0 0 0)'), ST_GeomFromText('LINESTRING Z (-1 -1 0, 0 0 0)'))</div><div><div><br></div><div>In these cases, the distance is zero, and the reported shortest line is 'LINESTRING Z(0 0 0, 0 0 0)'.</div><div><br></div><div>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:<br><br>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)'))<br>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)'))</div><div><br></div><div>Results are:</div><div>0.7071067811865476   # Remark, this is SQRT(2) / 2, I believe?<br>LINESTRING Z (0 0 0, -0.5 -0.5 0)</div><div><br></div><div>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.</div><div><br></div><div>I've verified this behavior on PostGIS 3.2 and 3.0, using PG 12 and 13.</div><div><br></div><div>Does this sound correct? Thanks in advance.</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Mike Dominice<div><a href="mailto:michael.dominice@gmail.com" target="_blank">michael.dominice@gmail.com</a></div></div></div></div></div>