Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

Intuitively, I thought geometry would be faster than geography distance calculations, but this says otherwise: http://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?

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer
    
Ah ok so if I want to order points from nearest to furthest in relation to another point, I should still use geometry? – David Tan Jan 22 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 Jan 22 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 – David Tan Jan 22 at 16:32

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).

share|improve this answer
    
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? – David Tan Jan 22 at 14:43

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

share|improve this answer

Your Answer

 
discard

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.