mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
Get env from main ctx
Migrate all tests over to invoking main_group with a named command.
This commit is contained in:
parent
2925e10a2b
commit
9355513d39
@ -133,8 +133,6 @@ def blocks(
|
||||
'src.block_windows()'.
|
||||
"""
|
||||
|
||||
verbosity = ctx.obj['verbosity'] if ctx.obj else 1
|
||||
|
||||
dump_kwds = {'sort_keys': True}
|
||||
|
||||
if indent:
|
||||
@ -146,21 +144,21 @@ def blocks(
|
||||
output, 'w') if output else click.get_text_stream('stdout')
|
||||
|
||||
try:
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2):
|
||||
with rasterio.open(input) as src:
|
||||
with ctx.obj['env'], rasterio.open(input) as src:
|
||||
|
||||
collection = _Collection(
|
||||
src=src,
|
||||
bidx=bidx,
|
||||
precision=precision,
|
||||
geographic=projection != 'projected')
|
||||
collection = _Collection(
|
||||
src=src,
|
||||
bidx=bidx,
|
||||
precision=precision,
|
||||
geographic=projection != 'projected')
|
||||
|
||||
write_features(
|
||||
stdout, collection,
|
||||
sequence=sequence,
|
||||
geojson_type='feature' if sequence else 'collection',
|
||||
use_rs=use_rs,
|
||||
**dump_kwds)
|
||||
|
||||
write_features(
|
||||
stdout, collection,
|
||||
sequence=sequence,
|
||||
geojson_type='feature' if sequence else 'collection',
|
||||
use_rs=use_rs,
|
||||
**dump_kwds)
|
||||
except Exception:
|
||||
logger.exception("Exception caught during processing")
|
||||
raise click.Abort()
|
||||
|
||||
@ -46,7 +46,6 @@ def bounds(ctx, input, precision, indent, compact, projection, dst_crs,
|
||||
the projection parameter.
|
||||
"""
|
||||
import rasterio.warp
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
logger = logging.getLogger('rio')
|
||||
dump_kwds = {'sort_keys': True}
|
||||
if indent:
|
||||
@ -106,7 +105,7 @@ def bounds(ctx, input, precision, indent, compact, projection, dst_crs,
|
||||
self._ys.extend(bbox[1::2])
|
||||
|
||||
try:
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2) as env:
|
||||
with ctx.obj['env'] as env:
|
||||
write_features(
|
||||
stdout, Collection(env), sequence=sequence,
|
||||
geojson_type=geojson_type, use_rs=use_rs,
|
||||
|
||||
@ -86,10 +86,8 @@ def calc(ctx, command, files, output, name, dtype, masked, force_overwrite,
|
||||
"""
|
||||
import numpy as np
|
||||
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
|
||||
try:
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2):
|
||||
with ctx.obj['env']:
|
||||
output, files = resolve_inout(files=files, output=output,
|
||||
force_overwrite=force_overwrite)
|
||||
|
||||
|
||||
@ -53,9 +53,7 @@ def clip(
|
||||
|
||||
from rasterio.warp import transform_bounds
|
||||
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2):
|
||||
with ctx.obj['env']:
|
||||
|
||||
output, files = resolve_inout(files=files, output=output)
|
||||
input = files[0]
|
||||
|
||||
@ -53,9 +53,7 @@ def convert(
|
||||
--co compress=LZW
|
||||
|
||||
"""
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2):
|
||||
with ctx.obj['env']:
|
||||
|
||||
outputfile, files = resolve_inout(files=files, output=output)
|
||||
inputfile = files[0]
|
||||
|
||||
@ -124,15 +124,13 @@ def edit(ctx, input, nodata, crs, transform, tags, allmd, like):
|
||||
"""
|
||||
import numpy as np
|
||||
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
|
||||
def in_dtype_range(value, dtype):
|
||||
infos = {'c': np.finfo, 'f': np.finfo, 'i': np.iinfo,
|
||||
'u': np.iinfo}
|
||||
rng = infos[np.dtype(dtype).kind](dtype)
|
||||
return rng.min <= value <= rng.max
|
||||
|
||||
with rasterio.Env(CPL_DEBUG=(verbosity > 2)):
|
||||
with ctx.obj['env']:
|
||||
|
||||
with rasterio.open(input, 'r+') as dst:
|
||||
|
||||
|
||||
@ -73,10 +73,9 @@ def main(banner, dataset, alt_interpreter=None):
|
||||
@click.pass_context
|
||||
def insp(ctx, input, mode, interpreter):
|
||||
"""Open the input file in a Python interpreter."""
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
logger = logging.getLogger('rio')
|
||||
try:
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2):
|
||||
with ctx.obj['env']:
|
||||
with rasterio.open(input, mode) as src:
|
||||
main(
|
||||
'Rasterio %s Interactive Inspector (Python %s)\n'
|
||||
|
||||
@ -68,8 +68,6 @@ def mask(
|
||||
from rasterio.mask import mask as mask_tool
|
||||
from rasterio.features import bounds as calculate_bounds
|
||||
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
|
||||
output, files = resolve_inout(
|
||||
files=files, output=output, force_overwrite=force_overwrite)
|
||||
input = files[0]
|
||||
@ -84,7 +82,7 @@ def mask(
|
||||
click.echo('Invert option ignored when using --crop', err=True)
|
||||
invert = False
|
||||
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2):
|
||||
with ctx.obj['env']:
|
||||
try:
|
||||
with click.open_file(geojson_mask) as fh:
|
||||
geojson = json.loads(fh.read())
|
||||
|
||||
@ -45,12 +45,10 @@ def merge(ctx, files, output, driver, bounds, res, nodata, force_overwrite,
|
||||
"""
|
||||
from rasterio.merge import merge as merge_tool
|
||||
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
|
||||
output, files = resolve_inout(
|
||||
files=files, output=output, force_overwrite=force_overwrite)
|
||||
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2):
|
||||
with ctx.obj['env']:
|
||||
sources = [rasterio.open(f) for f in files]
|
||||
dest, output_transform = merge_tool(sources, bounds=bounds, res=res,
|
||||
nodata=nodata, precision=precision)
|
||||
|
||||
@ -66,9 +66,7 @@ def overview(ctx, input, build, ls, rebuild, resampling):
|
||||
rio overview --ls
|
||||
|
||||
"""
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
|
||||
with rasterio.Env(CPL_DEBUG=(verbosity > 2)):
|
||||
with ctx.obj['env']:
|
||||
with rasterio.open(input, 'r+') as dst:
|
||||
|
||||
if ls:
|
||||
|
||||
@ -114,8 +114,6 @@ def rasterize(
|
||||
from rasterio.features import rasterize
|
||||
from rasterio.features import bounds as calculate_bounds
|
||||
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
|
||||
output, files = resolve_inout(
|
||||
files=files, output=output, force_overwrite=force_overwrite)
|
||||
|
||||
@ -134,7 +132,7 @@ def rasterize(
|
||||
if fill == int(fill):
|
||||
fill = int(fill)
|
||||
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2):
|
||||
with ctx.obj['env']:
|
||||
|
||||
def feature_value(feature):
|
||||
if prop and 'properties' in feature:
|
||||
|
||||
@ -52,7 +52,6 @@ def sample(ctx, files, bidx):
|
||||
[25, 29]
|
||||
|
||||
"""
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
logger = logging.getLogger('rio')
|
||||
|
||||
files = list(files)
|
||||
@ -66,7 +65,7 @@ def sample(ctx, files, bidx):
|
||||
points = [input]
|
||||
|
||||
try:
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2):
|
||||
with ctx.obj['env']:
|
||||
with rasterio.open(source) as src:
|
||||
if bidx is None:
|
||||
indexes = src.indexes
|
||||
|
||||
@ -95,7 +95,6 @@ def shapes(
|
||||
import rasterio.features
|
||||
import rasterio.warp
|
||||
|
||||
verbosity = ctx.obj['verbosity'] if ctx.obj else 1
|
||||
logger = logging.getLogger('rio')
|
||||
dump_kwds = {'sort_keys': True}
|
||||
if indent:
|
||||
@ -223,7 +222,7 @@ def shapes(
|
||||
geojson_type = 'collection'
|
||||
|
||||
try:
|
||||
with rasterio.Env(CPL_DEBUG=(verbosity > 2)) as env:
|
||||
with ctx.obj['env'] as env:
|
||||
write_features(
|
||||
stdout, Collection(env), sequence=sequence,
|
||||
geojson_type=geojson_type, use_rs=use_rs,
|
||||
|
||||
@ -55,10 +55,9 @@ def stack(ctx, files, output, driver, bidx, photometric, force_overwrite,
|
||||
rio stack RGB.byte.tif --bidx ..2 RGB.byte.tif --bidx 3.. -o stacked.tif
|
||||
|
||||
"""
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 2
|
||||
logger = logging.getLogger('rio')
|
||||
try:
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2):
|
||||
with ctx.obj['env']:
|
||||
output, files = resolve_inout(files=files, output=output,
|
||||
force_overwrite=force_overwrite)
|
||||
output_count = 0
|
||||
|
||||
@ -21,7 +21,6 @@ import rasterio
|
||||
def transform(ctx, input, src_crs, dst_crs, precision):
|
||||
import rasterio.warp
|
||||
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
logger = logging.getLogger('rio')
|
||||
|
||||
# Handle the case of file, stream, or string input.
|
||||
@ -31,7 +30,7 @@ def transform(ctx, input, src_crs, dst_crs, precision):
|
||||
src = [input]
|
||||
|
||||
try:
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2):
|
||||
with ctx.obj['env']:
|
||||
if src_crs.startswith('EPSG'):
|
||||
src_crs = {'init': src_crs}
|
||||
elif os.path.exists(src_crs):
|
||||
|
||||
@ -9,6 +9,7 @@ from cligj import files_inout_arg, format_opt
|
||||
|
||||
import rasterio
|
||||
from rasterio.crs import CRS
|
||||
from rasterio.env import setenv
|
||||
from rasterio.errors import CRSError
|
||||
from rasterio.rio import options
|
||||
from rasterio.rio.helpers import resolve_inout
|
||||
@ -104,8 +105,6 @@ def warp(ctx, files, output, driver, like, dst_crs, dimensions, src_bounds,
|
||||
> --bounds -78 22 -76 24 --res 0.1 --dst-crs EPSG:4326
|
||||
|
||||
"""
|
||||
verbosity = (ctx.obj and ctx.obj.get('verbosity')) or 1
|
||||
|
||||
output, files = resolve_inout(
|
||||
files=files, output=output, force_overwrite=force_overwrite)
|
||||
|
||||
@ -132,8 +131,9 @@ def warp(ctx, files, output, driver, like, dst_crs, dimensions, src_bounds,
|
||||
raise click.BadParameter(
|
||||
"--dimensions cannot be used with --bounds or --res")
|
||||
|
||||
with rasterio.Env(CPL_DEBUG=verbosity > 2,
|
||||
CHECK_WITH_INVERT_PROJ=check_invert_proj):
|
||||
with ctx.obj['env']:
|
||||
setenv(CHECK_WITH_INVERT_PROJ=check_invert_proj)
|
||||
|
||||
with rasterio.open(files[0]) as src:
|
||||
l, b, r, t = src.bounds
|
||||
out_kwargs = src.profile.copy()
|
||||
@ -142,8 +142,8 @@ def warp(ctx, files, output, driver, like, dst_crs, dimensions, src_bounds,
|
||||
# Sort out the bounds options.
|
||||
if src_bounds and dst_bounds:
|
||||
raise click.BadParameter(
|
||||
"--src-bounds and destination --bounds may not be specified "
|
||||
"simultaneously.")
|
||||
"--src-bounds and destination --bounds may not be "
|
||||
"specified simultaneously.")
|
||||
|
||||
if like:
|
||||
with rasterio.open(like) as template_ds:
|
||||
|
||||
@ -4,7 +4,7 @@ import logging
|
||||
from click.testing import CliRunner
|
||||
|
||||
import rasterio
|
||||
from rasterio.rio.calc import calc
|
||||
from rasterio.rio.main import main_group
|
||||
|
||||
|
||||
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
||||
@ -13,18 +13,18 @@ logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
||||
def test_err(tmpdir):
|
||||
outfile = str(tmpdir.join('out.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(calc, [
|
||||
'($ 0.1 (read 1))', 'tests/data/shade.tif', outfile],
|
||||
catch_exceptions=False)
|
||||
result = runner.invoke(main_group, ['calc'] + [
|
||||
'($ 0.1 (read 1))', 'tests/data/shade.tif', outfile],
|
||||
catch_exceptions=False)
|
||||
assert result.exit_code == 1
|
||||
|
||||
|
||||
def test_multiband_calc(tmpdir):
|
||||
outfile = str(tmpdir.join('out.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(calc, [
|
||||
'(+ 125 (* 0.1 (read 1)))', 'tests/data/shade.tif', outfile],
|
||||
catch_exceptions=False)
|
||||
result = runner.invoke(main_group, ['calc'] + [
|
||||
'(+ 125 (* 0.1 (read 1)))', 'tests/data/shade.tif', outfile],
|
||||
catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outfile) as src:
|
||||
assert src.count == 1
|
||||
@ -38,11 +38,9 @@ def test_multiband_calc(tmpdir):
|
||||
def test_singleband_calc_byindex(tmpdir):
|
||||
outfile = str(tmpdir.join('out.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(calc, [
|
||||
'(+ 125 (* 0.1 (read 1 1)))',
|
||||
'tests/data/shade.tif',
|
||||
outfile],
|
||||
catch_exceptions=False)
|
||||
result = runner.invoke(main_group, ['calc'] + [
|
||||
'(+ 125 (* 0.1 (read 1 1)))', 'tests/data/shade.tif', outfile],
|
||||
catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outfile) as src:
|
||||
assert src.count == 1
|
||||
@ -54,11 +52,9 @@ def test_singleband_calc_byindex(tmpdir):
|
||||
def test_singleband_calc_byname(tmpdir):
|
||||
outfile = str(tmpdir.join('out.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(calc, [
|
||||
'(+ 125 (* 0.1 (take shade 1)))',
|
||||
'--name', 'shade=tests/data/shade.tif',
|
||||
outfile],
|
||||
catch_exceptions=False)
|
||||
result = runner.invoke(main_group, ['calc'] + [
|
||||
'(+ 125 (* 0.1 (take shade 1)))', '--name', 'shade=tests/data/shade.tif',
|
||||
outfile], catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outfile) as src:
|
||||
assert src.count == 1
|
||||
@ -72,11 +68,9 @@ def test_parts_calc(tmpdir):
|
||||
# Red band has bumped up values. Other bands are unchanged.
|
||||
outfile = str(tmpdir.join('out.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(calc, [
|
||||
'(asarray (+ (read 1 1) 125) (read 1 1) (read 1 1))',
|
||||
'tests/data/shade.tif',
|
||||
outfile],
|
||||
catch_exceptions=False)
|
||||
result = runner.invoke(main_group, ['calc'] + [
|
||||
'(asarray (+ (read 1 1) 125) (read 1 1) (read 1 1))',
|
||||
'tests/data/shade.tif', outfile], catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outfile) as src:
|
||||
assert src.count == 3
|
||||
@ -91,11 +85,9 @@ def test_parts_calc_2(tmpdir):
|
||||
# Produce greyscale output from the RGB file.
|
||||
outfile = str(tmpdir.join('out.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(calc, [
|
||||
'(+ (+ (/ (read 1 1) 3.0) (/ (read 1 2) 3.0)) (/ (read 1 3) 3.0))',
|
||||
'tests/data/RGB.byte.tif',
|
||||
outfile],
|
||||
catch_exceptions=False)
|
||||
result = runner.invoke(main_group, ['calc'] + [
|
||||
'(+ (+ (/ (read 1 1) 3.0) (/ (read 1 2) 3.0)) (/ (read 1 3) 3.0))',
|
||||
'tests/data/RGB.byte.tif', outfile], catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outfile) as src:
|
||||
assert src.count == 1
|
||||
@ -107,11 +99,9 @@ def test_parts_calc_2(tmpdir):
|
||||
def test_copy_rgb(tmpdir):
|
||||
outfile = str(tmpdir.join('out.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(calc, [
|
||||
'(read 1)',
|
||||
'tests/data/RGB.byte.tif',
|
||||
outfile],
|
||||
catch_exceptions=False)
|
||||
result = runner.invoke(main_group, ['calc'] + [
|
||||
'(read 1)', 'tests/data/RGB.byte.tif', outfile],
|
||||
catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outfile) as src:
|
||||
assert src.count == 3
|
||||
@ -123,11 +113,9 @@ def test_copy_rgb(tmpdir):
|
||||
def test_fillnodata(tmpdir):
|
||||
outfile = str(tmpdir.join('out.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(calc, [
|
||||
'(asarray (fillnodata (read 1 1)) (fillnodata (read 1 2)) (fillnodata (read 1 3)))',
|
||||
'tests/data/RGB.byte.tif',
|
||||
outfile],
|
||||
catch_exceptions=False)
|
||||
result = runner.invoke(main_group, ['calc'] + [
|
||||
'(asarray (fillnodata (read 1 1)) (fillnodata (read 1 2)) (fillnodata (read 1 3)))',
|
||||
'tests/data/RGB.byte.tif', outfile], catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outfile) as src:
|
||||
assert src.count == 3
|
||||
@ -139,11 +127,9 @@ def test_fillnodata(tmpdir):
|
||||
def test_fillnodata_map(tmpdir):
|
||||
outfile = str(tmpdir.join('out.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(calc, [
|
||||
'(asarray (map fillnodata (read 1)))',
|
||||
'tests/data/RGB.byte.tif',
|
||||
outfile],
|
||||
catch_exceptions=False)
|
||||
result = runner.invoke(main_group, ['calc'] + [
|
||||
'(asarray (map fillnodata (read 1)))',
|
||||
'tests/data/RGB.byte.tif', outfile], catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outfile) as src:
|
||||
assert src.count == 3
|
||||
@ -155,11 +141,9 @@ def test_fillnodata_map(tmpdir):
|
||||
def test_sieve_band(tmpdir):
|
||||
outfile = str(tmpdir.join('out.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(calc, [
|
||||
'(sieve (band 1 1) 42)',
|
||||
'tests/data/shade.tif',
|
||||
outfile],
|
||||
catch_exceptions=False)
|
||||
result = runner.invoke(main_group, ['calc'] + [
|
||||
'(sieve (band 1 1) 42)', 'tests/data/shade.tif', outfile],
|
||||
catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outfile) as src:
|
||||
assert src.count == 1
|
||||
@ -169,11 +153,9 @@ def test_sieve_band(tmpdir):
|
||||
def test_sieve_read(tmpdir):
|
||||
outfile = str(tmpdir.join('out.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(calc, [
|
||||
"(sieve (read 1 1 'uint8') 42)",
|
||||
'tests/data/shade.tif',
|
||||
outfile],
|
||||
catch_exceptions=False)
|
||||
result = runner.invoke(main_group, ['calc'] + [
|
||||
"(sieve (read 1 1 'uint8') 42)",
|
||||
'tests/data/shade.tif', outfile], catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outfile) as src:
|
||||
assert src.count == 1
|
||||
|
||||
@ -6,7 +6,6 @@ from click.testing import CliRunner
|
||||
|
||||
import rasterio
|
||||
from rasterio.rio.main import main_group
|
||||
from rasterio.rio.convert import convert
|
||||
|
||||
|
||||
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
||||
@ -74,8 +73,8 @@ def test_format(tmpdir):
|
||||
outputname = str(tmpdir.join('test.jpg'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
convert,
|
||||
['tests/data/RGB.byte.tif', outputname, '--format', 'JPEG'])
|
||||
main_group,
|
||||
['convert', 'tests/data/RGB.byte.tif', outputname, '--format', 'JPEG'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outputname) as src:
|
||||
assert src.driver == 'JPEG'
|
||||
@ -85,8 +84,8 @@ def test_format_short(tmpdir):
|
||||
outputname = str(tmpdir.join('test.jpg'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
convert,
|
||||
['tests/data/RGB.byte.tif', outputname, '-f', 'JPEG'])
|
||||
main_group,
|
||||
['convert', 'tests/data/RGB.byte.tif', outputname, '-f', 'JPEG'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outputname) as src:
|
||||
assert src.driver == 'JPEG'
|
||||
@ -96,8 +95,8 @@ def test_output_opt(tmpdir):
|
||||
outputname = str(tmpdir.join('test.jpg'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
convert,
|
||||
['tests/data/RGB.byte.tif', '-o', outputname, '-f', 'JPEG'])
|
||||
main_group,
|
||||
['convert', 'tests/data/RGB.byte.tif', '-o', outputname, '-f', 'JPEG'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outputname) as src:
|
||||
assert src.driver == 'JPEG'
|
||||
@ -107,8 +106,8 @@ def test_dtype(tmpdir):
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
convert,
|
||||
['tests/data/RGB.byte.tif', outputname, '--dtype', 'uint16'])
|
||||
main_group,
|
||||
['convert', 'tests/data/RGB.byte.tif', outputname, '--dtype', 'uint16'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outputname) as src:
|
||||
assert src.dtypes == tuple(['uint16'] * 3)
|
||||
@ -119,8 +118,8 @@ def test_dtype_rescaling_uint8_full(tmpdir):
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
convert,
|
||||
['tests/data/RGB.byte.tif', outputname, '--scale-ratio', '1.0'])
|
||||
main_group,
|
||||
['convert', 'tests/data/RGB.byte.tif', outputname, '--scale-ratio', '1.0'])
|
||||
assert result.exit_code == 0
|
||||
|
||||
src_stats = [
|
||||
@ -139,8 +138,8 @@ def test_dtype_rescaling_uint8_half(tmpdir):
|
||||
"""Rescale uint8 [0, 255] to uint8 [0, 127]"""
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(convert, [
|
||||
'tests/data/RGB.byte.tif', outputname, '--scale-ratio', '0.5'])
|
||||
result = runner.invoke(main_group, [
|
||||
'convert', 'tests/data/RGB.byte.tif', outputname, '--scale-ratio', '0.5'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outputname) as src:
|
||||
for band in src.read():
|
||||
@ -153,8 +152,8 @@ def test_dtype_rescaling_uint16(tmpdir):
|
||||
# NB: 255 * 16 is 4080, we don't actually get to 4095.
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(convert, [
|
||||
'tests/data/RGB.byte.tif', outputname, '--dtype', 'uint16',
|
||||
result = runner.invoke(main_group, [
|
||||
'convert', 'tests/data/RGB.byte.tif', outputname, '--dtype', 'uint16',
|
||||
'--scale-ratio', '16'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outputname) as src:
|
||||
@ -167,8 +166,8 @@ def test_dtype_rescaling_float64(tmpdir):
|
||||
"""Rescale uint8 [0, 255] to float64 [-1, 1]"""
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(convert, [
|
||||
'tests/data/RGB.byte.tif', outputname, '--dtype', 'float64',
|
||||
result = runner.invoke(main_group, [
|
||||
'convert', 'tests/data/RGB.byte.tif', outputname, '--dtype', 'float64',
|
||||
'--scale-ratio', str(2.0 / 255), '--scale-offset', '-1.0'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outputname) as src:
|
||||
@ -181,8 +180,8 @@ def test_rgb(tmpdir):
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
convert,
|
||||
['tests/data/RGB.byte.tif', outputname, '--rgb'])
|
||||
main_group,
|
||||
['convert', 'tests/data/RGB.byte.tif', outputname, '--rgb'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outputname) as src:
|
||||
assert src.colorinterp(1) == rasterio.enums.ColorInterp.red
|
||||
|
||||
@ -9,9 +9,8 @@ from affine import Affine
|
||||
import numpy as np
|
||||
|
||||
import rasterio
|
||||
from rasterio.rio.rasterize import rasterize
|
||||
from rasterio.rio.main import main_group
|
||||
from rasterio.crs import CRS
|
||||
from rasterio.rio.main import main_group
|
||||
|
||||
DEFAULT_SHAPE = (10, 10)
|
||||
|
||||
@ -499,8 +498,8 @@ def test_rasterize_resolution(tmpdir, runner, basic_feature):
|
||||
def test_rasterize_multiresolution(tmpdir, runner, basic_feature):
|
||||
output = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(
|
||||
rasterize,
|
||||
[output, '--res', 0.15, '--res', 0.15],
|
||||
main_group,
|
||||
['rasterize', output, '--res', 0.15, '--res', 0.15],
|
||||
input=json.dumps(basic_feature)
|
||||
)
|
||||
|
||||
@ -646,10 +645,9 @@ def test_rasterize_featurecollection(tmpdir, runner, basic_feature,
|
||||
'type': 'FeatureCollection',
|
||||
'features': [basic_feature]}
|
||||
result = runner.invoke(
|
||||
rasterize,
|
||||
[output, '--like', pixelated_image_file],
|
||||
input=json.dumps(collection)
|
||||
)
|
||||
main_group,
|
||||
['rasterize', output, '--like', pixelated_image_file],
|
||||
input=json.dumps(collection))
|
||||
assert result.exit_code == 0
|
||||
|
||||
|
||||
@ -657,17 +655,14 @@ def test_rasterize_src_crs_mismatch(tmpdir, runner, basic_feature,
|
||||
pixelated_image_file):
|
||||
output = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(
|
||||
rasterize,
|
||||
[output, '--like', pixelated_image_file],
|
||||
input=json.dumps(basic_feature)
|
||||
)
|
||||
main_group, ['rasterize', output, '--like', pixelated_image_file],
|
||||
input=json.dumps(basic_feature))
|
||||
assert result.exit_code == 0
|
||||
|
||||
result = runner.invoke(
|
||||
rasterize,
|
||||
[output, '--force-overwrite', '--src-crs', 'EPSG:3857'],
|
||||
input=json.dumps(basic_feature)
|
||||
)
|
||||
main_group, [
|
||||
'rasterize', output, '--force-overwrite', '--src-crs', 'EPSG:3857'],
|
||||
input=json.dumps(basic_feature))
|
||||
assert result.exit_code == 2
|
||||
assert 'GeoJSON does not match crs of existing output raster' in result.output
|
||||
|
||||
@ -703,8 +698,7 @@ def test_rasterize_like_raster_outside_bounds(tmpdir, runner, basic_feature,
|
||||
result = runner.invoke(
|
||||
main_group,
|
||||
['rasterize', output, '--like', pixelated_image_file],
|
||||
input=json.dumps(basic_feature)
|
||||
)
|
||||
input=json.dumps(basic_feature))
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert 'outside bounds' in result.output
|
||||
|
||||
@ -18,14 +18,14 @@ logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
||||
def test_edit_nodata_err(data):
|
||||
runner = CliRunner()
|
||||
inputfile = str(data.join('RGB.byte.tif'))
|
||||
result = runner.invoke(edit, [inputfile, '--nodata', '-1'])
|
||||
result = runner.invoke(main_group, ['edit-info', inputfile, '--nodata', '-1'])
|
||||
assert result.exit_code == 2
|
||||
|
||||
|
||||
def test_edit_nodata(data):
|
||||
runner = CliRunner()
|
||||
inputfile = str(data.join('RGB.byte.tif'))
|
||||
result = runner.invoke(edit, [inputfile, '--nodata', '255'])
|
||||
result = runner.invoke(main_group, ['edit-info', inputfile, '--nodata', '255'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(inputfile) as src:
|
||||
assert src.nodata == 255.0
|
||||
@ -34,14 +34,14 @@ def test_edit_nodata(data):
|
||||
def test_edit_crs_err(data):
|
||||
runner = CliRunner()
|
||||
inputfile = str(data.join('RGB.byte.tif'))
|
||||
result = runner.invoke(edit, [inputfile, '--crs', 'LOL:WUT'])
|
||||
result = runner.invoke(main_group, ['edit-info', inputfile, '--crs', 'LOL:WUT'])
|
||||
assert result.exit_code == 2
|
||||
|
||||
|
||||
def test_edit_crs_epsg(data):
|
||||
runner = CliRunner()
|
||||
inputfile = str(data.join('RGB.byte.tif'))
|
||||
result = runner.invoke(edit, [inputfile, '--crs', 'EPSG:32618'])
|
||||
result = runner.invoke(main_group, ['edit-info', inputfile, '--crs', 'EPSG:32618'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(inputfile) as src:
|
||||
assert src.crs == {'init': 'epsg:32618'}
|
||||
@ -50,7 +50,7 @@ def test_edit_crs_epsg(data):
|
||||
def test_edit_crs_proj4(data):
|
||||
runner = CliRunner()
|
||||
inputfile = str(data.join('RGB.byte.tif'))
|
||||
result = runner.invoke(edit, [inputfile, '--crs', '+init=epsg:32618'])
|
||||
result = runner.invoke(main_group, ['edit-info', inputfile, '--crs', '+init=epsg:32618'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(inputfile) as src:
|
||||
assert src.crs == {'init': 'epsg:32618'}
|
||||
@ -60,7 +60,7 @@ def test_edit_crs_obj(data):
|
||||
runner = CliRunner()
|
||||
inputfile = str(data.join('RGB.byte.tif'))
|
||||
result = runner.invoke(
|
||||
edit, [inputfile, '--crs', '{"init": "epsg:32618"}'])
|
||||
main_group, ['edit-info', inputfile, '--crs', '{"init": "epsg:32618"}'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(inputfile) as src:
|
||||
assert src.crs.to_dict() == {'init': 'epsg:32618'}
|
||||
@ -69,14 +69,14 @@ def test_edit_crs_obj(data):
|
||||
def test_edit_transform_err_not_json(data):
|
||||
runner = CliRunner()
|
||||
inputfile = str(data.join('RGB.byte.tif'))
|
||||
result = runner.invoke(edit, [inputfile, '--transform', 'LOL'])
|
||||
result = runner.invoke(main_group, ['edit-info', inputfile, '--transform', 'LOL'])
|
||||
assert result.exit_code == 2
|
||||
|
||||
|
||||
def test_edit_transform_err_bad_array(data):
|
||||
runner = CliRunner()
|
||||
inputfile = str(data.join('RGB.byte.tif'))
|
||||
result = runner.invoke(edit, [inputfile, '--transform', '[1,2]'])
|
||||
result = runner.invoke(main_group, ['edit-info', inputfile, '--transform', '[1,2]'])
|
||||
assert result.exit_code == 2
|
||||
|
||||
|
||||
@ -84,7 +84,7 @@ def test_edit_transform_affine(data):
|
||||
runner = CliRunner()
|
||||
inputfile = str(data.join('RGB.byte.tif'))
|
||||
input_t = '[300.038, 0.0, 101985.0, 0.0, -300.042, 2826915.0]'
|
||||
result = runner.invoke(edit, [inputfile, '--transform', input_t])
|
||||
result = runner.invoke(main_group, ['edit-info', inputfile, '--transform', input_t])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(inputfile) as src:
|
||||
for a, b in zip(src.transform, json.loads(input_t)):
|
||||
@ -95,9 +95,8 @@ def test_edit_transform_gdal(data):
|
||||
runner = CliRunner()
|
||||
inputfile = str(data.join('RGB.byte.tif'))
|
||||
gdal_geotransform = '[101985.0, 300.038, 0.0, 2826915.0, 0.0, -300.042]'
|
||||
result = runner.invoke(edit, [
|
||||
inputfile,
|
||||
'--transform', gdal_geotransform])
|
||||
result = runner.invoke(main_group, [
|
||||
'edit-info', inputfile, '--transform', gdal_geotransform])
|
||||
assert result.exit_code != 0
|
||||
assert 'not recognized as an Affine array' in result.output
|
||||
assert gdal_geotransform in result.output
|
||||
@ -106,8 +105,8 @@ def test_edit_transform_gdal(data):
|
||||
def test_edit_tags(data):
|
||||
runner = CliRunner()
|
||||
inputfile = str(data.join('RGB.byte.tif'))
|
||||
result = runner.invoke(edit, [
|
||||
inputfile, '--tag', 'lol=1', '--tag', 'wut=2'])
|
||||
result = runner.invoke(main_group, [
|
||||
'edit-info', inputfile, '--tag', 'lol=1', '--tag', 'wut=2'])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(inputfile) as src:
|
||||
assert src.tags()['lol'] == '1'
|
||||
|
||||
@ -11,7 +11,8 @@ import numpy as np
|
||||
from pytest import fixture
|
||||
|
||||
import rasterio
|
||||
from rasterio.rio.merge import merge
|
||||
from rasterio.merge import merge
|
||||
from rasterio.rio.main import main_group
|
||||
from rasterio.transform import Affine
|
||||
|
||||
|
||||
@ -83,7 +84,7 @@ def test_merge_with_colormap(test_data_dir_1):
|
||||
src.write_colormap(1, {0: (255, 0, 0, 255), 255: (0, 0, 0, 0)})
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(merge, inputs + [outputname])
|
||||
result = runner.invoke(main_group, ['merge'] + inputs + [outputname])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -98,7 +99,7 @@ def test_merge_with_nodata(test_data_dir_1):
|
||||
inputs = [str(x) for x in test_data_dir_1.listdir()]
|
||||
inputs.sort()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(merge, inputs + [outputname])
|
||||
result = runner.invoke(main_group, ['merge'] + inputs + [outputname])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
with rasterio.open(outputname) as out:
|
||||
@ -115,7 +116,8 @@ def test_merge_warn(test_data_dir_1):
|
||||
inputs = [str(x) for x in test_data_dir_1.listdir()]
|
||||
inputs.sort()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(merge, inputs + [outputname] + ['--nodata', '-1'])
|
||||
result = runner.invoke(
|
||||
main_group, ['merge'] + inputs + [outputname] + ['--nodata', '-1'])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
assert "using the --nodata option for better results" in result.output
|
||||
@ -126,7 +128,7 @@ def test_merge_without_nodata(test_data_dir_2):
|
||||
inputs = [str(x) for x in test_data_dir_2.listdir()]
|
||||
inputs.sort()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(merge, inputs + [outputname])
|
||||
result = runner.invoke(main_group, ['merge'] + inputs + [outputname])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
with rasterio.open(outputname) as out:
|
||||
@ -142,12 +144,10 @@ def test_merge_output_exists(tmpdir):
|
||||
outputname = str(tmpdir.join('merged.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
merge,
|
||||
['tests/data/RGB.byte.tif', outputname])
|
||||
main_group, ['merge', 'tests/data/RGB.byte.tif', outputname])
|
||||
assert result.exit_code == 0
|
||||
result = runner.invoke(
|
||||
merge,
|
||||
['tests/data/RGB.byte.tif', outputname])
|
||||
main_group, ['merge', 'tests/data/RGB.byte.tif', outputname])
|
||||
assert os.path.exists(outputname)
|
||||
with rasterio.open(outputname) as out:
|
||||
assert out.count == 3
|
||||
@ -157,8 +157,8 @@ def test_merge_output_exists_without_nodata_fails(test_data_dir_2):
|
||||
"""Fails without --force-overwrite"""
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
merge,
|
||||
[str(test_data_dir_2.join('a.tif')),
|
||||
main_group, [
|
||||
'merge', str(test_data_dir_2.join('a.tif')),
|
||||
str(test_data_dir_2.join('b.tif'))])
|
||||
assert result.exit_code == 1
|
||||
|
||||
@ -167,8 +167,8 @@ def test_merge_output_exists_without_nodata(test_data_dir_2):
|
||||
"""Succeeds with --force-overwrite"""
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
merge,
|
||||
['--force-overwrite', str(test_data_dir_2.join('a.tif')),
|
||||
main_group, [
|
||||
'merge', '--force-overwrite', str(test_data_dir_2.join('a.tif')),
|
||||
str(test_data_dir_2.join('b.tif'))])
|
||||
assert result.exit_code == 0
|
||||
|
||||
@ -176,8 +176,7 @@ def test_merge_output_exists_without_nodata(test_data_dir_2):
|
||||
def test_merge_err():
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
merge,
|
||||
['tests'])
|
||||
main_group, ['merge', 'tests'])
|
||||
assert result.exit_code == 1
|
||||
|
||||
|
||||
@ -185,8 +184,9 @@ def test_format_jpeg(tmpdir):
|
||||
outputname = str(tmpdir.join('stacked.jpg'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
merge,
|
||||
['tests/data/RGB.byte.tif', outputname, '--format', 'JPEG'])
|
||||
main_group, [
|
||||
'merge', 'tests/data/RGB.byte.tif', outputname,
|
||||
'--format', 'JPEG'])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -225,7 +225,7 @@ def test_merge_overlapping(test_data_dir_overlapping):
|
||||
inputs = [str(x) for x in test_data_dir_overlapping.listdir()]
|
||||
inputs.sort()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(merge, inputs + [outputname])
|
||||
result = runner.invoke(main_group, ['merge'] + inputs + [outputname])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
with rasterio.open(outputname) as out:
|
||||
@ -271,7 +271,8 @@ def test_merge_float(test_data_dir_float):
|
||||
inputs = [str(x) for x in test_data_dir_float.listdir()]
|
||||
inputs.sort()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(merge, inputs + [outputname] + ['--nodata', '-1.5'])
|
||||
result = runner.invoke(
|
||||
main_group, ['merge'] + inputs + [outputname] + ['--nodata', '-1.5'])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
with rasterio.open(outputname) as out:
|
||||
@ -326,7 +327,7 @@ def test_merge_tiny(tiffs):
|
||||
inputs = [str(x) for x in tiffs.listdir()]
|
||||
inputs.sort()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(merge, inputs + [outputname])
|
||||
result = runner.invoke(main_group, ['merge'] + inputs + [outputname])
|
||||
assert result.exit_code == 0
|
||||
|
||||
# Output should be
|
||||
@ -349,7 +350,7 @@ def test_merge_tiny_output_opt(tiffs):
|
||||
inputs = [str(x) for x in tiffs.listdir()]
|
||||
inputs.sort()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(merge, inputs + ['-o', outputname])
|
||||
result = runner.invoke(main_group, ['merge'] + inputs + ['-o', outputname])
|
||||
assert result.exit_code == 0
|
||||
|
||||
# Output should be
|
||||
@ -372,7 +373,8 @@ def test_merge_tiny_res_bounds(tiffs):
|
||||
inputs = [str(x) for x in tiffs.listdir()]
|
||||
inputs.sort()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(merge, inputs + [outputname, '--res', 2, '--bounds', 1, 0, 5, 4])
|
||||
result = runner.invoke(
|
||||
main_group, ['merge'] + inputs + [outputname, '--res', 2, '--bounds', 1, 0, 5, 4])
|
||||
assert result.exit_code == 0
|
||||
|
||||
# Output should be
|
||||
@ -393,7 +395,9 @@ def test_merge_tiny_res_high_precision(tiffs):
|
||||
inputs = [str(x) for x in tiffs.listdir()]
|
||||
inputs.sort()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(merge, inputs + [outputname, '--res', 2, '--precision', 15])
|
||||
result = runner.invoke(
|
||||
main_group,
|
||||
['merge'] + inputs + [outputname, '--res', 2, '--precision', 15])
|
||||
assert result.exit_code == 0
|
||||
|
||||
# Output should be
|
||||
@ -418,7 +422,7 @@ def test_merge_rgb(tmpdir):
|
||||
'tests/data/rgb3.tif',
|
||||
'tests/data/rgb4.tif']
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(merge, inputs + [outputname])
|
||||
result = runner.invoke(main_group, ['merge'] + inputs + [outputname])
|
||||
assert result.exit_code == 0
|
||||
|
||||
with rasterio.open(outputname) as src:
|
||||
@ -426,7 +430,6 @@ def test_merge_rgb(tmpdir):
|
||||
|
||||
|
||||
def test_merge_tiny_intres(tiffs):
|
||||
from rasterio.merge import merge
|
||||
inputs = [str(x) for x in tiffs.listdir()]
|
||||
inputs.sort()
|
||||
sources = [rasterio.open(x) for x in inputs]
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
from click.testing import CliRunner
|
||||
|
||||
import rasterio
|
||||
from rasterio.rio.main import main_group
|
||||
from rasterio.rio.stack import stack
|
||||
|
||||
|
||||
@ -8,9 +9,7 @@ def test_stack(tmpdir):
|
||||
outputname = str(tmpdir.join('stacked.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
stack,
|
||||
['tests/data/RGB.byte.tif', outputname],
|
||||
catch_exceptions=False)
|
||||
main_group, ['stack', 'tests/data/RGB.byte.tif', outputname])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outputname) as out:
|
||||
assert out.count == 3
|
||||
@ -21,8 +20,8 @@ def test_stack_list(tmpdir):
|
||||
outputname = str(tmpdir.join('stacked.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
stack,
|
||||
['tests/data/RGB.byte.tif', '--bidx', '1,2,3', outputname])
|
||||
main_group, [
|
||||
'stack', 'tests/data/RGB.byte.tif', '--bidx', '1,2,3', outputname])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outputname) as out:
|
||||
assert out.count == 3
|
||||
@ -32,8 +31,8 @@ def test_stack_slice(tmpdir):
|
||||
outputname = str(tmpdir.join('stacked.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
stack,
|
||||
[
|
||||
main_group, [
|
||||
'stack',
|
||||
'tests/data/RGB.byte.tif', '--bidx', '..2',
|
||||
'tests/data/RGB.byte.tif', '--bidx', '3..',
|
||||
outputname])
|
||||
@ -46,12 +45,11 @@ def test_stack_single_slice(tmpdir):
|
||||
outputname = str(tmpdir.join('stacked.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
stack,
|
||||
[
|
||||
main_group, [
|
||||
'stack',
|
||||
'tests/data/RGB.byte.tif', '--bidx', '1',
|
||||
'tests/data/RGB.byte.tif', '--bidx', '2..',
|
||||
'--rgb',
|
||||
outputname])
|
||||
'--rgb', outputname])
|
||||
assert result.exit_code == 0
|
||||
with rasterio.open(outputname) as out:
|
||||
assert out.count == 3
|
||||
@ -61,8 +59,9 @@ def test_format_jpeg(tmpdir):
|
||||
outputname = str(tmpdir.join('stacked.jpg'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
stack,
|
||||
['tests/data/RGB.byte.tif', outputname, '--format', 'JPEG'])
|
||||
main_group, [
|
||||
'stack', 'tests/data/RGB.byte.tif', outputname,
|
||||
'--format', 'JPEG'])
|
||||
assert result.exit_code == 0
|
||||
|
||||
|
||||
@ -70,6 +69,7 @@ def test_error(tmpdir):
|
||||
outputname = str(tmpdir.join('stacked.tif'))
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
stack,
|
||||
['tests/data/RGB.byte.tif', outputname, '--driver', 'BOGUS'])
|
||||
main_group, [
|
||||
'stack', 'tests/data/RGB.byte.tif', outputname,
|
||||
'--driver', 'BOGUS'])
|
||||
assert result.exit_code == 1
|
||||
|
||||
@ -29,7 +29,7 @@ def test_dst_crs_error(runner, tmpdir):
|
||||
|
||||
@pytest.mark.xfail(
|
||||
os.environ.get('GDALVERSION', 'a.b.c').startswith('1.9'),
|
||||
reason="GDAL 1.9 doesn't catch this error")
|
||||
reason="GDAL 1.9 doesn't catch this error")
|
||||
def test_dst_crs_error_2(runner, tmpdir):
|
||||
"""Invalid PROJ.4 is a bad parameter."""
|
||||
srcname = 'tests/data/RGB.byte.tif'
|
||||
@ -118,7 +118,7 @@ def test_warp_no_reproject(runner, tmpdir):
|
||||
""" When called without parameters, output should be same as source """
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, outputname])
|
||||
result = runner.invoke(main_group, ['warp', srcname, outputname])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -135,8 +135,8 @@ def test_warp_no_reproject(runner, tmpdir):
|
||||
def test_warp_no_reproject_dimensions(runner, tmpdir):
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--dimensions', '100', '100'])
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--dimensions', '100', '100'])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -146,14 +146,14 @@ def test_warp_no_reproject_dimensions(runner, tmpdir):
|
||||
assert output.width == 100
|
||||
assert output.height == 100
|
||||
assert np.allclose([97.839396, 97.839396],
|
||||
[output.transform.a, -output.transform.e])
|
||||
[output.transform.a, -output.transform.e])
|
||||
|
||||
|
||||
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])
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--res', 30])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -169,8 +169,8 @@ def test_warp_no_reproject_bounds(runner, tmpdir):
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
out_bounds = [-11850000, 4810000, -11849000, 4812000]
|
||||
result = runner.invoke(warp.warp,[srcname, outputname,
|
||||
'--bounds'] + out_bounds)
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--bounds'] + out_bounds)
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -179,7 +179,7 @@ def test_warp_no_reproject_bounds(runner, tmpdir):
|
||||
assert output.crs == src.crs
|
||||
assert np.allclose(output.bounds, out_bounds)
|
||||
assert np.allclose([src.transform.a, src.transform.e],
|
||||
[output.transform.a, output.transform.e])
|
||||
[output.transform.a, output.transform.e])
|
||||
assert output.width == 105
|
||||
assert output.height == 210
|
||||
|
||||
@ -188,9 +188,8 @@ def test_warp_no_reproject_bounds_res(runner, tmpdir):
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
out_bounds = [-11850000, 4810000, -11849000, 4812000]
|
||||
result = runner.invoke(warp.warp,[srcname, outputname,
|
||||
'--res', 30,
|
||||
'--bounds', ] + out_bounds)
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--res', 30, '--bounds'] + out_bounds)
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -202,13 +201,11 @@ def test_warp_no_reproject_bounds_res(runner, tmpdir):
|
||||
assert output.width == 34
|
||||
assert output.height == 67
|
||||
|
||||
|
||||
# dst-bounds should be an alias to bounds
|
||||
outputname = str(tmpdir.join('test2.tif'))
|
||||
out_bounds = [-11850000, 4810000, -11849000, 4812000]
|
||||
result = runner.invoke(warp.warp,[srcname, outputname,
|
||||
'--res', 30,
|
||||
'--dst-bounds', ] + out_bounds)
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--res', 30, '--dst-bounds'] + out_bounds)
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
with rasterio.open(srcname) as src:
|
||||
@ -219,8 +216,8 @@ def test_warp_no_reproject_bounds_res(runner, tmpdir):
|
||||
def test_warp_reproject_dst_crs(runner, tmpdir):
|
||||
srcname = 'tests/data/RGB.byte.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--dst-crs', 'EPSG:4326'])
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--dst-crs', 'EPSG:4326'])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -230,17 +227,17 @@ def test_warp_reproject_dst_crs(runner, tmpdir):
|
||||
assert output.crs == {'init': 'epsg:4326'}
|
||||
assert output.width == 835
|
||||
assert output.height == 696
|
||||
assert np.allclose(output.bounds,
|
||||
[-78.95864996545055, 23.564787976164418,
|
||||
-76.5759177302349, 25.550873767433984])
|
||||
assert np.allclose(output.bounds, [
|
||||
-78.95864996545055, 23.564787976164418,
|
||||
-76.5759177302349, 25.550873767433984])
|
||||
|
||||
|
||||
def test_warp_reproject_dst_crs_proj4(runner, tmpdir):
|
||||
proj4 = '+proj=longlat +ellps=WGS84 +datum=WGS84'
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--dst-crs', proj4])
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--dst-crs', proj4])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -251,9 +248,8 @@ def test_warp_reproject_dst_crs_proj4(runner, tmpdir):
|
||||
def test_warp_reproject_res(runner, tmpdir):
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--dst-crs', 'EPSG:4326',
|
||||
'--res', 0.01])
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--dst-crs', 'EPSG:4326', '--res', 0.01])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -267,19 +263,18 @@ def test_warp_reproject_res(runner, tmpdir):
|
||||
def test_warp_reproject_dimensions(runner, tmpdir):
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--dst-crs', 'EPSG:4326',
|
||||
'--dimensions', '100', '100'])
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--dst-crs', 'EPSG:4326',
|
||||
'--dimensions', '100', '100'])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
with rasterio.open(srcname) as src:
|
||||
with rasterio.open(outputname) as output:
|
||||
assert output.crs == {'init': 'epsg:4326'}
|
||||
assert output.width == 100
|
||||
assert output.height == 100
|
||||
assert np.allclose([0.0008789062498762235, 0.0006771676143921468],
|
||||
[output.transform.a, -output.transform.e])
|
||||
with rasterio.open(outputname) as output:
|
||||
assert output.crs == {'init': 'epsg:4326'}
|
||||
assert output.width == 100
|
||||
assert output.height == 100
|
||||
assert np.allclose([0.0008789062498762235, 0.0006771676143921468],
|
||||
[output.transform.a, -output.transform.e])
|
||||
|
||||
|
||||
def test_warp_reproject_dimensions_invalid_params(runner, tmpdir):
|
||||
@ -304,9 +299,9 @@ def test_warp_reproject_bounds_no_res(runner, tmpdir):
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
out_bounds = [-11850000, 4810000, -11849000, 4812000]
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--dst-crs', 'EPSG:4326',
|
||||
'--bounds', ] + out_bounds)
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--dst-crs', 'EPSG:4326', '--bounds'] +
|
||||
out_bounds)
|
||||
assert result.exit_code == 2
|
||||
|
||||
|
||||
@ -315,10 +310,9 @@ def test_warp_reproject_multi_bounds_fail(runner, tmpdir):
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
out_bounds = [-11850000, 4810000, -11849000, 4812000]
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--dst-crs', 'EPSG:4326',
|
||||
'--src-bounds'] + out_bounds +
|
||||
['--bounds'] + out_bounds)
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--dst-crs', 'EPSG:4326',
|
||||
'--src-bounds'] + out_bounds + ['--bounds'] + out_bounds)
|
||||
assert result.exit_code == 2
|
||||
|
||||
|
||||
@ -327,10 +321,9 @@ def test_warp_reproject_bounds_crossup_fail(runner, tmpdir):
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
out_bounds = [-11850000, 4810000, -11849000, 4812000]
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--dst-crs', 'EPSG:4326',
|
||||
'--res', 0.001, '--bounds', ]
|
||||
+ out_bounds)
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--dst-crs', 'EPSG:4326', '--res', 0.001,
|
||||
'--bounds'] + out_bounds)
|
||||
assert result.exit_code == 2
|
||||
|
||||
|
||||
@ -340,20 +333,20 @@ def test_warp_reproject_src_bounds_res(runner, tmpdir):
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
out_bounds = [-11850000, 4810000, -11849000, 4812000]
|
||||
result = runner.invoke(
|
||||
warp.warp, [srcname, outputname, '--dst-crs', 'EPSG:4326',
|
||||
'--res', 0.001, '--src-bounds'] + out_bounds)
|
||||
main_group, [
|
||||
'warp', srcname, outputname, '--dst-crs', 'EPSG:4326',
|
||||
'--res', 0.001, '--src-bounds'] + out_bounds)
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
with rasterio.open(srcname) as src:
|
||||
with rasterio.open(outputname) as output:
|
||||
assert output.crs == {'init': 'epsg:4326'}
|
||||
assert np.allclose(output.bounds[:],
|
||||
[-106.45036, 39.6138, -106.44136, 39.6278])
|
||||
assert np.allclose([0.001, 0.001],
|
||||
[output.transform.a, -output.transform.e])
|
||||
assert output.width == 9
|
||||
assert output.height == 14
|
||||
with rasterio.open(outputname) as output:
|
||||
assert output.crs == {'init': 'epsg:4326'}
|
||||
assert np.allclose(output.bounds[:],
|
||||
[-106.45036, 39.6138, -106.44136, 39.6278])
|
||||
assert np.allclose([0.001, 0.001],
|
||||
[output.transform.a, -output.transform.e])
|
||||
assert output.width == 9
|
||||
assert output.height == 14
|
||||
|
||||
|
||||
def test_warp_reproject_dst_bounds(runner, tmpdir):
|
||||
@ -362,26 +355,26 @@ def test_warp_reproject_dst_bounds(runner, tmpdir):
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
out_bounds = [-106.45036, 39.6138, -106.44136, 39.6278]
|
||||
result = runner.invoke(
|
||||
warp.warp, [srcname, outputname, '--dst-crs', 'EPSG:4326',
|
||||
'--res', 0.001, '--bounds'] + out_bounds)
|
||||
main_group, [
|
||||
'warp', srcname, outputname, '--dst-crs', 'EPSG:4326',
|
||||
'--res', 0.001, '--bounds'] + out_bounds)
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
with rasterio.open(srcname) as src:
|
||||
with rasterio.open(outputname) as output:
|
||||
assert output.crs == {'init': 'epsg:4326'}
|
||||
assert np.allclose(output.bounds[0::3],
|
||||
[-106.45036, 39.6278])
|
||||
assert np.allclose([0.001, 0.001],
|
||||
[output.transform.a, -output.transform.e])
|
||||
with rasterio.open(outputname) as output:
|
||||
assert output.crs == {'init': 'epsg:4326'}
|
||||
assert np.allclose(output.bounds[0::3],
|
||||
[-106.45036, 39.6278])
|
||||
assert np.allclose([0.001, 0.001],
|
||||
[output.transform.a, -output.transform.e])
|
||||
|
||||
# XXX: an extra row and column is produced in the dataset
|
||||
# because we're using ceil instead of floor internally.
|
||||
# Not necessarily a bug, but may change in the future.
|
||||
assert np.allclose([output.bounds[2]-0.001, output.bounds[1]+0.001],
|
||||
[-106.44136, 39.6138])
|
||||
assert output.width == 10
|
||||
assert output.height == 15
|
||||
# XXX: an extra row and column is produced in the dataset
|
||||
# because we're using ceil instead of floor internally.
|
||||
# Not necessarily a bug, but may change in the future.
|
||||
assert np.allclose([output.bounds[2] - 0.001, output.bounds[1] + 0.001],
|
||||
[-106.44136, 39.6138])
|
||||
assert output.width == 10
|
||||
assert output.height == 15
|
||||
|
||||
|
||||
def test_warp_reproject_like(runner, tmpdir):
|
||||
@ -405,8 +398,8 @@ def test_warp_reproject_like(runner, tmpdir):
|
||||
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--like', likename])
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--like', likename])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -440,8 +433,8 @@ def test_warp_reproject_like_invalid_params(runner, tmpdir):
|
||||
def test_warp_reproject_nolostdata(runner, tmpdir):
|
||||
srcname = 'tests/data/world.byte.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--dst-crs', 'EPSG:3857'])
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--dst-crs', 'EPSG:3857'])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -462,10 +455,8 @@ def test_warp_dst_crs_empty_string(runner, tmpdir):
|
||||
infile = 'tests/data/RGB.byte.tif'
|
||||
outfile = str(tmpdir.mkdir('empty_warp_dst_crs.tif').join('test.tif'))
|
||||
|
||||
result = runner.invoke(warp.warp, [
|
||||
infile,
|
||||
outfile,
|
||||
'--dst-crs', ''])
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', infile, outfile, '--dst-crs', ''])
|
||||
|
||||
assert result.exit_code != 0
|
||||
assert 'empty or invalid' in result.output
|
||||
@ -474,9 +465,9 @@ def test_warp_dst_crs_empty_string(runner, tmpdir):
|
||||
def test_warp_badcrs_dimensions(runner, tmpdir):
|
||||
srcname = 'tests/data/shade.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--dst-crs', '{"init": "epsg:-1"}',
|
||||
'--dimensions', '100', '100'])
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--dst-crs', '{"init": "epsg:-1"}',
|
||||
'--dimensions', '100', '100'])
|
||||
assert result.exit_code == 2
|
||||
assert "Invalid value for dst_crs" in result.output
|
||||
|
||||
@ -486,9 +477,9 @@ def test_warp_badcrs_src_bounds(runner, tmpdir):
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
out_bounds = [-11850000, 4810000, -11849000, 4812000]
|
||||
result = runner.invoke(
|
||||
warp.warp, [srcname, outputname,
|
||||
'--dst-crs', '{"init": "epsg:-1"}',
|
||||
'--res', 0.001, '--src-bounds'] + out_bounds)
|
||||
main_group, [
|
||||
'warp', srcname, outputname, '--dst-crs', '{"init": "epsg:-1"}',
|
||||
'--res', 0.001, '--src-bounds'] + out_bounds)
|
||||
assert result.exit_code == 2
|
||||
assert "Invalid value for dst_crs" in result.output
|
||||
|
||||
@ -496,9 +487,9 @@ def test_warp_badcrs_src_bounds(runner, tmpdir):
|
||||
def test_warp_reproject_check_invert(runner, tmpdir):
|
||||
srcname = 'tests/data/world.rgb.tif'
|
||||
outputname = str(tmpdir.join('test.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, outputname,
|
||||
'--check-invert-proj',
|
||||
'--dst-crs', 'EPSG:3759'])
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, outputname, '--check-invert-proj',
|
||||
'--dst-crs', 'EPSG:3759'])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(outputname)
|
||||
|
||||
@ -507,8 +498,8 @@ def test_warp_reproject_check_invert(runner, tmpdir):
|
||||
shape1 = output.shape
|
||||
|
||||
output2name = str(tmpdir.join('test2.tif'))
|
||||
result = runner.invoke(warp.warp, [srcname, output2name,
|
||||
'--dst-crs', 'EPSG:3759'])
|
||||
result = runner.invoke(main_group, [
|
||||
'warp', srcname, output2name, '--dst-crs', 'EPSG:3759'])
|
||||
assert result.exit_code == 0
|
||||
assert os.path.exists(output2name)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user