mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
Consolidated res
After resolving merge conflicts from rebase
This commit is contained in:
parent
7e53e58045
commit
d6364c20dc
@ -488,7 +488,13 @@ Or provide output bounds (in source crs) and resolution:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ rio warp input.tif output.tif --dst-crs EPSG:4326 --bounds -78 22 -76 24 --res 0.1
|
||||
$ rio warp input.tif output.tif --dst-crs EPSG:4326 --bounds -78 22 -76 24 --res 0.1 0.1
|
||||
|
||||
Other options are available, see:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ rio warp --help
|
||||
|
||||
|
||||
Suggestions for other commands are welcome!
|
||||
|
||||
@ -550,8 +550,6 @@ def rasterize(
|
||||
raise click.BadParameter(
|
||||
'pixel dimensions are required',
|
||||
ctx, param=res, param_hint='--res')
|
||||
elif len(res) == 1:
|
||||
res = (res[0], res[0])
|
||||
|
||||
width = max(int(ceil((bounds[2] - bounds[0]) /
|
||||
float(res[0]))), 1)
|
||||
|
||||
@ -20,8 +20,7 @@ from rasterio.transform import Affine
|
||||
@options.output_opt
|
||||
@format_opt
|
||||
@options.bounds_opt
|
||||
@click.option('-r', '--res', nargs=2, type=float, default=None,
|
||||
help="Output dataset resolution: pixel width, pixel height")
|
||||
@options.resolution_opt
|
||||
@click.option('--nodata', type=float, default=None,
|
||||
help="Override nodata values defined in input datasets")
|
||||
@options.creation_options
|
||||
|
||||
@ -138,18 +138,18 @@ output_opt = click.option(
|
||||
help="Path to output file (optional alternative to a positional arg "
|
||||
"for some commands).")
|
||||
|
||||
|
||||
resolution_opt = click.option(
|
||||
'-r', '--res',
|
||||
multiple=True, type=float, default=None,
|
||||
help='Output dataset resolution in units of coordinate '
|
||||
'reference system. Pixels assumed to be square if this option '
|
||||
'is used once, otherwise use: '
|
||||
'--res pixel_width --res pixel_height')
|
||||
|
||||
nargs=2,
|
||||
type=float,
|
||||
default=None,
|
||||
help="Output dataset resolution: pixel width, pixel height")
|
||||
|
||||
creation_options = click.option(
|
||||
'--co', 'creation_options', metavar='NAME=VALUE', multiple=True, callback=_cb_key_val,
|
||||
help="Driver specific creation options. See the documentation for the selected output "
|
||||
"driver for more information."
|
||||
)
|
||||
'--co', 'creation_options',
|
||||
metavar='NAME=VALUE',
|
||||
multiple=True,
|
||||
callback=_cb_key_val,
|
||||
help="Driver specific creation options."
|
||||
"See the documentation for the selected output driver for "
|
||||
"more information.")
|
||||
@ -76,7 +76,7 @@ def warp(
|
||||
coordinate reference system.
|
||||
|
||||
rio warp input.tif output.tif --bounds -78 22 -76 24 --dst-crs EPSG:4326
|
||||
--res 0.1
|
||||
--res 0.1 0.1
|
||||
"""
|
||||
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
@ -85,9 +85,6 @@ def warp(
|
||||
if not len(res):
|
||||
# Click sets this as an empty tuple if not provided
|
||||
res = None
|
||||
else:
|
||||
# Expand one value to two if needed
|
||||
res = (res[0], res[0]) if len(res) == 1 else res
|
||||
|
||||
with rasterio.drivers(CPL_DEBUG=verbosity > 2):
|
||||
with rasterio.open(input) as src:
|
||||
|
||||
@ -365,13 +365,13 @@ def test_rasterize_err(tmpdir, runner):
|
||||
assert result.exit_code == 2
|
||||
|
||||
# Test invalid CRS for bounds
|
||||
result = runner.invoke(features.rasterize, [output, '--res', 1],
|
||||
result = runner.invoke(features.rasterize, [output, '--res', 1, 1],
|
||||
input=TEST_MERC_FEATURECOLLECTION)
|
||||
assert result.exit_code == 2
|
||||
|
||||
# Test invalid CRS value
|
||||
result = runner.invoke(features.rasterize, [output,
|
||||
'--res', 1,
|
||||
'--res', 1, 1,
|
||||
'--src-crs', 'BOGUS'],
|
||||
input=TEST_MERC_FEATURECOLLECTION)
|
||||
assert result.exit_code == 2
|
||||
@ -413,7 +413,7 @@ def test_rasterize(tmpdir, runner):
|
||||
# Test resolution
|
||||
output = str(tmpdir.join('test3.tif'))
|
||||
result = runner.invoke(features.rasterize,
|
||||
[output, '--res', 0.5], input=TEST_FEATURES)
|
||||
[output, '--res', 0.5, 0.5], input=TEST_FEATURES)
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(output)
|
||||
with rasterio.open(output) as out:
|
||||
@ -440,7 +440,7 @@ def test_rasterize(tmpdir, runner):
|
||||
def test_rasterize_existing_output(tmpdir, runner):
|
||||
output = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(features.rasterize,
|
||||
[output, '--res', 0.5], input=TEST_FEATURES)
|
||||
[output, '--res', 0.5, 0.5], input=TEST_FEATURES)
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(output)
|
||||
|
||||
@ -473,7 +473,7 @@ def test_rasterize_existing_output(tmpdir, runner):
|
||||
# Confirm that a different src-crs is rejected, even if a geographic crs
|
||||
result = runner.invoke(features.rasterize,
|
||||
[output,
|
||||
'--res', 0.5,
|
||||
'--res', 0.5, 0.5,
|
||||
'--src-crs', 'EPSG:4269'
|
||||
], input=TEST_FEATURES)
|
||||
assert result.exit_code == 2
|
||||
@ -513,7 +513,7 @@ def test_rasterize_property_value(tmpdir, runner):
|
||||
output = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(features.rasterize,
|
||||
[output,
|
||||
'--res', 1000,
|
||||
'--res', 1000, 1000,
|
||||
'--property', 'val',
|
||||
'--src-crs', 'EPSG:3857'
|
||||
],
|
||||
@ -530,7 +530,7 @@ def test_rasterize_property_value(tmpdir, runner):
|
||||
# Test feature property values
|
||||
output = str(tmpdir.join('test2.tif'))
|
||||
result = runner.invoke(features.rasterize,
|
||||
[output, '--res', 0.5, '--property', 'val'],
|
||||
[output, '--res', 0.5, 0.5, '--property', 'val'],
|
||||
input=TEST_FEATURES)
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(output)
|
||||
|
||||
@ -50,7 +50,7 @@ def test_warp_no_reproject_res(runner, tmpdir):
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--res', '30'])
|
||||
'--res', 30, 30])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -86,7 +86,8 @@ def test_warp_no_reproject_bounds_res(runner, tmpdir):
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
out_bounds = [-11850000, 4810000, -11849000, 4812000]
|
||||
result = runner.invoke(warp.warp,[srcname, outputname,
|
||||
'--res', 30, '--bounds', ] + out_bounds)
|
||||
'--res', 30, 30,
|
||||
'--bounds', ] + out_bounds)
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -136,7 +137,7 @@ def test_warp_reproject_res(runner, tmpdir):
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--dst-crs', 'EPSG:4326',
|
||||
'--res', '0.01'])
|
||||
'--res', 0.01, 0.01])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -181,7 +182,7 @@ def test_warp_reproject_bounds_res(runner, tmpdir):
|
||||
out_bounds = [-11850000, 4810000, -11849000, 4812000]
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--dst-crs', 'EPSG:4326',
|
||||
'--res', 0.001, '--bounds', ]
|
||||
'--res', 0.001, 0.001, '--bounds', ]
|
||||
+ out_bounds)
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user