TomSchimansky / TomSchimansky/TkinterMapView

Drawing a polygon with one edge along the south pole returns error

Open
#142 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
743
Forks
110
PR merge metrics
No merged PRs in 30d

Description

Hi,

this code:

import tkinter as tk  
import tkintermapview  
  
  
root = tk.Tk()  
map = tkintermapview.TkinterMapView(root, height=1000, width=1000)  
polygon = map.set_polygon([(-35.0, -10.0), (-35.0, 15.0), (-90.0, 15.0), (-90.0, -10.0), (-35.0, -10.0)])  
  
map.pack()  
root.mainloop()

returns this error:

Traceback (most recent call last):
  File "Z:/OverpassBBoxStitcher/test.py", line 7, in <module>
    polygon = map.set_polygon([(-35.0, -10.0), (-35.0, 15.0), (-90.0, 15.0), (-90.0, -10.0), (-35.0, -10.0)])
  File "Python36\site-packages\tkintermapview\map_widget.py", line 381, in set_polygon
    polygon.draw()
  File "Python36\site-packages\tkintermapview\canvas_polygon.py", line 101, in draw
    canvas_position = self.get_canvas_pos(position, widget_tile_width, widget_tile_height)
  File "Python36\site-packages\tkintermapview\canvas_polygon.py", line 74, in get_canvas_pos
    tile_position = decimal_to_osm(*position, round(self.map_widget.zoom))
  File "Python36\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

I will work around this issue by clamping all the south values to -89.99999, but that feels hacky and un-elegant.
For the north pole, a similar issue does not occur.

This is what I want it to look like:
image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example in canvas_polygon.py and follow its call into utility_functions.py, where decimal_to_osm raises the math domain error for latitude -90. Check how map_widget.py invokes polygon.draw(). Done means the supplied polygon can be drawn along the south pole without the exception, with the existing north-pole behavior preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.