ST_LineInterpolatePoint

在LineString上指定位置插入点对象,并返回该点。

语法

geometry  ST_LineInterpolatePoint(geometry  aLinestring , float8  aFraction);
geography  ST_LineInterpolatePoint(geography  aLinestring , float8  aFraction);

参数

参数名称

描述

aLinestring

目标LineString对象。

aFraction

插入点位于该线段的百分比,是一个从0到1的浮点值。

描述

  • 该函数支持3D对象,并且不会删除Z坐标。

  • 该函数支持M坐标。

  • 使用地理坐标系时会根据球面距离进行计算。

示例

  • 计算给定线段的中点坐标:

    SELECT ST_AsText(ST_LineInterpolatePoint(geom, 0.5)) FROM (SELECT 'LINESTRING(0 0,2 2)'::geometry as geom) As test;
     st_astext
    ------------
     POINT(1 1)
    (1 row)
    
    
    SELECT ST_AsText(ST_LineInterpolatePoint(geog, 0.5)) FROM (SELECT 'LINESTRING(0 0,2 2)'::geography as geog) As test;
    
    ------------------------------------------
     POINT(0.99969732796684 1.00015638159834)
  • 获取线上距离某个Geometry对象最近的点:

    SELECT ST_AsText(ST_LineInterpolatePoint(geom, ST_LineLocatePoint(geom, 'POINT(1 1)'::geometry))) FROM (SELECT 'LINESTRING(0 0,0 2)'::geometry As geom) As test;
     st_astext
    ------------
     POINT(0 1)
    (1 row)
    
    -- geography
    SELECT ST_AsText(ST_LineInterpolatePoint(geog, ST_LineLocatePoint(geog, 'POINT(1 1)'::geography))) FROM (SELECT 'LINESTRING(0 0,0 2)'::geography As geog) As test;
    ---------------------------
     POINT(0 1.00015229710421)