Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!