komoot / staticmap

A small, python-based library for creating map images with lines, markers and polygons.
https://www.komoot.com
Other
290 stars 65 forks source link

Negative Latitude Value #12

Closed eliascotto closed 7 years ago

eliascotto commented 7 years ago

Hi, when I create a map with a large set of cities, the library rase an errore like this one

Traceback (most recent call last):
  File "/xxx/pyxxx.py", line 71, in <module>
    image = m.render(zoom=1)
  File "/usr/local/lib/python2.7/dist-packages/staticmap/staticmap.py", line 268, in render
    extent = self.determine_extent(zoom=self.zoom)
  File "/usr/local/lib/python2.7/dist-packages/staticmap/staticmap.py", line 304, in determine_extent
    y = _lat_to_y(e[1], zoom)
  File "/usr/local/lib/python2.7/dist-packages/staticmap/staticmap.py", line 141, in _lat_to_y
    return (1 - log(tan(lat * pi / 180) + 1 / cos(lat * pi / 180)) / pi) / 2 * pow(2, zoom)
ValueError: math domain error

So, the math domain error is probably related to the log function, that with negative number is mathematically undefined.

christophlingg commented 7 years ago

tan is not defined for latitude = ±90. it seems you want to draw a city exactly on the north pole or south pole. that's actually not possible with the usual (=mercator) projection.

Without knowing your data that's my best guess. Can you check your data for suspicious latitude values?