Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

226
Vistas
Building a neighbor query based on another layer's qualities

I am working with PostGIS and PostgreSQL. I have 2 layers of data.

  • A layer with polygons with some details attached to it i.e. table polygons with fields id, quality and geom (geometry shape).
  • Another, a layer with points: a table points with fields id and geom (geometry shape).

For each point (example point marked yellow), I would like to find the nearest point which shows a strong characteristic but this is within a range (also yellow). To get this quality, I have to look at the details of polygons surrounding the points under investigation (green).

SELECT pt1.id, pt2.id, p.id, sum(p.quality) as quality_total
FROM polygons p, points pt1, points pt2
WHERE ST_DWithin(pt1.geom, pt2.geom, 100) --points maximum 100 units away from each other
  AND ST_DWithin(p.geom, pt2.geom, 10) --polygons maximum 10 units away from point pt2
  AND (pt1.id = 1 OR pt1.id = 2) --specific points
GROUP BY quality, pt1.id, pt2.id, p.id 

Above is my attempt so far. As you can see it is for only specific points. I was hoping the output would be for all points, like:

pt1.id, pt2.id, sum(p.quality)

to mean that pt1.id is a point, pt2.id is the point nearest to pt1 (exhibiting a quality) and sum(p.quality) is the sum of the quality of all the polygons in pt2's range. I am at a loss how to continue building the query. I would appreciate any help. I suppose this is a form of clustering problem but I am not so educated here.

Image complementing the explanation of my problem

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda