def test_write_read_geotiff_kwoptions(self): img = np.ones((self.height, self.width), np.int16) nodata = 42 path = os.path.join(os.getcwd(), "test_write_read_geotiff.tif") ImageIO.gdal_write("GTiff", img, path, self.projection, self.coordinates, options=["COMPRESS=DEFLATE"], nodata=nodata) self.assertTrue(os.path.exists(path)) arr, ds = ImageIO.tiff_to_array(path, array_only=False) self.assertTrue((arr == img).all()) self.assertEqual( nodata, gdal.Info(ds, format="json")["bands"][0]["noDataValue"]) self.assertEqual( gdal.Info( ds, format="json")["metadata"]["IMAGE_STRUCTURE"]["COMPRESSION"], "DEFLATE") self.assertEqual(ds.GetGeoTransform(), self.coordinates) # Compare projections by removing all spaces cause of multiline string self.assertEqual(ds.GetProjection().replace(" ", ""), self.projection.replace(" ", "")) FileSystem.remove_file(path) self.assertFalse(os.path.exists(path))
def write(self, p_out, **kwargs): """ Write the array to a given location :param p_out: Location to write to, overrides internal `self._p_out` parameter :keyword kwargs: Optional gdal keyword arguments. :return: Writes array to given location """ nodata = kwargs.pop("nodata", self.nodata_value) driver = kwargs.pop("driver", "GTiff") return ImageIO.gdal_write(driver, self.array, p_out, self.projection, self.geotransform, nodata=nodata, **kwargs)