This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_process_zones.py
65 lines (53 loc) · 1.72 KB
/
gen_process_zones.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
"""
Prints bounding box values of process zones.
Usage: ./gen_process_zones.py datacubes.mapchete -b <left>, <bottom>, <right>, <top>
"""
import click
from tilematrix import TilePyramid
import yaml
from shapely import speedups
speedups.disable()
@click.command()
@click.argument(
"mapchete_file",
type=click.Path(exists=True)
)
@click.option(
"--bounds", "-b",
type=click.FLOAT,
nargs=4,
help="Spatial subset in Tile Pyramid CRS. (default: Tile Pyramid bounds)"
)
@click.option(
"--zoom-delta",
type=click.INT,
default=5,
help="Zoom levels above maximum zoom provided in mapchete configuration to determine "
"process zone bounds. (default: 5, e.g. if max zoom is 13, process zoom levels will "
"be tiles from zoom 8.)"
)
@click.option(
"--wkt/--no-wkt",
help="Output WKT strings instead of bounds"
)
def gen_process_zones(mapchete_file, bounds=None, zoom_delta=None, wkt=None):
"""Generate bounding boxes of process zones from mapchete config."""
with open(mapchete_file) as src:
config = yaml.load(src.read())
tp = TilePyramid.from_dict(config["pyramid"])
# TODO: we need to parse min/max zoom levels if provided in config
max_zoom = config["zoom_levels"]
bounds = bounds or tp.bounds
process_zone_zoom = max_zoom - zoom_delta
if process_zone_zoom < 0:
raise TypeError(
"zoom_delta cannot be larger than process max zoom ({})".format(max_zoom)
)
for tile in tp.tiles_from_bounds(bounds, process_zone_zoom):
if(wkt):
click.echo(str(tile.bbox()))
else:
click.echo(" ".join(list(map(str,tile.bounds()))))
if __name__ == '__main__':
gen_process_zones()