全部產品
Search
文件中心

ApsaraDB RDS:ST_LineInterpolatePoint

更新時間:Feb 28, 2024

在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)