直线上两点之间的距离 [英] postgis distance between two points on a line

查看:156
本文介绍了直线上两点之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条路线(如LINESTRING)和两辆有位置的车辆(如POINT).我需要计算路径上 的两点之间的距离.

I have a route (as a LINESTRING) and two vehicles with a position (as a POINT). I need to calculate the distance between the two points over the route.

作为一个额外的困难,我认为在车辆此时不在路线上的情况下,我还需要测量从点到直线上最近点的距离.

As an added difficulty I think I also need to measure the distance from the point to the closest point on the line in the case that the vehicle is not on the route at that moment.

我正在使用它来查找路线上的最近点:

I'm using this to find the closest point on the route:

SELECT ST_AsText(ST_ClosestPoint(pt,line)) AS cp_pt_line, 
    ST_AsText(ST_ClosestPoint(line,pt)) As cp_line_pt
FROM (SELECT 'POINT(100 100)'::geometry As pt, 
    'LINESTRING (20 80, 98 190, 110 180, 50 75 )'::geometry As line
) As foo;

查询中可能吗?

推荐答案

SELECT     ST_Length(ST_GeographyFromText(ST_AsText(ST_Line_Substring(line,ST_Line_Locate_Point(line,ST_ClosestPoint(line,fpt)),ST_Line_Locate_Point(line,ST_ClosestPoint(line,tpt)))))) As length_m,
                                                                   ST_Distance(ST_ClosestPoint(line,tpt)::geography, tpt::geography) as to_point_to_line_m,
                                                                   ST_Distance(ST_ClosestPoint(line,fpt)::geography, fpt::geography) as from_point_to_line_m,
                                                                   ST_AsText(ST_ClosestPoint(line,tpt)) as to_point_on_line,
                                                                   ST_AsText(ST_ClosestPoint(line,fpt)) as from_point_on_line,
                                                                   ST_AsText(tpt) as to_point,
                                                                   ST_AsText(fpt) as from_point
                                           FROM ( SELECT 'SRID=4326;POINT(1)'::geometry As tpt,
                                                                                          'SRID=4326;POINT(2)'::geometry As fpt,
                                                                                          ST_Segmentize('SRID=4326;LINESTRING(123)'::geometry,  0.00001) As line
                                                       ) As foo;

距离length_m,到在线点和从在线点的距离. :)

Distance length_m, distance to_point_on_line and from_point_on_line. :)

这篇关于直线上两点之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆