我正在使用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)绘制的结果。

有什么可以解释的?
发布于 2022-07-05 07:17:49
如果你依靠你的眼睛来确定这条线是否是最短的,你可能会被误导到这个结论。ST_ShortestLine将返回一条与ST_Distance完全相同的线,这是两个几何的最小二维笛卡尔距离。这正是正在发生的事情:
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)也许你和我分享了你期待的结果,然后我们就可以继续下去了。
https://stackoverflow.com/questions/72861735
复制相似问题