Google Groups Home
Help | Sign in
AttributeError: 'VincentyDistance' object has no attribute '_kilometers'
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all
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
Ben Sizer  
View profile
 More options Dec 24 2006, 9:54 pm
From: "Ben Sizer" <kylo...@gmail.com>
Date: Mon, 25 Dec 2006 02:54:09 -0000
Local: Sun, Dec 24 2006 9:54 pm
Subject: AttributeError: 'VincentyDistance' object has no attribute '_kilometers'
This seems to be some odd sort of interaction with properties and maybe
subclasses, but I can't get the distance() stuff to work properly.
Here's the end of a traceback, with hopefully all the relevant
information:

  File "F:\code\pyprojects\kproj\controllers.py", line 164, in index
    theDistance = geography.xdistance(myLoc,theirLoc)
  File "F:\code\pyprojects\kproj\geography.py", line 46, in xdistance
    return geopy.distance.distance(x,y).kilometers
  File
"F:\code\Python24\lib\site-packages\geopy-0.93-py2.4.egg\geopy\distance.py" ,
line 344, in kilometers
AttributeError: 'VincentyDistance' object has no attribute
'_kilometers'

If I change .kilometers to .miles, I get a similar error:

  File "F:\code\pyprojects\kproj\controllers.py", line 164, in index
    theDistance = geography.xdistance(myLoc,theirLoc)
  File "F:\code\pyprojects\kproj\geography.py", line 46, in xdistance
    return geopy.distance.distance(x,y).miles
  File
"F:\code\Python24\lib\site-packages\geopy-0.93-py2.4.egg\geopy\distance.py" ,
line 92, in miles
  File
"F:\code\Python24\lib\site-packages\geopy-0.93-py2.4.egg\geopy\distance.py" ,
line 344, in kilometers
AttributeError: 'VincentyDistance' object has no attribute
'_kilometers'

Same sort of thing if I change it to .km or .mi.

Any suggestions?

--
Ben Sizer


    Reply to author    Forward  
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.
Brian Beck  
View profile
 More options Dec 24 2006, 10:01 pm
From: "Brian Beck" <exo...@gmail.com>
Date: Mon, 25 Dec 2006 03:01:40 -0000
Local: Sun, Dec 24 2006 10:01 pm
Subject: Re: AttributeError: 'VincentyDistance' object has no attribute '_kilometers'
Hi Ben,

I think I've seen this before, but I can't remember the code that
produced it (it was fixable).  Can you post the piece of your
geography.py that used geopy.distance.distance?  What values are x and
y, specifically?

Thanks.


    Reply to author    Forward  
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.
Ben Sizer  
View profile
 More options Dec 25 2006, 6:01 pm
From: "Ben Sizer" <kylo...@gmail.com>
Date: Mon, 25 Dec 2006 23:01:09 -0000
Local: Mon, Dec 25 2006 6:01 pm
Subject: Re: AttributeError: 'VincentyDistance' object has no attribute '_kilometers'

Brian Beck wrote:
> I think I've seen this before, but I can't remember the code that
> produced it (it was fixable).  Can you post the piece of your
> geography.py that used geopy.distance.distance?  What values are x and
> y, specifically?

No need for that, as I think I found the issue. If x and y are exactly
equal or are the same object, this happens. My guess is that there's
some division by zero or a similar exception thrown before it reaches
the self._kilometers = s line, but caught elsewhere so that the end
application never sees it.

I can put in a special check in my code for now, but it would be great
if this could be fixed, if I've correctly identified the problem that
is!

--
Ben Sizer


    Reply to author    Forward  
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.
Brian Beck  
View profile
 More options Dec 25 2006, 6:04 pm
From: "Brian Beck" <exo...@gmail.com>
Date: Mon, 25 Dec 2006 18:04:57 -0500
Local: Mon, Dec 25 2006 6:04 pm
Subject: Re: AttributeError: 'VincentyDistance' object has no attribute '_kilometers'
On 12/25/06, Ben Sizer <kylo...@gmail.com> wrote:

> No need for that, as I think I found the issue. If x and y are exactly
> equal or are the same object, this happens. My guess is that there's
> some division by zero or a similar exception thrown before it reaches
> the self._kilometers = s line, but caught elsewhere so that the end
> application never sees it.

Interesting, I thought the algorithm handled this properly, thanks for
the heads up.

--
Brian Beck
Adventurer of the First Order


    Reply to author    Forward  
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.
Gary Bernhardt  
View profile
 More options Dec 25 2006, 8:19 pm
From: "Gary Bernhardt" <gary.bernha...@gmail.com>
Date: Mon, 25 Dec 2006 20:19:08 -0500
Local: Mon, Dec 25 2006 8:19 pm
Subject: Re: AttributeError: 'VincentyDistance' object has no attribute '_kilometers'

On 12/25/06, Ben Sizer <kylo...@gmail.com> wrote:

> No need for that, as I think I found the issue. If x and y are exactly
> equal or are the same object, this happens. My guess is that there's
> some division by zero or a similar exception thrown before it reaches
> the self._kilometers = s line, but caught elsewhere so that the end
> application never sees it.

You almost had it.  It's a premature return, not an exception.  From
distance.py, line 284:

            if sin_sigma == 0:
                return 0 # Coincident points

That's the only place in the calculate function where it actually returns a
value.  It looks like the function was originally written to return the
distance, but was later modified to set self._kilometers as its output.  The
attached patch fixes it.  And the results:

>>> geopy.distance.VincentyDistance((1.0, 1.0), (1.0, 1.0)).kilometers

0

  coincident_points.diff
< 1K Download

    Reply to author    Forward  
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.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google