Monday, August 30, 2010

Re: GeoDjango: default 4326 SRID doesn't work for transform()

Hi,

thanks for the tips! to answer your questions:

1. our model doesnt specify a coordinate system, it just saves the lat
and lng that are returned from google maps.
2. i thought transforming had to be done to make a lat/lng point
"spatial" before distance was calculated. have i got that wrong?
3. i'm not actually sure we even have a "geodatabase". all we have are
pointfields in the model for users, which save the lat/lng points from
google.

i'm not really capable enough to know how to proceed on my own from
your points, but for now i'll try removing the transform() (and also
placing it after) and i'll also specify the transform SRID of 900973
(is that the SRID for google or are you talking about something else
with that number?)

thanks again

Kyle

On Aug 30, 9:16 am, Reinout van Rees <rein...@vanrees.org> wrote:
> 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-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment