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_tiles_single_zoom():
bounds = (-105, 39.99, -104.99, 40)
tiles = list(mercantile.tiles(*bounds, zooms=14))
expect = [
mercantile.Tile(x=3413, y=6202, z=14),
mercantile.Tile(x=3413, y=6203, z=14),
]
assert sorted(tiles) == sorted(expect)
def test_global_tiles_clamped():
"""Y is clamped to (0, 2 ** zoom - 1)"""
tiles = list(mercantile.tiles(-180, -90, 180, 90, [1]))
assert len(tiles) == 4
assert min(t.y for t in tiles) == 0
assert max(t.y for t in tiles) == 1
def test_tiles():
bounds = (-105, 39.99, -104.99, 40)
tiles = list(mercantile.tiles(*bounds, zooms=[14]))
expect = [
mercantile.Tile(x=3413, y=6202, z=14),
mercantile.Tile(x=3413, y=6203, z=14),
]
assert sorted(tiles) == sorted(expect)
def test_tiles_truncate():
"""Input is truncated"""
assert list(
mercantile.tiles(-181.0, 0.0, -170.0, 10.0, zooms=[2], truncate=True)
) == list(mercantile.tiles(-180.0, 0.0, -170.0, 10.0, zooms=[2]))
parser.add_argument('--overwrite', dest='overwrite',
action='store_true', default=False)
args = parser.parse_args()
client = boto3.client('batch')
database_url = os.environ.get('DATABASE_URL')
assert database_url, \
"Please set a DATABASE_URL environment variable"
assert args.zoom < args.max_zoom, \
"Pyramid root zoom must be less than max zoom"
(w, s, e, n) = map(float, args.bbox.split(','))
for tile in mercantile.tiles(w, s, e, n, [args.zoom]):
command_list = [
'python', 'examples/render_pyramid.py',
str(tile.x), str(tile.y), str(tile.z),
str(args.max_zoom), args.bucket
]
if args.key_prefix:
command_list.append('--key_prefix')
command_list.append(args.key_prefix)
container_overrides = {
'command': command_list,
'environment': [
{'name': 'DATABASE_URL',
'value': database_url},
]
parser.add_argument('--copy_only')
parser.add_argument('--cutoff_date')
parser.add_argument('--bbox',
default='-180.0,-90.0,180.0,90.0',
help='Bounding box of tiles to submit jobs. '
'format: left,bottom,right,top')
args = parser.parse_args()
client = boto3.client('batch')
assert args.zoom < args.max_zoom, \
"Pyramid root zoom must be less than max zoom"
(w, s, e, n) = map(float, args.bbox.split(','))
for tile in mercantile.tiles(w, s, e, n, [args.zoom]):
command_list = [
'python', 'examples/aws_s3_tile_cp.py',
str(tile.x), str(tile.y), str(tile.z),
str(args.max_zoom), args.from_bucket, args.to_bucket,
]
if args.from_prefix:
command_list.append('--from_prefix')
command_list.append(args.from_prefix)
if args.to_prefix:
command_list.append('--to_prefix')
command_list.append(args.to_prefix)
if args.remove_hash:
command_list.append('--remove_hash')
def polyfill(self, input_gdf, zoom_level):
check_package('mercantile', is_optional=True)
import mercantile
if not hasattr(input_gdf, 'geometry'):
raise ValueError('This dataframe has no valid geometry.')
geometry_name = input_gdf.geometry.name
dfs = []
for _, row in input_gdf.iterrows():
input_geometry = row[geometry_name]
bounds = input_geometry.bounds
tiles = mercantile.tiles(bounds[0], bounds[1], bounds[2], bounds[3], zoom_level)
new_rows = []
for tile in tiles:
new_row = row.copy()
new_geometry = box(*mercantile.bounds(tile))
if new_geometry.intersects(input_geometry):
new_row[geometry_name] = new_geometry
new_row['quadkey'] = mercantile.quadkey(tile)
new_rows.append(new_row)
dfs.append(pd.DataFrame(new_rows))
df = pd.concat(dfs).reset_index(drop=True)
return CartoDataFrame(df, geometry=geometry_name, crs='epsg:4326')
def bounds(west, south, east, north, start_year, end_year, dry_run=False):
return [
region(tile.x, tile.y, start_year, end_year, dry_run)
for tile in mercantile.tiles(west, south, east, north, config.region_zoom_level)
]
parser.add_argument('--output_prefix',
default="output",
help='The path prefix to output coverage data to')
args = parser.parse_args()
cities_resp = requests.get(args.cities_url)
cities_resp.raise_for_status()
cities_data = cities_resp.json()
for feature in cities_data:
name = feature['id']
bbox = feature['bbox']
min_lon, min_lat, max_lon, max_lat = float(bbox['left']), float(bbox['bottom']), float(bbox['right']), float(bbox['top'])
count = 0
with open(os.path.join(args.output_prefix, '{}.csv'.format(name)), 'w') as f:
for x, y, z in mercantile.tiles(min_lon, min_lat, max_lon, max_lat, range(args.min_zoom, args.max_zoom + 1)):
f.write('{}/{}/{}\n'.format(z, x, y))
count += 1
print("Wrote out {} tiles to {}".format(count, f.name))