summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Wiesmann <daniel.wiesmann@gmail.com>2017-06-08 15:51:19 +0100
committerTim Graham <timograham@gmail.com>2017-06-08 12:44:26 -0400
commitfe5e34a2954afdeaabbee80c762735acdd29a948 (patch)
treefbc10f91b7d17f2410cd4c80793d228a5dd7d613 /tests
parent0c3c37a376bac149fe7e7e4b2696f8fb7990e2ab (diff)
Fixed #28288 -- Allowed passing papsz options to GDALRaster initialization.
Diffstat (limited to 'tests')
-rw-r--r--tests/gis_tests/gdal_tests/test_raster.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/gis_tests/gdal_tests/test_raster.py b/tests/gis_tests/gdal_tests/test_raster.py
index f82b37a6a9..756b7a2726 100644
--- a/tests/gis_tests/gdal_tests/test_raster.py
+++ b/tests/gis_tests/gdal_tests/test_raster.py
@@ -310,6 +310,44 @@ class GDALRasterTests(SimpleTestCase):
info_ref = [line.strip() for line in gdalinfo.split('\n') if line.strip() != '']
self.assertEqual(info_dyn, info_ref)
+ def test_compressed_file_based_raster_creation(self):
+ rstfile = tempfile.NamedTemporaryFile(suffix='.tif')
+ # Make a compressed copy of an existing raster.
+ compressed = self.rs.warp({'papsz_options': {'compress': 'packbits'}, 'name': rstfile.name})
+ # Check physically if compression worked.
+ self.assertLess(os.path.getsize(compressed.name), os.path.getsize(self.rs.name))
+ if GDAL_VERSION > (1, 11):
+ # Create file-based raster with options from scratch.
+ compressed = GDALRaster({
+ 'datatype': 1,
+ 'driver': 'tif',
+ 'name': rstfile.name,
+ 'width': 40,
+ 'height': 40,
+ 'srid': 3086,
+ 'origin': (500000, 400000),
+ 'scale': (100, -100),
+ 'skew': (0, 0),
+ 'bands': [{
+ 'data': range(40 ^ 2),
+ 'nodata_value': 255,
+ }],
+ 'papsz_options': {
+ 'compress': 'packbits',
+ 'pixeltype': 'signedbyte',
+ 'blockxsize': 23,
+ 'blockysize': 23,
+ }
+ })
+ # Check if options used on creation are stored in metadata.
+ # Reopening the raster ensures that all metadata has been written
+ # to the file.
+ compressed = GDALRaster(compressed.name)
+ self.assertEqual(compressed.metadata['IMAGE_STRUCTURE']['COMPRESSION'], 'PACKBITS',)
+ self.assertEqual(compressed.bands[0].metadata['IMAGE_STRUCTURE']['PIXELTYPE'], 'SIGNEDBYTE')
+ if GDAL_VERSION >= (2, 1):
+ self.assertIn('Block=40x23', compressed.info)
+
def test_raster_warp(self):
# Create in memory raster
source = GDALRaster({