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 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
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.*, 
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

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.