kercos / geomodel

Automatically exported from code.google.com/p/geomodel
0 stars 0 forks source link

geomath.py distance calculation sometimes produces math Value error #13

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. compute a distance between two identical points at lat:48.856668 lon:
2.350987

What is the expected output? What do you see instead?
geomath.py", line 44, in distance
    math.cos(p1lat) * math.cos(p2lat) * math.cos(p2lon - p1lon))
ValueError: math domain error

This is because it seems that 1.0000 may be > 1.  

What version of the product are you using? On what operating system?
MacOS X snow leopard, latest version as of today

Please provide any additional information below.
Solved the issue by doing
  return RADIUS * math.acos(max(min(math.sin(p1lat) * math.sin(p2lat) +
      math.cos(p1lat) * math.cos(p2lat) * math.cos(p2lon - p1lon),1),-1))

Original issue reported on code.google.com by b...@simpleapp.fr on 21 Dec 2009 at 7:16

GoogleCodeExporter commented 8 years ago
I've seen this as well.  It's coming from proximity_fetch, at least:

  File "/xxx/geo/geomodel.py", line 221, in proximity_fetch
    for entity in new_results]
  File "/xxx/geo/geomath.py", line 41, in distance

    math.cos(p1lat) * math.cos(p2lat) * math.cos(p2lon - p1lon))
ValueError: math domain error

This error also arose from doing a proximity_fetch around a point which is 
represented exactly in the database.  The above min/max edit does work.  It 
would be 
great to see this fixed upstream.

Original comment by dsh%linu...@gtempaccount.com on 25 Feb 2010 at 1:10

GoogleCodeExporter commented 8 years ago

Original comment by romannu...@google.com on 2 Aug 2011 at 5:40

GoogleCodeExporter commented 8 years ago
Why not simply applying the patch provided by the OP?

Original comment by flavioju...@gmail.com on 21 Sep 2011 at 10:53

GoogleCodeExporter commented 8 years ago
Saw this error today using a recent SVN checkout. Appears to be the same one as 
previously reported. I can confirm that the fix from the original report in 
2009 fixed this issue for me. This bug is two years old and the fix is simple. 
Why has it not been fixed? 

  File "/home/app/geo/geomodel.py", line 214, in proximity_fetch
    util.distance_sorted_edges(cur_geocells, center)
  File "/home/app/geo/util.py", line 114, in distance_sorted_edges
    point)),
  File "/home/app/geo/geomath.py", line 41, in distance
    math.cos(p1lat) * math.cos(p2lat) * math.cos(p2lon - p1lon))
ValueError: math domain error

Original comment by chris.ba...@gmail.com on 18 Nov 2011 at 5:40

GoogleCodeExporter commented 8 years ago
r25 resolves this issue.

Original comment by jli...@google.com on 18 Nov 2011 at 5:50

GoogleCodeExporter commented 8 years ago
wow - we are using the async version of geomodel and just ran into this problem 
- hard to believe the current published version still includes this rounding 
error

Original comment by pow...@getsplash.com on 13 Jun 2012 at 4:42