Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion GeoDjango: distance calculation
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
kmishler  
View profile  
 More options Jan 17 2008, 2:18 pm
From: kmishler <kmish...@arinc.com>
Date: Thu, 17 Jan 2008 11:18:41 -0800 (PST)
Local: Thurs, Jan 17 2008 2:18 pm
Subject: GeoDjango: distance calculation
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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.