Intuitively, I thought geometry would be faster than geography distance calculations, but this says otherwise: https://stackoverflow.com/questions/3547699/need-performance-on-postgis-with-geodjango#answer-3551142

The docs here also seem to suggest that distance calculations are more efficient using geography: https://docs.djangoproject.com/en/1.9/ref/contrib/gis/model-api/#srid

Why is this? Is it some sort of optimization or indexing with geography that allows faster distance calculations?

3 Answers 3


Distance calculations that assume shortest distance on the Earth will always be faster than geometry because geometry can be in any projection, and there's no way generally to know that the shortest path in that projection is the 'shortest path' and so you need to go to ellipsoid calcs and potentially insert more vertices for the curvature from the source to the target and then back transform. So yeah, do the trig for distances (unless your path is loxodromic or some other special case and you can apply shortcuts).

  • I think I'm missing the background knowledge to fully understand this, could you please provide some links or examples for me to read more?
    – davidtgq
    Commented Jan 22, 2016 at 14:43

I'll speculate that what the GeoDjango docs are trying to say is that if you have geographic (lat/lon) data, and you want to perform range queries on that data (like ST_DWithin) in meters rather than units of degrees, then you are better served by using the geography type, which uses meters natively. The geography distance calculations themselves (ie distance(pt1, pt2)) are slower than Cartesian distance calculations.

  • Ah ok so if I want to order points from nearest to furthest in relation to another point, I should still use geometry?
    – davidtgq
    Commented Jan 22, 2016 at 15:35
  • Depends on what data you have and how you want to access it. Do you have geographic coordinates, or will all of your data fit inside Rhode Island State Plane, for example? Do you want to find the distance between a point and all other points, or between a point and all points within 1km? Making sure your query/access pattern can take advantage of an index is going to be more important than the speed of an individual distance calculation.
    – dbaston
    Commented Jan 22, 2016 at 16:28
  • I've asked another question with these exact details: gis.stackexchange.com/questions/177861/… Most of the queries from my users will be of the type "Show me all points within roughly 20km from this point, and order them from nearest to furthest". Even though the data has points all over Canada, the user is only interested in points within a small locality with any given query
    – davidtgq
    Commented Jan 22, 2016 at 16:32

Best explained from Microsoft in Spatial Data Types Overview:

Measurements in spatial data types

In the planar, or flat-earth, system, measurements of distances and areas are given in the same unit of measurement as coordinates. Using the geometry data type, the distance between (2, 2) and (5, 6) is 5 units, regardless of the units used.

In the ellipsoidal, or round-earth system, coordinates are given in degrees of latitude and longitude. However, lengths and areas are usually measured in meters and square meters, though the measurement may depend on the spatial reference identifier (SRID) of the geography instance. The most common unit of measurement for the geography data type is meters.

Here are some resources for Geometry and Geography

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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