Vertex closer to another - Postgis

Asked

Viewed 137 times

0

Is it possible to return the nearest vertex to another? One of the observed geometries is a linestring. As in the figure below:

inserir a descrição da imagem aqui

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

1 answer

1


You can use the function: 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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.