Vertex closer to other - Postgis

0

Is it possible to return the vertex closer to another? Being that one of the observed geometries is a linestring. As in the figure below:

I want to return the single vertex of the linestring (which is represented by the black dots) that is closest to the red dot (which does not belong to the linestring but is on it). Is there any function in postgis for this?

    
asked by anonymous 18.11.2015 / 15:09

1 answer

0

You can use the ST_ClosestPoint ()

SELECT 
    ST_AsText(ST_ClosestPoint(linha_qualquer, ponto_escolhido)) AS vertice_mais_proximo
FROM (
    SELECT
            l.geom AS linha_qualquer,
            p.geom AS ponto_escolhido
    FROM 
            linhas l, pontos p
    WHERE 
            p.gid = 1
) AS foo;
    
24.04.2016 / 16:46