Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _xy(lng, lat, truncate=False):
if truncate:
lng, lat = truncate_lnglat(lng, lat)
x = lng / 360.0 + 0.5
sinlat = math.sin(math.radians(lat))
try:
y = 0.5 - 0.25 * math.log((1.0 + sinlat) / (1.0 - sinlat)) / math.pi
except (ValueError, ZeroDivisionError):
raise InvalidLatitudeError("Y can not be computed: lat={!r}".format(lat))
else:
return x, y
w, s, e, n = bbox
truncate = bool(kwds.get("truncate"))
if truncate:
w, s = truncate_lnglat(w, s)
e, n = truncate_lnglat(e, n)
e = e - LL_EPSILON
s = s + LL_EPSILON
try:
tmin = tile(w, n, 32)
tmax = tile(e, s, 32)
except InvalidLatitudeError:
return Tile(0, 0, 0)
cell = tmin[:2] + tmax[:2]
z = _getBboxZoom(*cell)
if z == 0:
return Tile(0, 0, 0)
x = rshift(cell[0], (32 - z))
y = rshift(cell[1], (32 - z))
return Tile(x, y, z)