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.

Imagine a table of points of interest along with lat/long. The user identifies two of these points. I want to do the following:

  1. Calculate a great-circle path between these points
  2. Find all POIs that lie within "n" miles of the great-circle path from step 1.

I'm totally new to this stuff, what might be a good tool for accomplishing this? And how would you go about solving it using that tool?

Thanks!

share|improve this question
    
Great tutorial question which shows the spatial abilities of postgis +1 –  nickves Oct 29 '12 at 0:17
add comment

2 Answers 2

up vote 3 down vote accepted

One-liner, assuming the POI points are stored in a "geography" column, you supply the ids of the two points and the search radius in meters:

WITH line AS (
  SELECT ST_MakeLine(p.geog::geometry, q.geog::geometry)::geography AS geog
  FROM pois p, pois q
  WHERE p.id = :id1 and q.id = :id2
)
SELECT p.name, p.id
FROM pois p
JOIN line
ON ST_DWithin(p.geog, line.geog, :radius);

Only complication is that the geography points have to be cast to geometry to access the line building function, and the line has to then be cast back to geography for use in the distance query.

share|improve this answer
    
Terrific -- thanks very much! –  boozedog Oct 28 '12 at 13:17
    
Paul, would you mind explain the query a little bit? They didn't teach us SQL in the university and the query is above my current understanding level. –  nickves Oct 29 '12 at 0:21
    
The "WITH" block pulls out the two points of interest and create a line out of them. So now you have a line in a relation named "line". The next block joins the "line" relation to the pois table, using the condition that only points within the radius will be in the final output relation, which is the condition the questioner was looking for: "only points within N meters of the line between points A and B" –  Paul Ramsey Oct 29 '12 at 17:21
    
Reading up on "WITH" queries will make your life brighter and happier. postgresql.org/docs/current/static/queries-with.html –  Paul Ramsey Oct 31 '12 at 18:40
add comment

ArcMap has a select-features-within-a-certain radius-of-another-feature tool. It's on the Select by Location dialog box. I wouldn't be surprised if other programs like QGIS have similar functionality.

Just tell the software the distance and go from there.

share|improve this answer
    
Using software as big black boxes doesn't help you understand what are you doing. "Just telling the software to do something" for you it's big trap produsing something that you don't know if it's correct or not. Yes the issue here is trivial, but imo this way you make the software doing what you want, instead doing something the software is able to do. –  nickves Oct 29 '12 at 0:28
add comment

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.