Skip to content

Commit

Permalink
Merge pull request #69 from djhoese/bugfix-tiff-ext
Browse files Browse the repository at this point in the history
Add .tiff as recognized geotiff extension
  • Loading branch information
djhoese committed Jun 3, 2020
2 parents 9b779dc + 572ef0c commit 1f63856
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions trollimage/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,17 @@ def test_save_geotiff_int(self):
np.testing.assert_allclose(file_data[1], exp[:, :, 1])
np.testing.assert_allclose(file_data[2], exp[:, :, 2])
np.testing.assert_allclose(file_data[3], 255)
# test .tiff too
with NamedTemporaryFile(suffix='.tiff') as tmp:
img.save(tmp.name)
with rio.open(tmp.name) as f:
file_data = f.read()
self.assertEqual(file_data.shape, (4, 5, 5)) # alpha band added
exp = np.arange(75).reshape(5, 5, 3)
np.testing.assert_allclose(file_data[0], exp[:, :, 0])
np.testing.assert_allclose(file_data[1], exp[:, :, 1])
np.testing.assert_allclose(file_data[2], exp[:, :, 2])
np.testing.assert_allclose(file_data[3], 255)

data = xr.DataArray(da.from_array(np.arange(75).reshape(5, 5, 3), chunks=5),
dims=['y', 'x', 'bands'],
Expand Down
3 changes: 2 additions & 1 deletion trollimage/xrimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def save(self, filename, fformat=None, fill_value=None, compute=True,
"""
kwformat = format_kwargs.pop('format', None)
fformat = fformat or kwformat or os.path.splitext(filename)[1][1:]
if fformat in ('tif', 'jp2') and rasterio:
if fformat in ('tif', 'tiff', 'jp2') and rasterio:
return self.rio_save(filename, fformat=fformat,
fill_value=fill_value, compute=compute,
keep_palette=keep_palette, cmap=cmap,
Expand Down Expand Up @@ -477,6 +477,7 @@ def rio_save(self, filename, fformat=None, fill_value=None,
drivers = {'jpg': 'JPEG',
'png': 'PNG',
'tif': 'GTiff',
'tiff': 'GTiff',
'jp2': 'JP2OpenJPEG'}
driver = drivers.get(fformat, fformat)

Expand Down

0 comments on commit 1f63856

Please sign in to comment.