Nome

ST_LineInterpolatePoint — Returns a point interpolated along a line at a fractional location.

Sinopse

geometry ST_LineInterpolatePoint(geometry a_linestring, float8 a_fraction);

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

Descrição

Retorna um ponto interpolar com uma linha. Primeiro argumento deve ser uma LINESTRING. Segundo argumento é um float8 entre 0 e 1 representando fração do comprimento total da linestring do ponto tem que ser localizado.

Veja ST_LineLocatePoint para computar a linha de localização mais perto de um ponto.

[Nota]

This function computes points in 2D and then interpolates values for Z and M, while ST_3DLineInterpolatePoint computes points in 3D and only interpolates the M value.

[Nota]

Desde a liberação 1.1.1 essa função também interpola valores M e Z (quando presentes), enquanto as liberações anteriores configura eles para 0.0.

Disponibilidade: 0.8.2, Suporte a Z e M adicionado em 1.1.1

Alterações: 2.1.0 para 2.0.x foi chamada ST_Line_Interpolate_Point.

This function supports 3d and will not drop the z-index.

Exemplos

This example returns the point 20 percent along a line.

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

The mid-point of a 3D line:

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

The closest point on a line to a point:

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;
Raster Outputs
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;
Raster Outputs
interpolated_offset_point
---------------------------
 POINT(6 -2)
Figure
Geometry figure for visual-st-lineinterpolatepoint-04