PostGIS -ST_SHORTESTLINE与LAT LON不正确

发布于 2025-02-13 03:15:16 字数 580 浏览 0 评论 0原文

我正在使用PostGis st_shortestline来计算一条线和点之间的最短线(一些米):

SELECT ST_AsText(
        ST_ShortestLine(ST_GeomFromText('POINT(2.33123610021 48.87902639841)', 4326),
                ST_GeomFromText('LINESTRING ( 2.33122725689 48.87902421718, 2.33123229444 48.87901190847)', 4326))
        ) As sline;

我得到的结果似乎不连贯,给定的行不是最短的线:

LINESTRING(2.33123610021 48.87902639841,2.331227760998549 48.87902298544515)

这是一幅图纸结果,使用Mercator投影(JOSM)。

“点的绘图”

可以解释这一点?

I'm calculating the shortest line between a Line and a Point for very short distances (some meters), using Postgis ST_ShortestLine:

SELECT ST_AsText(
        ST_ShortestLine(ST_GeomFromText('POINT(2.33123610021 48.87902639841)', 4326),
                ST_GeomFromText('LINESTRING ( 2.33122725689 48.87902421718, 2.33123229444 48.87901190847)', 4326))
        ) As sline;

I get a result which does not seem coherent, the given line not being the shortest one:

LINESTRING(2.33123610021 48.87902639841,2.331227760998549 48.87902298544515)

Here is a drawing of the result, using the Mercator projection (JOSM).

Drawing of the points

What could explain this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

徒留西风 2025-02-20 03:15:16

如果您依靠眼睛来确定绘制线是否是最短的线条,那么您可能会误导这一结论。 ST_SHORTESTLINE将返回一条与st_distance完全相同的行,这是两个几何的最小2D笛卡尔距离。这正是正在发生的事情:

WITH j (line,point) AS (
  VALUES ('SRID=4326;POINT(2.33123610021 48.87902639841)',
          'SRID=4326;LINESTRING(2.33122725689 48.87902421718, 2.33123229444 48.87901190847)')
)
SELECT   
  ST_Length(ST_ShortestLine(point,line)), -- length of the shortest line
  ST_Distance(line,point),                -- distance between 'point' and 'line'
  ST_AsEWKT(ST_ShortestLine(point,line))  -- the shortest line as EWKT 
FROM j;

       st_length       |      st_distance      |                                       st_asewkt                                        
-----------------------+-----------------------+----------------------------------------------------------------------------------------
 9.010592472335791e-06 | 9.010592472335791e-06 | SRID=4326;LINESTRING(2.331227760998549 48.87902298544515,2.33123610021 48.87902639841)
(1 row)

也许您分享了您期望的结果,我们可以从那里去。

If you're relying on your eyes to determine if the drawn line is the shortest one you might have been mislead to this conclusion. ST_ShortestLine will return a line with exact same length of ST_Distance, which is the minimum 2D cartesian distance of two geometries. And it is exactly what is happening:

WITH j (line,point) AS (
  VALUES ('SRID=4326;POINT(2.33123610021 48.87902639841)',
          'SRID=4326;LINESTRING(2.33122725689 48.87902421718, 2.33123229444 48.87901190847)')
)
SELECT   
  ST_Length(ST_ShortestLine(point,line)), -- length of the shortest line
  ST_Distance(line,point),                -- distance between 'point' and 'line'
  ST_AsEWKT(ST_ShortestLine(point,line))  -- the shortest line as EWKT 
FROM j;

       st_length       |      st_distance      |                                       st_asewkt                                        
-----------------------+-----------------------+----------------------------------------------------------------------------------------
 9.010592472335791e-06 | 9.010592472335791e-06 | SRID=4326;LINESTRING(2.331227760998549 48.87902298544515,2.33123610021 48.87902639841)
(1 row)

Perhaps you share the result you're expecting and we can go from there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文