Taking the log of zero in decimal_to_osm
Corey4005 opened this issue · comments
Corey Walker commented
In tkintermapview utility_functions.py
line 6, there is a function called decimal_to_osm
which converts decimal coordinates to internal OSM coordinates.
It looks like this:
def decimal_to_osm(lat_deg: float, lon_deg: float, zoom: int) -> tuple:
""" converts decimal coordinates to internal OSM coordinates"""
lat_rad = math.radians(lat_deg)
n = 2.0 ** zoom
xtile = (lon_deg + 180.0) / 360.0 * n
ytile = (1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n
return xtile, ytile
If I put in a lat_deg of -90.0, I get the following error:
File "c:\Users\Corey4005\Desktop\repos\aquatron\virt\datacontainer.py", line 82, in marker
self.mapobject.set_marker(self.lon, self.lat, text=self.station, command=self.get_data)
File "c:\Users\Corey4005\Desktop\repos\aquatron\virt\lib\site-packages\tkintermapview\map_widget.py", line
369, in set_marker
marker.draw()
File "c:\Users\Corey4005\Desktop\repos\aquatron\virt\lib\site-packages\tkintermapview\canvas_position_marker.py", line 133, in draw
canvas_pos_x, canvas_pos_y = self.get_canvas_pos(self.position)
File "c:\Users\Corey4005\Desktop\repos\aquatron\virt\lib\site-packages\tkintermapview\canvas_position_marker.py", line 122, in get_canvas_pos
tile_position = decimal_to_osm(*position, round(self.map_widget.zoom))
File "c:\Users\Corey4005\Desktop\repos\aquatron\virt\lib\site-packages\tkintermapview\utility_functions.py", line 12, in decimal_to_osm
ytile = (1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n
ValueError: math domain error
Upon further inspection, I found that math.tan(lat_rad) and 1 / math.cos(lat_rad) evaluate to the same thing, which causes the function to take a log of zero, causing a traceback because this is undefined. Perhaps a new method should be instituted?
Corey Walker commented
Please forgive me. I was accidentally inserting the longitude as the latitude.