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 have two datasets in postgres; 1) a bunch of points that represent bus locations 2) city block polygons.

Each bus has a unique ID and each block polygon has a field that has the block name in it. As the bus moves throughout the day, what is the best way to construct a SQL query that returns the block name for each bus point as it travels.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Considering the blocks have no intersections and every of your buses can be inside the only one block at a time, you can try something like this:

SELECT b.*, bl.name 
FROM buses b, blocks bl 
WHERE ST_Within(b.the_geom, bl.the_geom)

While you have a bunch of points, it's very useful to keep last coordinates just in buses table (via triggers), instead of executing queries over all these points you mentioned.

share|improve this answer
    
That was what I was looking for. A lot easier than I thought ;-) –  AdamEstrada Apr 12 '13 at 23:29
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.