def test_fix_global_metadata(self): ds = gdal.Open(self.test_file_gcps) vrt = VRT.copy_dataset(ds) vrt.dataset.SetMetadataItem(str('test'), str('"test"')) vrt.fix_global_metadata(['AREA_OR_POINT']) self.assertNotIn('AREA_OR_POINT', vrt.dataset.GetMetadata()) self.assertEqual('"test"', vrt.dataset.GetMetadataItem(str('test')))
def test_leave_few_bands(self): ds = gdal.Open(self.test_file_gcps) vrt = VRT.copy_dataset(ds) vrt.leave_few_bands([1, 'L_469']) self.assertEqual(vrt.dataset.RasterCount,2) self.assertEqual(vrt.dataset.GetRasterBand(1).GetMetadataItem(str('name')), 'L_645') self.assertEqual(vrt.dataset.GetRasterBand(2).GetMetadataItem(str('name')), 'L_469')
def test_set_fake_gcps_empty(self): ds = gdal.Open('NETCDF:"%s":UMass_AES' % self.test_file_arctic) vrt = VRT.copy_dataset(ds) dst_wkt = vrt._set_fake_gcps(self.nsr_wkt, [], 1) self.assertEqual(dst_wkt, self.nsr_wkt) self.assertEqual(len(vrt.dataset.GetGCPs()), 0)
def test_fix_band_metadata(self): ds = gdal.Open(self.test_file_gcps) vrt = VRT.copy_dataset(ds) self.assertIn('standard_name', vrt.dataset.GetRasterBand(1).GetMetadata()) self.assertIn('time', vrt.dataset.GetRasterBand(1).GetMetadata()) vrt.fix_band_metadata(['standard_name', 'time']) self.assertNotIn('standard_name', vrt.dataset.GetRasterBand(1).GetMetadata()) self.assertNotIn('time', vrt.dataset.GetRasterBand(1).GetMetadata())
def test_set_gcps_geolocation_geotransform_with_geotransform(self): ds = gdal.Open('NETCDF:"%s":UMass_AES' % self.test_file_arctic) vrt = VRT.copy_dataset(ds) vrt._set_gcps_geolocation_geotransform() self.assertEqual(vrt.dataset.GetGeoTransform(), (-1000000.0, 25000.0, 0.0, 5000000.0, 0.0, -25000.0)) self.assertEqual(vrt.dataset.GetMetadata(str('GEOLOCATION')), {}) self.assertEqual(vrt.dataset.GetGCPs(), ())
def test_hardcopy_bands(self): ds = gdal.Open(self.test_file_gcps) vrt = VRT.copy_dataset(ds) vrt.hardcopy_bands() self.assertTrue(np.allclose(vrt.dataset.ReadAsArray(), ds.ReadAsArray())) band_nodes = Node.create(str(vrt.xml)).nodeList('VRTRasterBand') self.assertEqual(band_nodes[0].node('SourceFilename').value, vrt.band_vrts[1].filename) self.assertEqual(band_nodes[1].node('SourceFilename').value, vrt.band_vrts[2].filename) self.assertEqual(band_nodes[2].node('SourceFilename').value, vrt.band_vrts[3].filename)
def test_set_fake_gcps(self): ds = gdal.Open('NETCDF:"%s":UMass_AES' % self.test_file_arctic) gcps = gdal.Open(self.test_file_gcps).GetGCPs() vrt = VRT.copy_dataset(ds) dst_wkt = vrt._set_fake_gcps(self.nsr_wkt, gcps, 1) self.assertEqual(dst_wkt, None) self.assertEqual(len(vrt.dataset.GetGCPs()), len(gcps)) self.assertEqual([gcp.GCPPixel for gcp in gcps], [gcp.GCPX for gcp in vrt.dataset.GetGCPs()]) self.assertEqual([gcp.GCPLine for gcp in gcps], [gcp.GCPY for gcp in vrt.dataset.GetGCPs()])
def test_update_warped_vrt_xml(self): dataset = gdal.Open('NETCDF:"%s":UMass_AES' % self.test_file_arctic) warped_dataset = gdal.AutoCreateWarpedVRT(dataset, None, str(self.nsr_wkt), 0) warped_vrt = VRT.copy_dataset(warped_dataset) x_size = 100 y_size = 200 geo_transform = (0.0, 1.0, 0.0, 200.0, 0.0, -1.0) block_size = 64 working_data_type = 'Float32' warped_vrt._update_warped_vrt_xml(x_size, y_size, geo_transform, block_size, working_data_type) self.assertEqual(warped_vrt.dataset.RasterXSize, x_size) self.assertEqual(warped_vrt.dataset.RasterYSize, y_size) self.assertEqual(warped_vrt.dataset.GetGeoTransform(), geo_transform) self.assertEqual(warped_vrt.dataset.GetRasterBand(1).GetBlockSize(), [block_size, block_size]) self.assertIn('<WorkingDataType>Float32</WorkingDataType>', warped_vrt.xml)
def test_remove_geotransform(self): ds = gdal.Open('NETCDF:"%s":UMass_AES' % self.test_file_arctic) vrt = VRT.copy_dataset(ds) self.assertTrue('<GeoTransform>' in vrt.xml) vrt._remove_geotransform() self.assertFalse('<GeoTransform>' in vrt.xml)