From c67ce8d098c224d84123c4db4aa3258e57f4f3b2 Mon Sep 17 00:00:00 2001 From: dnomadb Date: Fri, 18 Nov 2016 11:23:45 -0800 Subject: [PATCH 1/2] adding grow command --- supermercado/grow_tiles.py | 31 +++++++++++++++++++++++++++++++ supermercado/scripts/cli.py | 22 ++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 supermercado/grow_tiles.py diff --git a/supermercado/grow_tiles.py b/supermercado/grow_tiles.py new file mode 100644 index 0000000..96ccc98 --- /dev/null +++ b/supermercado/grow_tiles.py @@ -0,0 +1,31 @@ +from supermercado import super_utils as sutils +import numpy as np + + +def itergrow(burn, distance=1): + idxs = sutils.get_idx() + + for g in range(distance): + burn = (np.max(np.dstack(( + np.roll(np.roll(burn, i[0], 0), i[1], 1) for i in idxs + )), axis=2)) + + return burn + +def grow(inputtiles, parsenames, distance): + tiles = sutils.tile_parser(inputtiles, parsenames) + + xmin, xmax, ymin, ymax = sutils.get_range(tiles) + + zoom = sutils.get_zoom(tiles) + + burn = sutils.burnXYZs(tiles, xmin, xmax, ymin, ymax, pad=distance+1) + + xys_edge = itergrow(burn.copy(), distance) - burn + + xys_edge = np.dstack(np.where(xys_edge))[0] + xys_edge[:, 0] += xmin - 1 - distance + xys_edge[:, 1] += ymin - 1 - distance + + + return np.append(xys_edge, np.zeros((xys_edge.shape[0], 1), dtype=np.uint8) + zoom, axis=1) \ No newline at end of file diff --git a/supermercado/scripts/cli.py b/supermercado/scripts/cli.py index 9a63c2d..ef19108 100644 --- a/supermercado/scripts/cli.py +++ b/supermercado/scripts/cli.py @@ -1,6 +1,6 @@ import click, json import cligj -from supermercado import edge_finder, uniontiles, burntiles, super_utils +from supermercado import edge_finder, uniontiles, burntiles, super_utils, grow_tiles @click.group('supermercado') @@ -44,6 +44,24 @@ def union(inputtiles, parsenames): cli.add_command(union) +@click.command('grow') +@click.argument('inputtiles', default='-', required=False) +@click.option('--distance', '-d', type=int, default=1, help='Degree to grow by [DEFAULT = 1]') +@click.option('--parsenames', is_flag=True) +def grow(inputtiles, parsenames, distance): + """ + Grow a stream of [, , ] tiles in the x and y dimensions + """ + try: + inputtiles = click.open_file(inputtiles).readlines() + except IOError: + inputtiles = [inputtiles] + grown = grow_tiles.grow(inputtiles, parsenames, distance) + for t in grown: + click.echo(json.dumps(t.tolist())) + +cli.add_command(grow) + @click.command('burn') @cligj.features_in_arg @@ -57,7 +75,7 @@ def burn(features, sequence, zoom): tiles = burntiles.burn(features, zoom) for t in tiles: - click.echo(t.tolist()) + click.echo(json.dumps(t.tolist())) cli.add_command(burn) \ No newline at end of file From c1017150f03e6bd49dae3eb7fdc38cf26b755733 Mon Sep 17 00:00:00 2001 From: dnomadb Date: Fri, 18 Nov 2016 11:31:56 -0800 Subject: [PATCH 2/2] adding new only --- supermercado/grow_tiles.py | 7 +++++-- supermercado/scripts/cli.py | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/supermercado/grow_tiles.py b/supermercado/grow_tiles.py index 96ccc98..9787330 100644 --- a/supermercado/grow_tiles.py +++ b/supermercado/grow_tiles.py @@ -12,7 +12,7 @@ def itergrow(burn, distance=1): return burn -def grow(inputtiles, parsenames, distance): +def grow(inputtiles, parsenames, distance, edges): tiles = sutils.tile_parser(inputtiles, parsenames) xmin, xmax, ymin, ymax = sutils.get_range(tiles) @@ -21,7 +21,10 @@ def grow(inputtiles, parsenames, distance): burn = sutils.burnXYZs(tiles, xmin, xmax, ymin, ymax, pad=distance+1) - xys_edge = itergrow(burn.copy(), distance) - burn + xys_edge = itergrow(burn.copy(), distance) + + if edges: + xys_edge -= burn xys_edge = np.dstack(np.where(xys_edge))[0] xys_edge[:, 0] += xmin - 1 - distance diff --git a/supermercado/scripts/cli.py b/supermercado/scripts/cli.py index ef19108..00553f0 100644 --- a/supermercado/scripts/cli.py +++ b/supermercado/scripts/cli.py @@ -47,8 +47,9 @@ def union(inputtiles, parsenames): @click.command('grow') @click.argument('inputtiles', default='-', required=False) @click.option('--distance', '-d', type=int, default=1, help='Degree to grow by [DEFAULT = 1]') +@click.option('--new-only', '-n', is_flag=True) @click.option('--parsenames', is_flag=True) -def grow(inputtiles, parsenames, distance): +def grow(inputtiles, parsenames, distance, new_only): """ Grow a stream of [, , ] tiles in the x and y dimensions """ @@ -56,7 +57,7 @@ def grow(inputtiles, parsenames, distance): inputtiles = click.open_file(inputtiles).readlines() except IOError: inputtiles = [inputtiles] - grown = grow_tiles.grow(inputtiles, parsenames, distance) + grown = grow_tiles.grow(inputtiles, parsenames, distance, new_only) for t in grown: click.echo(json.dumps(t.tolist()))