mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
rio overview branch logic, --ls opens readonly
This commit is contained in:
parent
c5b44b524a
commit
a3bede25fc
@ -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 ...")
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user