> We are starting to usegeodjango(revision 7003) and are having
> problems using the api to calculate distance.
>
> class Airport(models.Model):
> icao = models.CharField('ICAO', max_length=4)
> location = models.PointField()
>
First, a reminder to add the `objects.GeoManager()` to your models --
it appears that you just omitted it in this post (or else you would
have received errors).
> Using distance_sphere, I get the correct results. Is there any way to
> use the django api to get distance_sphere?
I just clarified this in the documentation - the current distance API
currently works only with projected coordinate systems. Geodetic
systems, such as WGS84 (the default), will just use the degree
conversion factor, thus producing inaccurate results. I know of
`distance_sphere`, however, it only supports calculation between
points in PostGIS. Thus, geodetic support was purposely delayed until
I could come up with a better solution.
> I also tried using the SRID 32140 ...
> When I try to use the api to get distance, I get closer results, but
> they're still not correct:
SRID 32140 is "NAD83 / Texas South Central", thus I would not be
surprised if you obtained invalid results when using it for geographic
data that is outside it's bounds (e.g., KDEN, or Denver International
Airport, is a long way from South Texas). See
http://www.spatialreference.org/ref/epsg/32140/.
One option is to use custom SQL to perform the calculations using
`distance_sphere` -- a patch adding such support would be even better
(I created ticket #6414 for this purpose). An interim measure would
be to just support such calculations for PointFields, which would
requiring some hacking on the `PostGISDistance` SQL construction
object in django/contrib/gis/db/backends/postgis/query.py
Best Regards,
-Justin