Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have records stored in a table with latitude/longitude coordinates stored in a geometry field. I want to find all records nearby a user supplied reference point. Note "nearby" probably means less than 100km (possibly even smaller).

Most examples I see use ST_DWithin. Is there a reason you can't use ST_Distance? What is the difference between using ST_DWithin and ST_Distance to do this?

For example:

SELECT name, ST_AsText(coords)
FROM places
WHERE ST_DWithin(coords, ST_GeomFromText('POINT(-12.5842 24.4944)',4326), 1)


SELECT name, ST_AsText(coords)
FROM places
WHERE ST_Distance(coords, ST_GeomFromText('POINT(-12.5842 24.4944)',4326)) < 1
share|improve this question
up vote 8 down vote accepted

ST_Distance is a calculation which must be executed and evaluated on every row. ST_DWithin can use an index, so it's likely to be much faster.

share|improve this answer
Also managed to find this which says pretty much same thing: – User Dec 10 '13 at 5:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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