Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_lnglat_xy_roundtrip():
lnglat = (-105.0844, 40.5853)
roundtrip = mercantile.lnglat(*mercantile.xy(*lnglat))
for a, b in zip(roundtrip, lnglat):
assert round(a - b, 7) == 0
def test_lnglat_truncate():
xy = (-28366731.739810849, -1655181.9927159143)
assert mercantile.lnglat(*xy, truncate=True) == (-180, -14.704620000000013)
def tile_to_blocks(tile_x, tile_y, zoom, year):
tile = mercantile.xy_bounds(tile_x, tile_y, zoom)
west, north = mercantile.lnglat(tile.left, tile.top)
east, south = mercantile.lnglat(tile.right, tile.bottom)
blocks = []
for block in mercantile.tiles(west, south, east, north, config.block_zoom):
bounds = mercantile.bounds(block)
block = {
'id': '{}-{}-{}'.format(block.x, block.y, year),
'x': block.x,
'y': block.y,
'year': year,
'north': bounds.north,
'east': bounds.east + 0.1,
'south': bounds.south - 0.1,
'west': bounds.west,
}
blocks += [block]
def tile(x, y, zoom, start_year, end_year, dry_run=False):
xy_bounds = mercantile.xy_bounds(x, y, zoom)
west, north = mercantile.lnglat(xy_bounds.left, xy_bounds.top)
east, south = mercantile.lnglat(xy_bounds.right, xy_bounds.bottom)
return bounds(west, south, east, north, start_year, end_year, dry_run)
def tile_to_blocks(tile_x, tile_y, zoom, year):
tile = mercantile.xy_bounds(tile_x, tile_y, zoom)
west, north = mercantile.lnglat(tile.left, tile.top)
east, south = mercantile.lnglat(tile.right, tile.bottom)
blocks = []
for block in mercantile.tiles(west, south, east, north, config.block_zoom):
bounds = mercantile.bounds(block)
block = {
'id': '{}-{}-{}'.format(block.x, block.y, year),
'x': block.x,
'y': block.y,
'year': year,
'north': bounds.north,
'east': bounds.east + 0.1,
'south': bounds.south - 0.1,
'west': bounds.west,
}
blocks += [block]
return blocks
def tile(x, y, zoom, start_year, end_year, dry_run=False):
xy_bounds = mercantile.xy_bounds(x, y, zoom)
west, north = mercantile.lnglat(xy_bounds.left, xy_bounds.top)
east, south = mercantile.lnglat(xy_bounds.right, xy_bounds.bottom)
return bounds(west, south, east, north, start_year, end_year, dry_run)