Skip to content

Commit

Permalink
Merge 66219ca into 80c6fbb
Browse files Browse the repository at this point in the history
  • Loading branch information
sgillies committed Jun 26, 2018
2 parents 80c6fbb + 66219ca commit 8095618
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
5 changes: 1 addition & 4 deletions rasterio/_base.pyx
Expand Up @@ -1062,9 +1062,6 @@ cdef class DatasetBase(object):
value : iter
A sequence of ``ColorInterp.<enum>``.
"""

value = tuple(value)

if self.mode == 'r':
raise RasterioIOError(
"Can only set color interpretation when dataset is "
Expand All @@ -1077,7 +1074,7 @@ cdef class DatasetBase(object):

for bidx, ci in zip(self.indexes, value):
exc_wrap_int(
GDALSetRasterColorInterpretation(self.band(bidx), ci.value))
GDALSetRasterColorInterpretation(self.band(bidx), <GDALColorInterp>ci.value))

def colormap(self, bidx):
"""Returns a dict containing the colormap for a band or None."""
Expand Down
10 changes: 5 additions & 5 deletions rasterio/rio/mask.py
Expand Up @@ -111,17 +111,17 @@ def mask(
'input raster',
param=crop,
param_hint='--crop')
else: # pragma: no cover
else: # pragma: no cover
raise e

meta = src.meta.copy()
meta.update(**creation_options)
meta.update({
profile = src.profile
profile.update(**creation_options)
profile.update({
'driver': driver,
'height': out_image.shape[1],
'width': out_image.shape[2],
'transform': out_transform
})

with rasterio.open(output, 'w', **meta) as out:
with rasterio.open(output, 'w', **profile) as out:
out.write(out_image)
4 changes: 3 additions & 1 deletion tests/test_colorinterp.py
Expand Up @@ -86,9 +86,11 @@ def test_set_colorinterp(path_rgba_byte_tif, tmpdir, dtype):

@pytest.mark.parametrize("ci", ColorInterp.__members__.values())
def test_set_colorinterp_all(path_4band_no_colorinterp, ci):

"""Test setting with all color interpretations."""

if ci.value == 1:
pytest.xfail("Setting colorinterp to gray fails with GDAL 2.3, see https://github.com/mapbox/rasterio/issues/1234")

with rasterio.open(path_4band_no_colorinterp, 'r+') as src:
all_ci = list(src.colorinterp)
all_ci[1] = ci
Expand Down
11 changes: 9 additions & 2 deletions tests/test_rio_mask.py
Expand Up @@ -10,11 +10,15 @@

import rasterio
from rasterio.crs import CRS
from rasterio.env import GDALVersion
from rasterio.rio.main import main_group

from .conftest import requires_gdal22


gdal_version = GDALVersion.runtime()


def test_mask(runner, tmpdir, basic_feature, basic_image_2x2,
pixelated_image_file):

Expand Down Expand Up @@ -160,7 +164,9 @@ def test_mask_invalid_geojson(runner, tmpdir, pixelated_image_file):
assert 'Invalid GeoJSON' in result.output



@pytest.mark.xfail(
gdal_version.at_least('2.3'),
reason="Test only applicable to GDAL < 2.3")
@requires_gdal22(
reason="This test is sensitive to pixel values and requires GDAL 2.2+")
def test_mask_crop(runner, tmpdir, basic_feature, pixelated_image):
Expand All @@ -173,7 +179,7 @@ def test_mask_crop(runner, tmpdir, basic_feature, pixelated_image):
outfilename = str(tmpdir.join('pixelated_image.tif'))
kwargs = {
"crs": CRS({'init': 'epsg:4326'}),
"transform": affine.Affine(1, 0, 0, 0, -1, 0),
"transform": affine.Affine(1.0, 0, 0, 0, -1.0, 0),
"count": 1,
"dtype": rasterio.uint8,
"driver": "GTiff",
Expand All @@ -192,6 +198,7 @@ def test_mask_crop(runner, tmpdir, basic_feature, pixelated_image):
main_group,
['mask', outfilename, output, '--crop', '--geojson-mask', '-'],
input=json.dumps(basic_feature))

assert result.exit_code == 0
assert os.path.exists(output)
with rasterio.open(output) as out:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_transform.py
Expand Up @@ -2,10 +2,14 @@
import pytest
import rasterio
from rasterio import transform
from rasterio.env import GDALVersion
from rasterio.transform import xy, rowcol
from rasterio.windows import Window


gdal_version = GDALVersion.runtime()


def test_window_transform():
with rasterio.open('tests/data/RGB.byte.tif') as src:
assert src.window_transform(((0, None), (0, None))) == src.transform
Expand Down Expand Up @@ -78,6 +82,9 @@ def test_affine_roundtrip(tmpdir):
assert out.transform == out_affine


@pytest.mark.skipif(
gdal_version.at_least('2.3'),
reason="Test only applicable to GDAL < 2.3")
def test_affine_identity(tmpdir):
"""
Setting a transform with absolute values equivalent to Affine.identity()
Expand Down

0 comments on commit 8095618

Please sign in to comment.