From 913304f70892a201643b6f5b7f099a617665d285 Mon Sep 17 00:00:00 2001 From: "Dr. Andrew Annex" Date: Fri, 9 Aug 2024 15:30:16 -0700 Subject: [PATCH 1/3] adds --tms optional argument to the shapes and tiles cli tools --- morecantile/scripts/cli.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/morecantile/scripts/cli.py b/morecantile/scripts/cli.py index 939a09a..5527186 100644 --- a/morecantile/scripts/cli.py +++ b/morecantile/scripts/cli.py @@ -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, @@ -198,6 +203,7 @@ def shapes( # noqa: C901 collect, extents, buffer, + tms, ): """ Reads one or more Web Mercator tile descriptions @@ -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: @@ -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, @@ -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 @@ -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): @@ -362,7 +379,7 @@ 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: From 9a76bcbe9f3f6e6b99ce5f698ecf25e393470630 Mon Sep 17 00:00:00 2001 From: "Dr. Andrew Annex" Date: Wed, 14 Aug 2024 13:10:57 -0700 Subject: [PATCH 2/3] fix black formatting --- morecantile/scripts/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/morecantile/scripts/cli.py b/morecantile/scripts/cli.py index 5527186..715dcbf 100644 --- a/morecantile/scripts/cli.py +++ b/morecantile/scripts/cli.py @@ -282,7 +282,7 @@ def shapes( # noqa: C901 click.echo( json.dumps( {"type": "FeatureCollection", "bbox": bbox, "features": features}, - **dump_kwds + **dump_kwds, ) ) From c74cd13064aa6928f25985064af8e9611fc77d8b Mon Sep 17 00:00:00 2001 From: "Dr. Andrew Annex" Date: Wed, 14 Aug 2024 13:19:22 -0700 Subject: [PATCH 3/3] another fix --- morecantile/scripts/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/morecantile/scripts/cli.py b/morecantile/scripts/cli.py index 715dcbf..ef6b309 100644 --- a/morecantile/scripts/cli.py +++ b/morecantile/scripts/cli.py @@ -379,7 +379,9 @@ def tiles(ctx, zoom, input, identifier, seq, tms): # noqa: C901 east -= epsilon north -= epsilon - for tile in tilematrixset.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: