Nombre

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

Sinopsis

geometry ST_LineInterpolatePoint(geometry a_linestring, float8 a_fraction);

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

Descripción

Devuelve un punto interpolado a lo largo de una línea. El primer argumento debe ser un LINESTRING. El segundo argumento es un float8 entre 0 y 1 que representa la fracción de la longitud total de la cadena de línea del punto tiene que ser localizado.

Ver ST_LineLocatePoint para calcular la ubicación de la línea más cercana a un punto.

[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 la versión 1.1.1 esta función también interpola los valores M y Z (cuando están presentes), mientras que las versiones anteriores las establecen en 0.0.

Disponibilidad: 0.8.2, Z y M soportados añadidos en 1.1.1

Cambiado: 2.1.0. Hasta 2.0. x esto se llamaba ST_Line_Interpolate_Point.

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

Ejemplos

This example returns the point 20 percent along a line.

Code
SELECT ST_LineInterpolatePoint(
'LINESTRING(25 50,100 125,150 190)',
0.2);
Output
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);
Output
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;
Output
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;
Output
interpolated_offset_point
---------------------------
 POINT(6 -2)
Figure
Geometry figure for visual-st-lineinterpolatepoint-04