-
Notifications
You must be signed in to change notification settings - Fork 21
/
cli.py
63 lines (50 loc) · 1.64 KB
/
cli.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
import click, json
import cligj
from supermercado import edge_finder, uniontiles, burntiles, super_utils
@click.group('supermercado')
def cli():
pass
@click.command('edges')
@click.argument('inputtiles', default='-', required=False)
@click.option('--parsenames', is_flag=True)
def edges(inputtiles, parsenames):
"""
For a stream of [<x>, <y>, <z>] tiles, return only those tiles that are on the edge.
"""
try:
inputtiles = click.open_file(inputtiles).readlines()
except IOError:
inputtiles = [inputtiles]
# parse the input stream into an array
tiles = edge_finder.findedges(inputtiles, parsenames)
for t in tiles:
click.echo(t.tolist())
cli.add_command(edges)
@click.command('union')
@click.argument('inputtiles', default='-', required=False)
@click.option('--parsenames', is_flag=True)
def union(inputtiles, parsenames):
"""
Returns the unioned shape of a stream of [<x>, <y>, <z>] tiles in GeoJSON.
"""
try:
inputtiles = click.open_file(inputtiles).readlines()
except IOError:
inputtiles = [inputtiles]
unioned = uniontiles.union(inputtiles, parsenames)
for u in unioned:
click.echo(json.dumps(u))
cli.add_command(union)
@click.command('burn')
@cligj.features_in_arg
@cligj.sequence_opt
@click.argument('zoom', type=int)
def burn(features, sequence, zoom):
"""
Burn a stream of GeoJSONs into a output stream of the tiles they intersect for a given zoom.
"""
features = [f for f in super_utils.filter_polygons(features)]
tiles = burntiles.burn(features, zoom)
for t in tiles:
click.echo(t.tolist())
cli.add_command(burn)