Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
Postgis Spatial Query

I am trying to create a query that will return a list of points that do not intersect with a line. For the most part it works great and very fast. However I would like to know how far away the nearest line is.

I have tried to use the st_distance function but it is returning null. Does anybody have any tips or guidance to help me solve this?

This is my SQL statement so far:

SELECT p.objectid, p.voidentifier, p.featuretypecd, p.heightagl, st_distance(p.geom::geography, l.geom::geography), p.geom 
FROM vo_point p 
  LEFT JOIN vo_line l ON ST_Intersects(p.geom, l.geom) 
WHERE l.featureid IS NULL 
  and p.featuretypecd in ('537','538','540','541','542','543','544');
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I believe a subquery is what you're looking for:

SELECT p.objectid, p.voidentifier, p.featuretypecd, p.heightagl, p.geom,
  (SELECT min(ST_Distance(p.geom::geography, l2.geom::geography)) FROM vo_line l2)
FROM vo_point p 
LEFT JOIN vo_line l ON ST_Intersects(p.geom, l.geom) 
WHERE l.featureid IS NULL 
  AND p.featuretypecd IN ('537','538','540','541','542','543','544');

This query should return all records where points and lines intersect, and it will also return the distance to the nearest line.

over 4 years ago · Santiago Trujillo Relatório

0

So after more than an hour I decided to abort and try a different approach. Instead I created two views:

create view pylon_temp as SELECT p.objectid, p.voidentifier, p.featuretypecd, p.heightagl, p.geom
FROM vo_point p LEFT JOIN vo_line l ON ST_Intersects(p.geom, l.geom)
WHERE l.featureid IS NULL and p.featuretypecd in ('537','538','540','541','542','543','544');
create view pylon_errors as
select p.objectid, p.voidentifier, p.featuretypecd, p.heightagl, min(st_distance(p.geom::geography, l.geom::geography))as distance, p.geom
from pylon_temp p, vo_line l
where st_dwithin(p.geom,l.geom,0.001)
group by p.objectid, p.voidentifier, p.featuretypecd, p.heightagl, p.geom
order by distance desc;

It may not be the most elegant way of going about this, but it is very quick and I can use the view in my web app / GIS applications.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda