def test_nodata(self): inputfile = os.path.join(__dir__, 'srtm.nodata.tif') vrt = warp(inputfile=inputfile) with vrt.get_tempfile(suffix='.vrt') as outputfile: # No Data value must be the same as the input file's in_data = Dataset(inputfile) out_data = Dataset(outputfile.name) for band in range(1, out_data.RasterCount + 1): self.assertEqual( in_data.GetRasterBand(band).GetNoDataValue(), out_data.GetRasterBand(band).GetNoDataValue())
def test_nodata(self): inputfile = os.path.join(__dir__, 'srtm.nodata.tif') in_data = Dataset(inputfile) with NamedTemporaryFile(suffix='.tif') as outputfile: preprocess(inputfile=inputfile, outputfile=outputfile.name) self.assertTrue(os.path.exists(outputfile.name)) self.assertTrue(os.stat(outputfile.name).st_size > 0) # Output nodata value should be the same an input nodata value out_data = Dataset(outputfile.name) self.assertEqual(out_data.RasterCount, 1) # Only one output band self.assertEqual( out_data.GetRasterBand(1).GetNoDataValue(), in_data.GetRasterBand(1).GetNoDataValue())
def test_delete_dataset(self): dataset = Dataset(self.float32file) band = dataset.GetRasterBand(1) # Delete the dataset del dataset # Band should still be valid self.assertEqual(band.GetNoDataValue(), None)
def test_readasarray(self): with LibVips.disable_warnings(): vips_ds = VipsDataset(inputfile=self.upsamplingfile) gdal_ds = Dataset(inputfile=self.upsamplingfile) # Reading the whole file self.assertEqual( vips_ds.ReadAsArray(xoff=0, yoff=0).all(), gdal_ds.ReadAsArray(xoff=0, yoff=0).all()) # Reading from an offset vips_data = vips_ds.ReadAsArray(xoff=128, yoff=128) gdal_data = gdal_ds.ReadAsArray(xoff=128, yoff=128, xsize=128, ysize=128) self.assertEqual(vips_data.all(), gdal_data.all()) vips_blue = vips_ds.GetRasterBand(3) gdal_blue = gdal_ds.GetRasterBand(3) # Reading the whole band self.assertEqual( vips_blue.ReadAsArray(xoff=0, yoff=0).all(), gdal_blue.ReadAsArray(xoff=0, yoff=0).all()) # Reading from an offset vips_band_data = vips_blue.ReadAsArray(xoff=128, yoff=128) gdal_band_data = gdal_blue.ReadAsArray(xoff=128, yoff=128, win_xsize=128, win_ysize=128) self.assertEqual(vips_band_data.all(), gdal_band_data.all()) # Test for errors self.assertRaises(ValueError, vips_ds.ReadAsArray, xoff=0, yoff=0, buf_obj=[]) self.assertRaises(ValueError, vips_blue.ReadAsArray, xoff=0, yoff=0, buf_xsize=1, buf_ysize=1)
def test_simple(self): inputfile = os.path.join(__dir__, 'srtm.tif') with NamedTemporaryFile(suffix='.tif') as outputfile: preprocess(inputfile=inputfile, outputfile=outputfile.name) self.assertTrue(os.path.exists(outputfile.name)) self.assertTrue(os.stat(outputfile.name).st_size > 0) in_data = Dataset(inputfile) out_data = Dataset(outputfile.name) # Output size should match input size self.assertEqual(out_data.RasterXSize, in_data.RasterXSize) self.assertEqual(out_data.RasterYSize, in_data.RasterYSize) # No Data value never existed for band in range(1, out_data.RasterCount + 1): self.assertEqual( out_data.GetRasterBand(band).GetNoDataValue(), None)