[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgis-users
Subject:    [postgis-users] 3D distance functions for lines with identical start points
From:       Michael Dominice <michael.dominice () gmail ! com>
Date:       2022-02-25 15:32:35
Message-ID: CAF1z0y3LUxP4Oup3zmqRxLWCkFS1BiRgKrqk7MEq2y3qCE4wUA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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@gmail.com

[Attachment #5 (text/html)]

<div dir="ltr">Hi all,<div><br></div><div>I&#39;ve been experiencing some interesting \
behavior attempting to store and query 3-dimensional data using \
PostGIS.</div><div><br></div><div>From what I&#39;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(&#39;LINESTRING Z (0 0 0, 1 1 0)&#39;), \
ST_GeomFromText(&#39;LINESTRING Z (0 0 0, -1 -1 \
0)&#39;))<br>ST_3DShortestLine(ST_GeomFromText(&#39;LINESTRING Z (0 0 0, 1 1 \
0)&#39;), ST_GeomFromText(&#39;LINESTRING Z (0 0 0, -1 -1 0)&#39;))<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(&#39;LINESTRING Z (1 \
1 0, 0 0 0)&#39;), ST_GeomFromText(&#39;LINESTRING Z (-1 -1 0, 0 0 \
0)&#39;))</div><div>ST_3DShortestLine(ST_GeomFromText(&#39;LINESTRING Z (1 1 0, 0 0 \
0)&#39;), ST_GeomFromText(&#39;LINESTRING Z (-1 -1 0, 0 0 \
0)&#39;))</div><div><div><br></div><div>In these cases, the distance is zero, and the \
reported shortest line is &#39;LINESTRING Z(0 0 0, 0 0 \
0)&#39;.</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&#39;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(&#39;LINESTRING Z (0 0 0, 0.5 0.5 0, 1 \
1 0)&#39;), ST_GeomFromText(&#39;LINESTRING Z (0 0 0, -0.5 -0.5 0, -1 -1 \
0)&#39;))<br>ST_3DShortestLine(ST_GeomFromText(&#39;LINESTRING Z (0 0 0, 0.5 0.5 0, 1 \
1 0)&#39;), ST_GeomFromText(&#39;LINESTRING Z (0 0 0, -0.5 -0.5 0, -1 -1 \
0)&#39;))</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&#39;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&#39;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>



_______________________________________________
postgis-users mailing list
postgis-users@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/postgis-users


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic