Created
December 19, 2017 01:13
-
-
Save geowurster/d89371d51d5286328e2fa210922a7f2c to your computer and use it in GitHub Desktop.
GDAL Trunk CI Failure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import affine | |
import rasterio | |
from rasterio import shutil as rio_shutil | |
from rasterio.enums import ColorInterp | |
path_4band_no_colorinterp = '4band-no-ci.tif' | |
# This seems to be a GDAL default. GDAL 2.2 allows 'undefined' for first | |
# band, but older versions silently convert to 'gray' | |
undefined_ci = ( | |
ColorInterp.gray, | |
ColorInterp.undefined, | |
ColorInterp.undefined, | |
ColorInterp.undefined) | |
profile = { | |
'height': 10, | |
'width': 10, | |
'count': 4, | |
'dtype': rasterio.ubyte, | |
'transform': affine.Affine(1, 0.0, 0, | |
0.0, -1, 1), | |
'driver': 'GTiff', | |
'photometric': 'minisblack' | |
} | |
with rasterio.open(path_4band_no_colorinterp, 'w', **profile) as src: | |
src.colorinterp = undefined_ci | |
# Ensure color interp was set. | |
with rasterio.open(path_4band_no_colorinterp) as src: | |
if src.colorinterp != undefined_ci: | |
raise ValueError( | |
"Didn't properly set color interpretation. GDAL can " | |
"forcefully make assumptions.") | |
for ci in ColorInterp.__members__.values(): | |
with rasterio.open(path_4band_no_colorinterp, 'r+') as src: | |
all_ci = list(src.colorinterp) | |
# Adjust CI for first band. This appears to be failing on GDAL | |
# trunk for 'ColorInterp.gray' and 'ColorInterp.grey', which are | |
# aliases for the same value. | |
all_ci[1] = ci | |
src.colorinterp = all_ci | |
with rasterio.open(path_4band_no_colorinterp) as src: | |
assert src.colorinterp[1] == ci |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment