Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

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 am working on a project for ambulance management using GIS. using Qgis,Postgresql,Postgis I am finding it difficult querying using St_dwithin as well as St_buffer. My aim is to find any hospitals available to a victim within a particular radius.I have the information of the victims locations in form of geometry.plz kindly help.

share|improve this question
Please be specific. What's wrong with ST_DWithin? It's the correct approach. – underdark Apr 6 '13 at 14:58
st_ d within requires me to give them two geography values...where as my aim is to find the available geometry values of hospitals from my victims location. – arianna Apr 6 '13 at 15:33
If you are working on a real life project (not a term paper or something) you don't want to find closest hospital using buffers - you want to find the quickest to get to by the road. And that means to use routing and traffic statistics. – SS_Rebelious Apr 6 '13 at 18:08

PostGIS FAQ answers that question. The two geography values that you give to ST_DWithin are the victim location that you have and the hospital location you should have in your database.

share|improve this answer

The closest (in straight line) Hospital from the event can be found with a query like this:

      st_distance(a.geom, ST_GeomFromText('POINT($X $Y)', <SRID>)) as distance 
      data.hospital_db as a
ORDER BY distance ASC limit 1;

The query calculates for each hospital the distance between them and the event, and then it returns the id of the hospital and the distance between them in straight line .

Then it orders the hospital with an ascending order based on the distance. It returns only the first result.

Also be sure to check your projection, one degree is not equal to one kilometer!

share|improve this answer

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.