Skip to content

Commit f5241ae

Browse files
committed
optional min/max zoom
1 parent 480b4db commit f5241ae

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

mapbox_tilesets/scripts/cli.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tilesets command line interface"""
22

3+
import os
34
import base64
45
import builtins
56
import json
@@ -858,11 +859,23 @@ def validate_stream(features):
858859
default=15,
859860
help="The number of bands your recipe is selecting",
860861
)
862+
@click.option(
863+
"--minzoom",
864+
required=False,
865+
type=int,
866+
help="The minzoom value override"
867+
)
868+
@click.option(
869+
"--maxzoom",
870+
required=False,
871+
type=int,
872+
help="The maxzoom value override"
873+
)
861874
@click.option(
862875
"--raw", required=False, type=bool, default=False, is_flag=True, help="Raw CU value"
863876
)
864877
@click.option("--token", "-t", required=False, type=str, help="Mapbox access token")
865-
def estimate_cu(tileset, num_bands=15, sources=None, raw=False, token=None):
878+
def estimate_cu(tileset, num_bands=15, minzoom=None, maxzoom=None, sources=None, raw=False, token=None):
866879
"""
867880
Estimates the CUs that will be consumed when processing your recipe into a tileset.
868881
Requires extra installation steps: see https://github.com/mapbox/tilesets-cli/blob/master/README.md
@@ -874,13 +887,16 @@ def estimate_cu(tileset, num_bands=15, sources=None, raw=False, token=None):
874887
click.echo(f"[warning] estimating '{tileset}' with a default global bounds")
875888
sources = ""
876889

890+
total_size = 0
877891
overall_bounds = None
878892
src_list = glob(sources)
879893

880894
if len(src_list) > 0:
881895
with rio.open(src_list[0], mode="r") as ds:
882896
overall_bounds = ds.bounds
883897

898+
total_size += os.path.getsize(src_list[0])
899+
884900
if len(src_list) > 1:
885901
for source in src_list:
886902
try:
@@ -893,6 +909,8 @@ def estimate_cu(tileset, num_bands=15, sources=None, raw=False, token=None):
893909
overall_bounds.top = ds.bounds.top
894910
if ds.bounds.bottom < overall_bounds.bottom:
895911
overall_bounds.bottom = ds.bounds.bottom
912+
913+
total_size += os.path.getsize(source)
896914
except Exception:
897915
click.echo(f"[warning] skipping invalid source '{source}'")
898916

@@ -902,13 +920,20 @@ def estimate_cu(tileset, num_bands=15, sources=None, raw=False, token=None):
902920
url = "{0}/tilesets/v1/{1}/estimate".format(mapbox_api, tileset)
903921

904922
query_params = {
923+
"filesize": total_size,
905924
"band_count": num_bands,
906925
"access_token": mapbox_token,
907926
}
908927

909928
if overall_bounds is not None:
910929
query_params["bounds"] = json.dumps([*overall_bounds])
911930

931+
if minzoom is not None:
932+
query_params["minzoom"] = minzoom
933+
934+
if maxzoom is not None:
935+
query_params["maxzoom"] = maxzoom
936+
912937
response = s.get(url, params=query_params)
913938

914939
if not response.ok:

0 commit comments

Comments
 (0)