rio overview branch logic, --ls opens readonly

This commit is contained in:
Matthew Perry 2016-09-20 11:31:34 -04:00
parent c5b44b524a
commit a3bede25fc
2 changed files with 18 additions and 6 deletions

View File

@ -67,9 +67,8 @@ def overview(ctx, input, build, ls, rebuild, resampling):
"""
with ctx.obj['env']:
with rasterio.open(input, 'r+') as dst:
if ls:
if ls:
with rasterio.open(input, 'r') as dst:
resampling_method = dst.tags(
ns='rio_overview').get('resampling') or 'unknown'
@ -77,8 +76,8 @@ def overview(ctx, input, build, ls, rebuild, resampling):
for idx in dst.indexes:
click.echo(" Band %d: %s (method: '%s')" % (
idx, dst.overviews(idx) or 'None', resampling_method))
elif rebuild:
elif rebuild:
with rasterio.open(input, 'r+') as dst:
# Build the same overviews for all bands.
factors = reduce(
operator.or_,
@ -91,8 +90,13 @@ def overview(ctx, input, build, ls, rebuild, resampling):
dst.build_overviews(
list(factors), Resampling[resampling_method])
elif build:
elif build:
with rasterio.open(input, 'r+') as dst:
dst.build_overviews(build, Resampling[resampling])
# Save the resampling method to a tag.
dst.update_tags(ns='rio_overview', resampling=resampling)
else:
raise click.UsageError(
"Please specify --ls, --rebuild, or --build ...")

View File

@ -66,3 +66,11 @@ def test_rebuild_ls(data):
expected = " Band 1: [2, 4, 8] (method: 'cubic')\n Band 2: [2, 4, 8] (method: 'cubic')\n Band 3: [2, 4, 8] (method: 'cubic')\n"
assert result.output.endswith(expected)
def test_no_args(data):
runner = CliRunner()
inputfile = str(data.join('RGB.byte.tif'))
result = runner.invoke(cli, ['overview', inputfile])
assert result.exit_code == 2
assert "Please specify --ls, --rebuild, or --build ..." in result.output