We are starting to use geodjango (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()

The location field will eventually be populated using lat/longs from a
text file.

For now, I populated 3 records in the table:

Airport.objects.create(icao="KBWI",
location=fromstr('POINT(-76.668333333333337 39.175361111111108)',
srid=4326))
Airport.objects.create(icao="KDEN",
location=fromstr('POINT(-104.67317777777778 39.861655555555558)',
srid=4326))
Airport.objects.create(icao="EGLL",
location=fromstr('POINT(-0.4613888888888889 51.477499999999999)',
srid=4326))

When I try to use the api to get distance, I do not get the correct
results:

point = Airport.objects.get(icao="KBWI").location
for airport in Airport.objects.distance(point):
    print airport.icao + ": " + str(airport.distance) + ", " +
str(Distance(degree=airport.distance).nm)

EGLL: 77.1935295397, 0.000727473678024
KBWI: 0.0, 0.0
KDEN: 28.0132524428, 0.000263997564426

select icao, ST_distance(ST_GeomFromText('POINT(-76.668333333333337
39.175361111111108)',4326), location) from common_airport;
 icao |   st_distance
------+------------------
 KBWI |                0
 KDEN | 28.0132524427637
 EGLL | 77.1935295397234


select icao,
distance_sphere(ST_GeomFromText('POINT(-76.668333333333337
39.175361111111108)',4326), location) from common_airport;
 icao |   distance_sphere        converting manually to nm
------+----------------------
 KDEN |      2393555.0105449     1292.41631
 KBWI | 2.81660258041303e-10     0
 EGLL |     5833168.46744864     3149.65875


Using distance_sphere, I get the correct results.  Is there any way to
use the django api to get distance_sphere?

I also tried using the SRID 32140:

class Airport(models.Model):
    icao = models.CharField('ICAO', max_length=4)
    location = models.PointField(32140)

I used the same code to populate the records - it's nice that
geodjango can do that.

When I try to use the api to get distance, I get closer results, but
they're still not correct:

point = Airport.objects.get(icao="KBWI").location
for airport in Airport.objects.distance(point):
    print airport.icao + ": " + str(airport.distance) + ", " +
str(Distance(meter=airport.distance).nm)

EGLL: 6258767.81814, 3379.46426466
KBWI: 0.0, 0.0
KDEN: 2442966.58517, 1319.09642828

Is there any way to use the django api to get the distance?


Versions:
 WhiteBox Enterprise Linux 3.0 (clone of Red Hat enterprise 3.0)
 gcc 3.2.3 / glibc 3.2.3
 Python 2.4.2
 ctypes 1.0.2
 PostgreSQL 8.2.4
 postgis 1.3.2
 geos 3.0.0
 proj4 4.6.0
 curl 7.17.1 (needed for gdal)
 expat 2.0.1 (needed for gdal)
 gdal 1.5.0

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to