Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

adds --tms optional argument to the shapes and tiles cli tools #151

Merged
merged 3 commits into from
Aug 20, 2024
Merged
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
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
Loading