postgis distance between two points on a line

空扰寡人 提交于 2019-12-03 09:10:02
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;

Distance length_m, distance to_point_on_line and from_point_on_line. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!