Skip to content

Commit

Permalink
Merge pull request #151 from AndrewAnnex/add_tms_cli_arg
Browse files Browse the repository at this point in the history
adds --tms optional argument to the shapes and tiles cli tools
  • Loading branch information
vincentsarago authored Aug 20, 2024
2 parents 4545afc + c74cd13 commit 19aac63
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions morecantile/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ def cli(ctx, verbose, quiet):
default=None,
help="Shift shape x and y values by a constant number",
)
@click.option(
"--tms",
help="Path to TileMatrixSet JSON file.",
type=click.Path(),
)
@click.pass_context
def shapes( # noqa: C901
ctx,
Expand All @@ -198,6 +203,7 @@ def shapes( # noqa: C901
collect,
extents,
buffer,
tms,
):
"""
Reads one or more Web Mercator tile descriptions
Expand All @@ -217,7 +223,10 @@ def shapes( # noqa: C901
the properties object of the output feature.
"""
tms = morecantile.tms.get(identifier)
tilematrixset = morecantile.tms.get(identifier)
if tms:
with open(tms, "r") as f:
tilematrixset = morecantile.TileMatrixSet(**json.load(f))

dump_kwds = {"sort_keys": True}
if indent:
Expand All @@ -243,7 +252,7 @@ def shapes( # noqa: C901
else:
raise click.BadParameter("{0}".format(obj), param=input, param_hint="input")

feature = tms.feature(
feature = tilematrixset.feature(
(x, y, z),
fid=fid,
props=props,
Expand Down Expand Up @@ -273,7 +282,7 @@ def shapes( # noqa: C901
click.echo(
json.dumps(
{"type": "FeatureCollection", "bbox": bbox, "features": features},
**dump_kwds
**dump_kwds,
)
)

Expand Down Expand Up @@ -302,8 +311,13 @@ def shapes( # noqa: C901
default=False,
help="Write a RS-delimited JSON sequence (default is LF).",
)
@click.option(
"--tms",
help="Path to TileMatrixSet JSON file.",
type=click.Path(),
)
@click.pass_context
def tiles(ctx, zoom, input, identifier, seq): # noqa: C901
def tiles(ctx, zoom, input, identifier, seq, tms): # noqa: C901
"""
Lists TMS tiles at ZOOM level intersecting
GeoJSON [west, south, east, north] bounding boxen, features, or
Expand All @@ -324,7 +338,10 @@ def tiles(ctx, zoom, input, identifier, seq): # noqa: C901
[853, 1551, 12]
"""
tms = morecantile.tms.get(identifier)
tilematrixset = morecantile.tms.get(identifier)
if tms:
with open(tms, "r") as f:
tilematrixset = morecantile.TileMatrixSet(**json.load(f))

for obj in normalize_source(input):
if isinstance(obj, list):
Expand Down Expand Up @@ -362,7 +379,9 @@ def tiles(ctx, zoom, input, identifier, seq): # noqa: C901
east -= epsilon
north -= epsilon

for tile in tms.tiles(west, south, east, north, [zoom], truncate=False):
for tile in tilematrixset.tiles(
west, south, east, north, [zoom], truncate=False
):
vals = (tile.x, tile.y, zoom)
output = json.dumps(vals)
if seq:
Expand Down

0 comments on commit 19aac63

Please sign in to comment.