名称

ST_LineInterpolatePoint — 返回沿线在百分比指示位置的插值点。

大纲

geometry ST_LineInterpolatePoint(geometry a_linestring, float8 a_fraction);

geography ST_LineInterpolatePoint(geography a_linestring, float8 a_fraction, boolean use_spheroid = true);

描述

返回沿线在百分比指示位置的插值点。 第一个参数是线串。 第二个参数是介于 0 和 1 之间的浮点数,它表示点的位置与线长度的比率。 如果存在 Z 和 M 值,则执行插值计算。

请参阅ST_LineLocatePoint以计算最接近该点的线位置。

[注意]

此函数计算 2D 中的点,然后对 Z 和 M 的值进行插值,而 ST_3DLineInterpolatePoint 计算 3D 中的点,然后仅对 M 值进行插值。

[注意]

从版本 1.1.1 开始,此函数还会插入 M 和 Z 值(如果存在),而之前的版本将它们设置为 0.0。

可用性:0.8.2,1.1.1中添加支持Z和M

更改:2.1.0。 在 2.0.x 之前,这称为 ST_Line_Interpolate_Point。

该函数支持 3d 并且不会丢失 z-index。

示例

This example returns the point 20 percent along a line.

Code
SELECT ST_LineInterpolatePoint(
'LINESTRING(25 50,100 125,150 190)',
0.2);
栅格输出
POINT(51.5974135047432 76.5974135047432)
Figure
Geometry figure for visual-st-lineinterpolatepoint-01

3D 线的中点:

Code
SELECT ST_LineInterpolatePoint(
'LINESTRING(1 2 3,4 5 6,6 7 8)',
0.5);
栅格输出
POINT(3.5 4.5 5.5)
Figure
Geometry figure for visual-st-lineinterpolatepoint-02

直线上距离某点最近的点:

Code
SELECT ST_LineInterpolatePoint(
    line.geom,
    ST_LineLocatePoint(line.geom, 'POINT(4 3)'))
FROM (SELECT 'LINESTRING(1 2,4 5,6 7)'::geometry As geom) AS line;
栅格输出
POINT(3 4)
Figure
Geometry figure for visual-st-lineinterpolatepoint-03

An interpolated point can be offset to the left or right of a line by using ST_OffsetCurve before interpolation. This is useful for locating an address point beside a street centerline.

Code
WITH street AS (
    SELECT 'LINESTRING(0 0, 10 0)'::geometry AS geom,
           100 AS from_num,
           200 AS to_num
)
SELECT
    ST_LineInterpolatePoint(
        ST_OffsetCurve(geom, -2),
        (160 - from_num)::float8 / (to_num - from_num)
    ) AS interpolated_offset_point
FROM street;
栅格输出
interpolated_offset_point
---------------------------
 POINT(6 -2)
Figure
Geometry figure for visual-st-lineinterpolatepoint-04