Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
2  
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
4  
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

2 Answers 2

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:

Select 
      id, 
      st_distance(a.geom, ST_GeomFromText('POINT($X $Y)', <SRID>)) as distance 
from
      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

 
discard

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.