Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

adding grow command [ WIP] #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions supermercado/grow_tiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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, edges):
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)

if edges:
xys_edge -= 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)
23 changes: 21 additions & 2 deletions supermercado/scripts/cli.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -44,6 +44,25 @@ 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('--new-only', '-n', is_flag=True)
@click.option('--parsenames', is_flag=True)
def grow(inputtiles, parsenames, distance, new_only):
"""
Grow a stream of [<x>, <y>, <z>] 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, new_only)
for t in grown:
click.echo(json.dumps(t.tolist()))

cli.add_command(grow)


@click.command('burn')
@cligj.features_in_arg
Expand All @@ -57,7 +76,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)