2

For example, if I want a query that says "show me all houses within 50km from here and order them from nearest to furthest", these are the questions and concerns I have:

  1. Assuming we are using EC2 (application server with GeoDjango) and RDS (database server with PostGIS), it seems that this query would execute on RDS. This is a problem, isn't it? Not only is RDS optimized for IOPS, but we only have one RDS instance serving all our EC2 instances. It would only be worth it if this distance query is only slightly more expensive than simply reading all the latitudes and longitudes.

  2. Will GeoDjango or PostGIS be smart enough to run precise distance calculations only on houses that are within a reasonable distance, skipping all the houses that are too far away to matter? For example, it can calculate the maximum bounds given a radius, and only compute distances for houses within those bounds.

  3. Does there exist a less precise method to calculate distance in GeoDjango/PostGIS, so we can sacrifice accuracy for speed? If not, would it be significantly better to roll our own solution?

closed as too broad by PolyGeo Jan 11 '16 at 1:46

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to GIS SE! As a new user please take the Tour where you will see that there should be only one question asked per question. – PolyGeo Jan 11 '16 at 1:46
  • If you set up Django with a PostGIS backend, then GeoDjango does essentially create PostGIS queries for you through distance lookups, it also automatically creates spatial indexes on your tables for models with geographic fields. The lookups are thus almost as fast as PostGIS queries. See docs.djangoproject.com/en/1.9/ref/contrib/gis/db-api/… – yellowcap Jan 12 '16 at 21:15
2
  1. It's for this purpose PostGIS exists... > Don't read "all the latitudes and longitudes" just use the PostGIS geometry/geography.
  2. With PostGIS, you just need to find all points within your polygon (created from a buffer around your point). If you use spatial index, you will never have to make calculation for every points just the ones within the bounding box around your circle of 50km... (it will ignored all points outside)
  3. Don't roll our own solution because spatial indexes already do the optimization. You will not make sacrifice at all.

Make some tests with PostGIS outside Django with pure PostGIS queries (only a point table is required)

For spatial index, go to http://postgis.net/workshops/postgis-intro/indexing.html to understand.

See also this other blog post to find about nearest search with PostGIS.

  • 3. I mean what if I don't care too much about accuracy, but want fast searches? I was thinking of simply taking all the points between two sets of lat/lng, and compare the difference in the lat/lng numbers to order them from nearest to furthest. This is of course less accurate, but very simply, fast, and easy to implement – dvtan Jan 11 '16 at 1:58
  • It's what an index do! Read the link about indexing, please – ThomasG77 Jan 11 '16 at 2:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.