0

A Region has a latitude, longitude (GEOMETRY('POINT')) and a radius.

Using postgis, how can I query all Regions where the distance from pointParam and region.point is less than or equal to region.radius?

SELECT *
FROM region
ORDER BY region.origin <-> my_location
WHERE (region.origin <-> my_location) <= region.radius // <--- This is where I don't know what to put
LIMIT 5;

bumped to the homepage by Community yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

Here's the (pseudo) query that worked for me:

SELECT *
FROM regions
WHERE ST_DWithin("origin", ST_MakePoint(lat, long), max, false) = true AND ST_Distance("origin", ST_MakePoint(lat, long), false) - radius <= 0 
ORDER BY distance ASC 
LIMIT 5;

I figured out how to do the actual distance query; use the built in gis distance function and just subtracted radius from the distance. If that value is less than or equal to 0, then it should not be returned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.