On 08/29/2010 07:45 PM, kyleduncan wrote:
Hi all,
I am trying to do obtain the distance between two users on my site,
using code I found in this group. We already have geoDjango installed,
though i'm wondering if my problem comes from being on an old version
(i dont know which version we're using - if somebody could tell me how
to check that would be great). We are running Django 1.1
Well, then you're using the geodjango bundled with django 1.1. I don't
remember seeing big changes in django 1.2's changelog regarding
geodjango. So you ought to be OK with that.
the code i am using is:
from django.contrib.gis.geos import Point
from django.contrib.gis.measure import D
my_location = request.user.get_profile().location
their_location = other_user.get_profile().location
my_location.transform(4326)
their_location.transform(4326)
distance = my_location.distance(their_location)
if request.user.get_profile().get_preferences().use_metric
== 1:
distance_result =
round(D(m=my_location.distance(their_location)).km, 1)
else:
distance_result =
round(D(m=my_location.distance(their_location)).mi, 1)
the last section is just a check to see whether the user wants the
result in miles or km. the bit that's troubles me is the transform()
section. if i put in 4326, i just get 0.0 as the result. if i put in
nothing so it's just transform() (which i understand should use 4326),
i get this django Error:
TypeError at /members/GayHopHelper/
transform() takes at least 2 arguments (1 given)
the only thing that works so far is using SRID 32140, which is for
south texas. the results seem ok but definitely a bit inaccurate,
which is to be expected.
I only recently started using geodjango, so I'll just spit out a few
brainstormy ideas without any real solution:
- What's the coordinate system of your user's location data?
- Why transforming before grabbing the distance? Can't you transform
afterwards?
- If you're using the google projection somewhere: did you add it to
your geo database? There's a note somewhere in geodjango's doc about
that 900973 projection. Not having it could throw off a calculation.
- There's also a hint in that doc about a NULL projection that you need
to add to your proj4 or whatever files to enable proper transformations.
Just a brainstorm to get you started ;-)
Reinout
--
Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
Collega's gezocht!
Django/python vacature in Utrecht: http://tinyurl.com/35v34f9
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.