davidtgq
davidtgq

Reputation: 4010

GeoDjango and PostGIS distance query efficiency concerns

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 possible with a given 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?

Upvotes: 0

Views: 111

Answers (1)

e4c5
e4c5

Reputation: 53774

Well this is really about ten questions.

1) It would only be worth it if this distance query is only slightly more expensive than simply reading all the latitudes and longitudes.

The distance query is not expensive at all compared to reading all the rows.

2) Will GeoDjango or PostGIS be smart enough Postgis will definitely be smart enough. GeoDjango only builds the queries and the query is executed by postgis. http://postgis.net/docs/ST_DWithin.html

3) Does there exist a less precise method to calculate distance in GeoDjango/PostGIS, so we can sacrifice accuracy for speed? If not,

There is no need to sacrifice speed for accuracy. ST_Dwithin is very fast.

3.1) would it be significantly better to roll our own solution? hell no! and it would be plagued with bugs.

Upvotes: 1

Related Questions