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.
SELECT ST_LineInterpolatePoint( 'LINESTRING(25 50,100 125,150 190)', 0.2);
POINT(51.5974135047432 76.5974135047432)
3D 线的中点:
SELECT ST_LineInterpolatePoint( 'LINESTRING(1 2 3,4 5 6,6 7 8)', 0.5);
POINT(3.5 4.5 5.5)
直线上距离某点最近的点:
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)
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.
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)