I have a table containing ‘places’, each place with its name (pk) and lat, lng. Given a bounding box of coordinates (lat/lng perimeters), what is an efficient way to retrieve only the places within that box?
I could (and currently do) iterate over all places and check if each one falls within the box. However, I am looking for something more efficient; perhaps constructing some index to define places by their location/possible boxes.
I am using Django framework, but am open to any lower-level optimizations as well (at the SQL level, perhaps).
If you are going to do Geo-Spatial queries on a DB you should be using a Spatial database
All major DB system support it or has extensions to add support for this.
Once you got a spatial DB you store your coordinates as ST_POINT and the DB indexes them in a way that lets you do efficient queries (in a polygin, in range, etc)