Esempio n. 1
0
File: hdf5.py Progetto: matrix0/gdal
def hdf5_7():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    ds = gdal.Open('data/metadata.h5')
    metadata = ds.GetMetadata()
    metadataList = ds.GetMetadata_List()
    ds = None

    if gdaltest.is_file_open('data/metadata.h5'):
        gdaltest.post_reason('file still opened.')
        return 'fail'

    if len(metadata) != len(metadataList):
        gdaltest.post_reason('error in metadata dictionary setup')
        return 'fail'

    metadataList = [item.split('=', 1)[0] for item in metadataList]
    for key in metadataList:
        try:
            metadata.pop(key)
        except KeyError:
            gdaltest.post_reason('unable to find "%s" key' % key)
            return 'fail'
    return 'success'
Esempio n. 2
0
def test_hdf5_9():

    if int(gdal.VersionInfo('VERSION_NUM')) < 1900:
        pytest.skip('would crash')

    ds = gdal.Open('data/vlstr_metadata.h5')
    metadata = ds.GetRasterBand(1).GetMetadata()
    ds = None
    assert not gdaltest.is_file_open(
        'data/vlstr_metadata.h5'), 'file still opened.'

    ref_metadata = {
        'TEST_BANDNAMES': 'SAA',
        'TEST_CODING': '0.6666666667 0.0000000000 TRUE',
        'TEST_FLAGS': '255=noValue',
        'TEST_MAPPING':
        'Geographic Lat/Lon 0.5000000000 0.5000000000 27.3154761905 -5.0833333333 0.0029761905 0.0029761905 WGS84 Degrees',
        'TEST_NOVALUE': '255',
        'TEST_RANGE': '0 255 0 255',
    }

    assert len(metadata) == len(ref_metadata), (
        'incorrect number of metadata: '
        'expected %d, got %d' % (len(ref_metadata), len(metadata)))

    for key in metadata:
        assert key in ref_metadata, ('unexpected metadata key "%s"' % key)

        assert metadata[key] == ref_metadata[key], \
            ('incorrect metadata value for key "%s": '
                                 'expected "%s", got "%s" ' %
                                 (key, ref_metadata[key], metadata[key]))
Esempio n. 3
0
File: hdf5.py Progetto: normanb/gdal
def hdf5_14():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    ds = gdal.Open('data/complex.h5')
    sds_list = ds.GetMetadata('SUBDATASETS')

    if len(sds_list) != 6:
        print(sds_list)
        gdaltest.post_reason('Did not get expected complex subdataset count.')
        return 'fail'

    if sds_list['SUBDATASET_1_NAME'] != 'HDF5:"data/complex.h5"://f16' \
            or sds_list['SUBDATASET_2_NAME'] != 'HDF5:"data/complex.h5"://f32' \
            or sds_list['SUBDATASET_3_NAME'] != 'HDF5:"data/complex.h5"://f64':
        print(sds_list)
        gdaltest.post_reason('did not get expected subdatasets.')
        return 'fail'

    ds = None

    if gdaltest.is_file_open('data/complex.h5'):
        gdaltest.post_reason('file still opened.')
        return 'fail'

    return 'success'
Esempio n. 4
0
def test_hdf5_9():

    if int(gdal.VersionInfo('VERSION_NUM')) < 1900:
        pytest.skip('would crash')

    ds = gdal.Open('data/vlstr_metadata.h5')
    metadata = ds.GetRasterBand(1).GetMetadata()
    ds = None
    assert not gdaltest.is_file_open('data/vlstr_metadata.h5'), 'file still opened.'

    ref_metadata = {
        'TEST_BANDNAMES': 'SAA',
        'TEST_CODING': '0.6666666667 0.0000000000 TRUE',
        'TEST_FLAGS': '255=noValue',
        'TEST_MAPPING': 'Geographic Lat/Lon 0.5000000000 0.5000000000 27.3154761905 -5.0833333333 0.0029761905 0.0029761905 WGS84 Degrees',
        'TEST_NOVALUE': '255',
        'TEST_RANGE': '0 255 0 255',
    }

    assert len(metadata) == len(ref_metadata), ('incorrect number of metadata: '
                             'expected %d, got %d' % (len(ref_metadata),
                                                      len(metadata)))

    for key in metadata:
        assert key in ref_metadata, ('unexpected metadata key "%s"' % key)

        assert metadata[key] == ref_metadata[key], \
            ('incorrect metadata value for key "%s": '
                                 'expected "%s", got "%s" ' %
                                 (key, ref_metadata[key], metadata[key]))
Esempio n. 5
0
def hdf5_7():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    ds = gdal.Open( 'data/metadata.h5' )
    metadata = ds.GetMetadata()
    metadataList = ds.GetMetadata_List()
    ds = None

    if gdaltest.is_file_open('data/metadata.h5'):
        gdaltest.post_reason( 'file still opened.' )
        return 'fail'

    if len(metadata) != len(metadataList):
        gdaltest.post_reason( 'error in metadata dictionary setup' )
        return 'fail'

    metadataList = [item.split('=', 1)[0] for item in metadataList]
    for key in metadataList:
        try:
            metadata.pop(key)
        except KeyError:
            gdaltest.post_reason( 'unable to find "%s" key' % key )
            return 'fail'
    return 'success'
Esempio n. 6
0
def hdf5_11():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    # Try opening the QLK subdataset to check that no error is generated
    gdal.ErrorReset()
    ds = gdal.Open( 'HDF5:"data/CSK_GEC.h5"://S01/QLK' )
    if ds is None or gdal.GetLastErrorMsg() != '':
           gdaltest.post_reason('fail')
           return 'fail'
    ds = None

    ds = gdal.Open( 'HDF5:"data/CSK_GEC.h5"://S01/SBI' )
    got_projection = ds.GetProjection()
    if got_projection.find('PROJCS["Transverse_Mercator",GEOGCS["WGS 84",DATUM["WGS_1984"') != 0:
        print(got_projection)
        gdaltest.post_reason('fail')
        return 'fail'

    got_gt = ds.GetGeoTransform()
    expected_gt = (275592.5, 2.5, 0.0, 4998152.5, 0.0, -2.5)
    for i in range(6):
        if abs(got_gt[i] - expected_gt[i]) > 1e-5:
            print(got_gt)
            gdaltest.post_reason('fail')
            return 'fail'

    ds = None

    if gdaltest.is_file_open('data/CSK_GEC.h5'):
        gdaltest.post_reason( 'file still opened.' )
        return 'fail'

    return 'success'
Esempio n. 7
0
def hdf5_2():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    ds = gdal.Open( 'data/groups.h5' )

    sds_list = ds.GetMetadata('SUBDATASETS')

    if len(sds_list) != 4:
        print(sds_list)
        gdaltest.post_reason( 'Did not get expected subdataset count.' )
        return 'fail'

    if sds_list['SUBDATASET_1_NAME'] != 'HDF5:"data/groups.h5"://MyGroup/Group_A/dset2' \
       or sds_list['SUBDATASET_2_NAME'] != 'HDF5:"data/groups.h5"://MyGroup/dset1':
        print(sds_list)
        gdaltest.post_reason( 'did not get expected subdatasets.' )
        return 'fail'

    ds = None

    if gdaltest.is_file_open('data/groups.h5'):
        gdaltest.post_reason( 'file still opened.' )
        return 'fail'

    return 'success'
Esempio n. 8
0
def hdf5_2():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    ds = gdal.Open('data/groups.h5')

    sds_list = ds.GetMetadata('SUBDATASETS')

    if len(sds_list) != 4:
        print(sds_list)
        gdaltest.post_reason('Did not get expected subdataset count.')
        return 'fail'

    if sds_list['SUBDATASET_1_NAME'] != 'HDF5:"data/groups.h5"://MyGroup/Group_A/dset2' \
       or sds_list['SUBDATASET_2_NAME'] != 'HDF5:"data/groups.h5"://MyGroup/dset1':
        print(sds_list)
        gdaltest.post_reason('did not get expected subdatasets.')
        return 'fail'

    ds = None

    if gdaltest.is_file_open('data/groups.h5'):
        gdaltest.post_reason('file still opened.')
        return 'fail'

    return 'success'
Esempio n. 9
0
def test_hdf5_6():

    shutil.copyfile('data/groups.h5', 'tmp/groups.h5')

    ds = gdal.Open('HDF5:"tmp/groups.h5"://MyGroup/dset1')
    ds.BuildOverviews(overviewlist=[2])
    ds = None

    assert not gdaltest.is_file_open('tmp/groups.h5'), 'file still opened.'

    ds = gdal.Open('HDF5:"tmp/groups.h5"://MyGroup/dset1')
    assert ds.GetRasterBand(
        1).GetOverviewCount() == 1, 'failed to find overview'
    ds = None

    # confirm that it works with a different path. (#3290)

    ds = gdal.Open('HDF5:"data/../tmp/groups.h5"://MyGroup/dset1')
    assert ds.GetRasterBand(1).GetOverviewCount() == 1, \
        'failed to find overview with alternate path'
    ovfile = ds.GetMetadataItem('OVERVIEW_FILE', 'OVERVIEWS')
    assert ovfile[:11] == 'data/../tmp', 'did not get expected OVERVIEW_FILE.'
    ds = None

    gdaltest.clean_tmp()
Esempio n. 10
0
def test_hdf5_3():

    ds = gdal.Open('HDF5:"data/u8be.h5"://TestArray')

    cs = ds.GetRasterBand(1).Checksum()
    assert cs == 135, 'did not get expected checksum'

    ds = None

    assert not gdaltest.is_file_open('data/u8be.h5'), 'file still opened.'
Esempio n. 11
0
def test_hdf5_3():

    ds = gdal.Open('HDF5:"data/u8be.h5"://TestArray')

    cs = ds.GetRasterBand(1).Checksum()
    assert cs == 135, 'did not get expected checksum'

    ds = None

    assert not gdaltest.is_file_open('data/u8be.h5'), 'file still opened.'
Esempio n. 12
0
def test_hdf5_14():

    ds = gdal.Open('data/complex.h5')
    sds_list = ds.GetMetadata('SUBDATASETS')

    assert len(sds_list) == 6, 'Did not get expected complex subdataset count.'

    assert sds_list['SUBDATASET_1_NAME'] == 'HDF5:"data/complex.h5"://f16' and sds_list['SUBDATASET_2_NAME'] == 'HDF5:"data/complex.h5"://f32' and sds_list['SUBDATASET_3_NAME'] == 'HDF5:"data/complex.h5"://f64', \
        'did not get expected subdatasets.'

    ds = None

    assert not gdaltest.is_file_open('data/complex.h5'), 'file still opened.'
Esempio n. 13
0
def test_hdf5_14():

    ds = gdal.Open('data/complex.h5')
    sds_list = ds.GetMetadata('SUBDATASETS')

    assert len(sds_list) == 6, 'Did not get expected complex subdataset count.'

    assert sds_list['SUBDATASET_1_NAME'] == 'HDF5:"data/complex.h5"://f16' and sds_list['SUBDATASET_2_NAME'] == 'HDF5:"data/complex.h5"://f32' and sds_list['SUBDATASET_3_NAME'] == 'HDF5:"data/complex.h5"://f64', \
        'did not get expected subdatasets.'

    ds = None

    assert not gdaltest.is_file_open('data/complex.h5'), 'file still opened.'
Esempio n. 14
0
def test_hdf5_2():
    ds = gdal.Open('data/groups.h5')

    sds_list = ds.GetMetadata('SUBDATASETS')

    assert len(sds_list) == 4, 'Did not get expected subdataset count.'

    assert sds_list['SUBDATASET_1_NAME'] == 'HDF5:"data/groups.h5"://MyGroup/Group_A/dset2' and sds_list['SUBDATASET_2_NAME'] == 'HDF5:"data/groups.h5"://MyGroup/dset1', \
        'did not get expected subdatasets.'

    ds = None

    assert not gdaltest.is_file_open('data/groups.h5'), 'file still opened.'
Esempio n. 15
0
def test_hdf5_2():
    ds = gdal.Open('data/groups.h5')

    sds_list = ds.GetMetadata('SUBDATASETS')

    assert len(sds_list) == 4, 'Did not get expected subdataset count.'

    assert sds_list['SUBDATASET_1_NAME'] == 'HDF5:"data/groups.h5"://MyGroup/Group_A/dset2' and sds_list['SUBDATASET_2_NAME'] == 'HDF5:"data/groups.h5"://MyGroup/dset1', \
        'did not get expected subdatasets.'

    ds = None

    assert not gdaltest.is_file_open('data/groups.h5'), 'file still opened.'
Esempio n. 16
0
def test_hdf5_7():

    ds = gdal.Open('data/metadata.h5')
    metadata = ds.GetMetadata()
    metadataList = ds.GetMetadata_List()
    ds = None

    assert not gdaltest.is_file_open('data/metadata.h5'), 'file still opened.'

    assert len(metadata) == len(metadataList), 'error in metadata dictionary setup'

    metadataList = [item.split('=', 1)[0] for item in metadataList]
    for key in metadataList:
        try:
            metadata.pop(key)
        except KeyError:
            pytest.fail('unable to find "%s" key' % key)
Esempio n. 17
0
def test_hdf5_7():

    ds = gdal.Open('data/metadata.h5')
    metadata = ds.GetMetadata()
    metadataList = ds.GetMetadata_List()
    ds = None

    assert not gdaltest.is_file_open('data/metadata.h5'), 'file still opened.'

    assert len(metadata) == len(metadataList), 'error in metadata dictionary setup'

    metadataList = [item.split('=', 1)[0] for item in metadataList]
    for key in metadataList:
        try:
            metadata.pop(key)
        except KeyError:
            pytest.fail('unable to find "%s" key' % key)
Esempio n. 18
0
def hdf5_9():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    if int(gdal.VersionInfo('VERSION_NUM')) < 1900:
        gdaltest.post_reason('would crash')
        return 'skip'

    ds = gdal.Open('data/vlstr_metadata.h5')
    metadata = ds.GetRasterBand(1).GetMetadata()
    ds = None
    if gdaltest.is_file_open('data/vlstr_metadata.h5'):
        gdaltest.post_reason('file still opened.')
        return 'fail'

    ref_metadata = {
        'TEST_BANDNAMES': 'SAA',
        'TEST_CODING': '0.6666666667 0.0000000000 TRUE',
        'TEST_FLAGS': '255=noValue',
        'TEST_MAPPING':
        'Geographic Lat/Lon 0.5000000000 0.5000000000 27.3154761905 -5.0833333333 0.0029761905 0.0029761905 WGS84 Degrees',
        'TEST_NOVALUE': '255',
        'TEST_RANGE': '0 255 0 255',
    }

    if len(metadata) != len(ref_metadata):
        gdaltest.post_reason('incorrect number of metadata: '
                             'expected %d, got %d' %
                             (len(ref_metadata), len(metadata)))
        return 'fail'

    for key in metadata:
        if key not in ref_metadata:
            gdaltest.post_reason('unexpected metadata key "%s"' % key)
            return 'fail'

        if metadata[key] != ref_metadata[key]:
            gdaltest.post_reason('incorrect metadata value for key "%s": '
                                 'expected "%s", got "%s" ' %
                                 (key, ref_metadata[key], metadata[key]))
            return 'fail'

    return 'success'
Esempio n. 19
0
def test_bag_2():
    if gdaltest.bag_drv is None:
        pytest.skip()

    ds = gdal.Open('data/true_n_nominal.bag')

    cs = ds.GetRasterBand(1).Checksum()
    assert cs == 1072, ('Wrong checksum on band 1, got %d.' % cs)

    cs = ds.GetRasterBand(2).Checksum()
    assert cs == 150, ('Wrong checksum on band 2, got %d.' % cs)

    cs = ds.GetRasterBand(3).Checksum()
    assert cs == 1315, ('Wrong checksum on band 3, got %d.' % cs)

    b1 = ds.GetRasterBand(1)
    assert b1.GetMinimum() == pytest.approx(10,
                                            abs=0.01), 'band 1 minimum wrong.'

    assert b1.GetMaximum() == pytest.approx(19.8,
                                            abs=0.01), 'band 1 maximum wrong.'

    assert b1.GetNoDataValue() == pytest.approx(
        1000000.0, abs=0.1), 'band 1 nodata wrong.'

    b2 = ds.GetRasterBand(2)
    assert b2.GetNoDataValue() == pytest.approx(
        1000000.0, abs=0.1), 'band 2 nodata wrong.'

    b3 = ds.GetRasterBand(3)
    assert b3.GetNoDataValue() == pytest.approx(
        0.0, abs=0.1), 'band 3 nodata wrong.'

    # It would be nice to test srs and geotransform but they are
    # pretty much worthless on this dataset.

    # Test the xml:BAG metadata domain
    xmlBag = ds.GetMetadata('xml:BAG')[0]
    assert xmlBag.startswith('<?xml'), 'did not get xml:BAG metadata'

    ds = None

    assert not gdaltest.is_file_open(
        'data/true_n_nominal.bag'), 'file still opened.'
Esempio n. 20
0
def hdf5_9():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    if int(gdal.VersionInfo('VERSION_NUM')) < 1900:
        gdaltest.post_reason('would crash')
        return 'skip'

    ds = gdal.Open( 'data/vlstr_metadata.h5' )
    metadata = ds.GetRasterBand(1).GetMetadata()
    ds = None
    if gdaltest.is_file_open('data/vlstr_metadata.h5'):
        gdaltest.post_reason( 'file still opened.' )
        return 'fail'

    ref_metadata = {
        'TEST_BANDNAMES': 'SAA',
        'TEST_CODING': '0.6666666667 0.0000000000 TRUE',
        'TEST_FLAGS': '255=noValue',
        'TEST_MAPPING': 'Geographic Lat/Lon 0.5000000000 0.5000000000 27.3154761905 -5.0833333333 0.0029761905 0.0029761905 WGS84 Degrees',
        'TEST_NOVALUE': '255',
        'TEST_RANGE': '0 255 0 255',
    }

    if len(metadata) != len(ref_metadata):
        gdaltest.post_reason( 'incorrect number of metadata: '
                              'expected %d, got %d' % (len(ref_metadata),
                                                       len(metadata)) )
        return 'fail'

    for key in metadata:
        if key not in ref_metadata:
            gdaltest.post_reason( 'unexpected metadata key "%s"' % key )
            return 'fail'

        if metadata[key] != ref_metadata[key]:
            gdaltest.post_reason( 'incorrect metadata value for key "%s": '
                                  'expected "%s", got "%s" '%
                                    (key, ref_metadata[key], metadata[key]) )
            return 'fail'

    return 'success'
Esempio n. 21
0
def hdf5_3():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    ds = gdal.Open( 'HDF5:"data/u8be.h5"://TestArray' )

    cs = ds.GetRasterBand(1).Checksum()
    if cs != 135:
        gdaltest.post_reason( 'did not get expected checksum' )
        return 'fail'

    ds = None

    if gdaltest.is_file_open('data/u8be.h5'):
        gdaltest.post_reason( 'file still opened.' )
        return 'fail'

    return 'success'
Esempio n. 22
0
def hdf5_3():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    ds = gdal.Open('HDF5:"data/u8be.h5"://TestArray')

    cs = ds.GetRasterBand(1).Checksum()
    if cs != 135:
        gdaltest.post_reason('did not get expected checksum')
        return 'fail'

    ds = None

    if gdaltest.is_file_open('data/u8be.h5'):
        gdaltest.post_reason('file still opened.')
        return 'fail'

    return 'success'
Esempio n. 23
0
def test_hdf5_10():

    # Try opening the QLK subdataset to check that no error is generated
    gdal.ErrorReset()
    ds = gdal.Open('HDF5:"data/CSK_DGM.h5"://S01/QLK')
    assert ds is not None and gdal.GetLastErrorMsg() == ''
    ds = None

    ds = gdal.Open('HDF5:"data/CSK_DGM.h5"://S01/SBI')
    got_gcpprojection = ds.GetGCPProjection()
    assert got_gcpprojection.startswith('GEOGCS["WGS 84",DATUM["WGS_1984"')

    got_gcps = ds.GetGCPs()
    assert len(got_gcps) == 4

    assert (abs(got_gcps[0].GCPPixel - 0) <= 1e-5 and abs(got_gcps[0].GCPLine - 0) <= 1e-5 and \
       abs(got_gcps[0].GCPX - 12.2395902509238) <= 1e-5 and abs(got_gcps[0].GCPY - 44.7280047434954) <= 1e-5)

    ds = None
    assert not gdaltest.is_file_open('data/CSK_DGM.h5'), 'file still opened.'
Esempio n. 24
0
def test_hdf5_11():

    # Try opening the QLK subdataset to check that no error is generated
    gdal.ErrorReset()
    ds = gdal.Open('HDF5:"data/CSK_GEC.h5"://S01/QLK')
    assert ds is not None and gdal.GetLastErrorMsg() == ''
    ds = None

    ds = gdal.Open('HDF5:"data/CSK_GEC.h5"://S01/SBI')
    got_projection = ds.GetProjection()
    assert got_projection.startswith('PROJCS["Transverse_Mercator",GEOGCS["WGS 84",DATUM["WGS_1984"')

    got_gt = ds.GetGeoTransform()
    expected_gt = (275592.5, 2.5, 0.0, 4998152.5, 0.0, -2.5)
    for i in range(6):
        assert abs(got_gt[i] - expected_gt[i]) <= 1e-5

    ds = None

    assert not gdaltest.is_file_open('data/CSK_GEC.h5'), 'file still opened.'
Esempio n. 25
0
def test_hdf5_11():

    # Try opening the QLK subdataset to check that no error is generated
    gdal.ErrorReset()
    ds = gdal.Open('HDF5:"data/CSK_GEC.h5"://S01/QLK')
    assert ds is not None and gdal.GetLastErrorMsg() == ''
    ds = None

    ds = gdal.Open('HDF5:"data/CSK_GEC.h5"://S01/SBI')
    got_projection = ds.GetProjection()
    assert got_projection.startswith('PROJCS["Transverse_Mercator",GEOGCS["WGS 84",DATUM["WGS_1984"')

    got_gt = ds.GetGeoTransform()
    expected_gt = (275592.5, 2.5, 0.0, 4998152.5, 0.0, -2.5)
    for i in range(6):
        assert abs(got_gt[i] - expected_gt[i]) <= 1e-5

    ds = None

    assert not gdaltest.is_file_open('data/CSK_GEC.h5'), 'file still opened.'
Esempio n. 26
0
def test_hdf5_10():

    # Try opening the QLK subdataset to check that no error is generated
    gdal.ErrorReset()
    ds = gdal.Open('HDF5:"data/CSK_DGM.h5"://S01/QLK')
    assert ds is not None and gdal.GetLastErrorMsg() == ''
    ds = None

    ds = gdal.Open('HDF5:"data/CSK_DGM.h5"://S01/SBI')
    got_gcpprojection = ds.GetGCPProjection()
    assert got_gcpprojection.startswith('GEOGCS["WGS 84",DATUM["WGS_1984"')

    got_gcps = ds.GetGCPs()
    assert len(got_gcps) == 4

    assert (abs(got_gcps[0].GCPPixel - 0) <= 1e-5 and abs(got_gcps[0].GCPLine - 0) <= 1e-5 and \
       abs(got_gcps[0].GCPX - 12.2395902509238) <= 1e-5 and abs(got_gcps[0].GCPY - 44.7280047434954) <= 1e-5)

    ds = None
    assert not gdaltest.is_file_open('data/CSK_DGM.h5'), 'file still opened.'
Esempio n. 27
0
File: bag.py Progetto: OSGeo/gdal
def test_bag_2():

    if gdaltest.bag_drv is None:
        pytest.skip()

    ds = gdal.Open('data/true_n_nominal.bag')

    cs = ds.GetRasterBand(1).Checksum()
    assert cs == 1072, ('Wrong checksum on band 1, got %d.' % cs)

    cs = ds.GetRasterBand(2).Checksum()
    assert cs == 150, ('Wrong checksum on band 2, got %d.' % cs)

    cs = ds.GetRasterBand(3).Checksum()
    assert cs == 1315, ('Wrong checksum on band 3, got %d.' % cs)

    b1 = ds.GetRasterBand(1)
    assert abs(b1.GetMinimum() - 10) <= 0.01, 'band 1 minimum wrong.'

    assert abs(b1.GetMaximum() - 19.8) <= 0.01, 'band 1 maximum wrong.'

    assert abs(b1.GetNoDataValue() - 1000000.0) <= 0.1, 'band 1 nodata wrong.'

    b2 = ds.GetRasterBand(2)
    assert abs(b2.GetNoDataValue() - 1000000.0) <= 0.1, 'band 2 nodata wrong.'

    b3 = ds.GetRasterBand(3)
    assert abs(b3.GetNoDataValue() - 0.0) <= 0.1, 'band 3 nodata wrong.'

    # It would be nice to test srs and geotransform but they are
    # pretty much worthless on this dataset.

    # Test the xml:BAG metadata domain
    xmlBag = ds.GetMetadata('xml:BAG')[0]
    assert xmlBag.startswith('<?xml'), 'did not get xml:BAG metadata'

    ds = None

    assert not gdaltest.is_file_open('data/true_n_nominal.bag'), 'file still opened.'
Esempio n. 28
0
def hdf5_6():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    shutil.copyfile( 'data/groups.h5', 'tmp/groups.h5' )

    ds = gdal.Open( 'HDF5:"tmp/groups.h5"://MyGroup/dset1' )
    ds.BuildOverviews( overviewlist = [2] )
    ds = None

    if gdaltest.is_file_open('tmp/groups.h5'):
        gdaltest.post_reason( 'file still opened.' )
        return 'fail'

    ds = gdal.Open( 'HDF5:"tmp/groups.h5"://MyGroup/dset1' )
    if ds.GetRasterBand(1).GetOverviewCount() != 1:
        gdaltest.post_reason( 'failed to find overview' )
        return 'fail'
    ds = None

    # confirm that it works with a different path. (#3290)

    ds = gdal.Open( 'HDF5:"data/../tmp/groups.h5"://MyGroup/dset1' )
    if ds.GetRasterBand(1).GetOverviewCount() != 1:
        gdaltest.post_reason( 'failed to find overview with alternate path' )
        return 'fail'
    ovfile = ds.GetMetadataItem('OVERVIEW_FILE','OVERVIEWS')
    if ovfile[:11] != 'data/../tmp':
        print(ovfile)
        gdaltest.post_reason( 'did not get expected OVERVIEW_FILE.' )
        return 'fail'
    ds = None


    gdaltest.clean_tmp()

    return 'success'
Esempio n. 29
0
def hdf5_11():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    # Try opening the QLK subdataset to check that no error is generated
    gdal.ErrorReset()
    ds = gdal.Open('HDF5:"data/CSK_GEC.h5"://S01/QLK')
    if ds is None or gdal.GetLastErrorMsg() != '':
        gdaltest.post_reason('fail')
        return 'fail'
    ds = None

    ds = gdal.Open('HDF5:"data/CSK_GEC.h5"://S01/SBI')
    got_projection = ds.GetProjection()
    if got_projection.find(
            'PROJCS["Transverse_Mercator",GEOGCS["WGS 84",DATUM["WGS_1984"'
    ) != 0:
        print(got_projection)
        gdaltest.post_reason('fail')
        return 'fail'

    got_gt = ds.GetGeoTransform()
    expected_gt = (275592.5, 2.5, 0.0, 4998152.5, 0.0, -2.5)
    for i in range(6):
        if abs(got_gt[i] - expected_gt[i]) > 1e-5:
            print(got_gt)
            gdaltest.post_reason('fail')
            return 'fail'

    ds = None

    if gdaltest.is_file_open('data/CSK_GEC.h5'):
        gdaltest.post_reason('file still opened.')
        return 'fail'

    return 'success'
Esempio n. 30
0
def hdf5_10():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    # Try opening the QLK subdataset to check that no error is generated
    gdal.ErrorReset()
    ds = gdal.Open('HDF5:"data/CSK_DGM.h5"://S01/QLK')
    if ds is None or gdal.GetLastErrorMsg() != '':
        gdaltest.post_reason('fail')
        return 'fail'
    ds = None

    ds = gdal.Open('HDF5:"data/CSK_DGM.h5"://S01/SBI')
    got_gcpprojection = ds.GetGCPProjection()
    expected_gcpprojection = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]]'
    if got_gcpprojection != expected_gcpprojection:
        print(got_gcpprojection)
        gdaltest.post_reason('fail')
        return 'fail'

    got_gcps = ds.GetGCPs()
    if len(got_gcps) != 4:
        gdaltest.post_reason('fail')
        return 'fail'

    if abs(got_gcps[0].GCPPixel - 0) > 1e-5 or abs(got_gcps[0].GCPLine - 0) > 1e-5 or \
       abs(got_gcps[0].GCPX - 12.2395902509238) > 1e-5 or abs(got_gcps[0].GCPY - 44.7280047434954) > 1e-5:
        gdaltest.post_reason('fail')
        return 'fail'

    ds = None
    if gdaltest.is_file_open('data/CSK_DGM.h5'):
        gdaltest.post_reason('file still opened.')
        return 'fail'

    return 'success'
Esempio n. 31
0
def hdf5_6():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    shutil.copyfile('data/groups.h5', 'tmp/groups.h5')

    ds = gdal.Open('HDF5:"tmp/groups.h5"://MyGroup/dset1')
    ds.BuildOverviews(overviewlist=[2])
    ds = None

    if gdaltest.is_file_open('tmp/groups.h5'):
        gdaltest.post_reason('file still opened.')
        return 'fail'

    ds = gdal.Open('HDF5:"tmp/groups.h5"://MyGroup/dset1')
    if ds.GetRasterBand(1).GetOverviewCount() != 1:
        gdaltest.post_reason('failed to find overview')
        return 'fail'
    ds = None

    # confirm that it works with a different path. (#3290)

    ds = gdal.Open('HDF5:"data/../tmp/groups.h5"://MyGroup/dset1')
    if ds.GetRasterBand(1).GetOverviewCount() != 1:
        gdaltest.post_reason('failed to find overview with alternate path')
        return 'fail'
    ovfile = ds.GetMetadataItem('OVERVIEW_FILE', 'OVERVIEWS')
    if ovfile[:11] != 'data/../tmp':
        print(ovfile)
        gdaltest.post_reason('did not get expected OVERVIEW_FILE.')
        return 'fail'
    ds = None

    gdaltest.clean_tmp()

    return 'success'
Esempio n. 32
0
def hdf5_10():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    # Try opening the QLK subdataset to check that no error is generated
    gdal.ErrorReset()
    ds = gdal.Open( 'HDF5:"data/CSK_DGM.h5"://S01/QLK' )
    if ds is None or gdal.GetLastErrorMsg() != '':
           gdaltest.post_reason('fail')
           return 'fail'
    ds = None

    ds = gdal.Open( 'HDF5:"data/CSK_DGM.h5"://S01/SBI' )
    got_gcpprojection = ds.GetGCPProjection()
    expected_gcpprojection = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]]'
    if got_gcpprojection != expected_gcpprojection:
        print(got_gcpprojection)
        gdaltest.post_reason('fail')
        return 'fail'

    got_gcps = ds.GetGCPs()
    if len(got_gcps) != 4:
           gdaltest.post_reason('fail')
           return 'fail'

    if abs(got_gcps[0].GCPPixel - 0) > 1e-5 or abs(got_gcps[0].GCPLine - 0) > 1e-5 or \
       abs(got_gcps[0].GCPX - 12.2395902509238) > 1e-5 or abs(got_gcps[0].GCPY - 44.7280047434954) > 1e-5:
           gdaltest.post_reason('fail')
           return 'fail'

    ds = None
    if gdaltest.is_file_open('data/CSK_DGM.h5'):
        gdaltest.post_reason( 'file still opened.' )
        return 'fail'

    return 'success'
Esempio n. 33
0
def hdf5_11():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    # Try opening the QLK subdataset to check that no error is generated
    gdal.ErrorReset()
    ds = gdal.Open( 'HDF5:"data/CSK_GEC.h5"://S01/QLK' )
    if ds is None or gdal.GetLastErrorMsg() != '':
           gdaltest.post_reason('fail')
           return 'fail'
    ds = None

    ds = gdal.Open( 'HDF5:"data/CSK_GEC.h5"://S01/SBI' )
    got_projection = ds.GetProjection()
    expected_projection = 'PROJCS["Transverse_Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",15],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0]]'
    if got_projection != expected_projection:
        print(got_projection)
        gdaltest.post_reason('fail')
        return 'fail'

    got_gt = ds.GetGeoTransform()
    expected_gt = (275592.5, 2.5, 0.0, 4998152.5, 0.0, -2.5)
    for i in range(6):
        if abs(got_gt[i] - expected_gt[i]) > 1e-5:
            print(got_gt)
            gdaltest.post_reason('fail')
            return 'fail'
            
    ds = None

    if gdaltest.is_file_open('data/CSK_GEC.h5'):
        gdaltest.post_reason( 'file still opened.' )
        return 'fail'

    return 'success'
Esempio n. 34
0
def hdf5_11():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    # Try opening the QLK subdataset to check that no error is generated
    gdal.ErrorReset()
    ds = gdal.Open('HDF5:"data/CSK_GEC.h5"://S01/QLK')
    if ds is None or gdal.GetLastErrorMsg() != '':
        gdaltest.post_reason('fail')
        return 'fail'
    ds = None

    ds = gdal.Open('HDF5:"data/CSK_GEC.h5"://S01/SBI')
    got_projection = ds.GetProjection()
    expected_projection = 'PROJCS["Transverse_Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",15],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0]]'
    if got_projection != expected_projection:
        print(got_projection)
        gdaltest.post_reason('fail')
        return 'fail'

    got_gt = ds.GetGeoTransform()
    expected_gt = (275592.5, 2.5, 0.0, 4998152.5, 0.0, -2.5)
    for i in range(6):
        if abs(got_gt[i] - expected_gt[i]) > 1e-5:
            print(got_gt)
            gdaltest.post_reason('fail')
            return 'fail'

    ds = None

    if gdaltest.is_file_open('data/CSK_GEC.h5'):
        gdaltest.post_reason('file still opened.')
        return 'fail'

    return 'success'
Esempio n. 35
0
def test_hdf5_6():

    shutil.copyfile('data/groups.h5', 'tmp/groups.h5')

    ds = gdal.Open('HDF5:"tmp/groups.h5"://MyGroup/dset1')
    ds.BuildOverviews(overviewlist=[2])
    ds = None

    assert not gdaltest.is_file_open('tmp/groups.h5'), 'file still opened.'

    ds = gdal.Open('HDF5:"tmp/groups.h5"://MyGroup/dset1')
    assert ds.GetRasterBand(1).GetOverviewCount() == 1, 'failed to find overview'
    ds = None

    # confirm that it works with a different path. (#3290)

    ds = gdal.Open('HDF5:"data/../tmp/groups.h5"://MyGroup/dset1')
    assert ds.GetRasterBand(1).GetOverviewCount() == 1, \
        'failed to find overview with alternate path'
    ovfile = ds.GetMetadataItem('OVERVIEW_FILE', 'OVERVIEWS')
    assert ovfile[:11] == 'data/../tmp', 'did not get expected OVERVIEW_FILE.'
    ds = None

    gdaltest.clean_tmp()
Esempio n. 36
0
def hdf5_10():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    # Try opening the QLK subdataset to check that no error is generated
    gdal.ErrorReset()
    ds = gdal.Open( 'HDF5:"data/CSK_DGM.h5"://S01/QLK' )
    if ds is None or gdal.GetLastErrorMsg() != '':
           gdaltest.post_reason('fail')
           return 'fail'
    ds = None

    ds = gdal.Open( 'HDF5:"data/CSK_DGM.h5"://S01/SBI' )
    got_gcpprojection = ds.GetGCPProjection()
    if got_gcpprojection.find('GEOGCS["WGS 84",DATUM["WGS_1984"') != 0:
        print(got_gcpprojection)
        gdaltest.post_reason('fail')
        return 'fail'

    got_gcps = ds.GetGCPs()
    if len(got_gcps) != 4:
           gdaltest.post_reason('fail')
           return 'fail'

    if abs(got_gcps[0].GCPPixel - 0) > 1e-5 or abs(got_gcps[0].GCPLine - 0) > 1e-5 or \
       abs(got_gcps[0].GCPX - 12.2395902509238) > 1e-5 or abs(got_gcps[0].GCPY - 44.7280047434954) > 1e-5:
           gdaltest.post_reason('fail')
           return 'fail'

    ds = None
    if gdaltest.is_file_open('data/CSK_DGM.h5'):
        gdaltest.post_reason( 'file still opened.' )
        return 'fail'

    return 'success'
Esempio n. 37
0
def hdf5_10():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    # Try opening the QLK subdataset to check that no error is generated
    gdal.ErrorReset()
    ds = gdal.Open('HDF5:"data/CSK_DGM.h5"://S01/QLK')
    if ds is None or gdal.GetLastErrorMsg() != '':
        gdaltest.post_reason('fail')
        return 'fail'
    ds = None

    ds = gdal.Open('HDF5:"data/CSK_DGM.h5"://S01/SBI')
    got_gcpprojection = ds.GetGCPProjection()
    if got_gcpprojection.find('GEOGCS["WGS 84",DATUM["WGS_1984"') != 0:
        print(got_gcpprojection)
        gdaltest.post_reason('fail')
        return 'fail'

    got_gcps = ds.GetGCPs()
    if len(got_gcps) != 4:
        gdaltest.post_reason('fail')
        return 'fail'

    if abs(got_gcps[0].GCPPixel - 0) > 1e-5 or abs(got_gcps[0].GCPLine - 0) > 1e-5 or \
       abs(got_gcps[0].GCPX - 12.2395902509238) > 1e-5 or abs(got_gcps[0].GCPY - 44.7280047434954) > 1e-5:
        gdaltest.post_reason('fail')
        return 'fail'

    ds = None
    if gdaltest.is_file_open('data/CSK_DGM.h5'):
        gdaltest.post_reason('file still opened.')
        return 'fail'

    return 'success'
Esempio n. 38
0
def bag_2():

    if gdaltest.bag_drv is None:
        return 'skip'

    ds = gdal.Open( 'data/true_n_nominal.bag' )

    cs = ds.GetRasterBand(1).Checksum()
    if cs != 1072:
        gdaltest.post_reason( 'Wrong checksum on band 1, got %d.' % cs )
        return 'fail'
    
    cs = ds.GetRasterBand(2).Checksum()
    if cs != 150:
        gdaltest.post_reason( 'Wrong checksum on band 2, got %d.' % cs )
        return 'fail'
    
    cs = ds.GetRasterBand(3).Checksum()
    if cs != 1315:
        gdaltest.post_reason( 'Wrong checksum on band 3, got %d.' % cs )
        return 'fail'

    b1 = ds.GetRasterBand(1)
    if abs(b1.GetMinimum()-10) > 0.01:
        gdaltest.post_reason( 'band 1 minimum wrong.' )
        return 'fail'
    
    if abs(b1.GetMaximum()-19.8) > 0.01:
        gdaltest.post_reason( 'band 1 maximum wrong.' )
        return 'fail'
    
    if abs(b1.GetNoDataValue()-1000000.0) > 0.1:
        gdaltest.post_reason( 'band 1 nodata wrong.' )
        return 'fail'

    b2 = ds.GetRasterBand(2)
    if abs(b2.GetNoDataValue()-1000000.0) > 0.1:
        gdaltest.post_reason( 'band 2 nodata wrong.' )
        return 'fail'

    b3 = ds.GetRasterBand(3)
    if abs(b3.GetNoDataValue()-1000000.0) > 0.1:
        gdaltest.post_reason( 'band 3 nodata wrong.' )
        return 'fail'
    
    # It would be nice to test srs and geotransform but they are
    # pretty much worthless on this dataset.


    # Test the xml:BAG metadata domain
    xmlBag = ds.GetMetadata('xml:BAG')[0]
    if xmlBag.find('<?xml') != 0:
        gdaltest.post_reason( 'did not get xml:BAG metadata' )
        print(xmlBag)
        return 'fail'

    ds = None

    if gdaltest.is_file_open('data/true_n_nominal.bag'):
        gdaltest.post_reason( 'file still opened.' )
        return 'fail'

    return 'success'
Esempio n. 39
0
def bag_2():

    if gdaltest.bag_drv is None:
        return 'skip'

    ds = gdal.Open('data/true_n_nominal.bag')

    cs = ds.GetRasterBand(1).Checksum()
    if cs != 1072:
        gdaltest.post_reason('Wrong checksum on band 1, got %d.' % cs)
        return 'fail'

    cs = ds.GetRasterBand(2).Checksum()
    if cs != 150:
        gdaltest.post_reason('Wrong checksum on band 2, got %d.' % cs)
        return 'fail'

    cs = ds.GetRasterBand(3).Checksum()
    if cs != 1315:
        gdaltest.post_reason('Wrong checksum on band 3, got %d.' % cs)
        return 'fail'

    b1 = ds.GetRasterBand(1)
    if abs(b1.GetMinimum() - 10) > 0.01:
        gdaltest.post_reason('band 1 minimum wrong.')
        return 'fail'

    if abs(b1.GetMaximum() - 19.8) > 0.01:
        gdaltest.post_reason('band 1 maximum wrong.')
        return 'fail'

    if abs(b1.GetNoDataValue() - 1000000.0) > 0.1:
        gdaltest.post_reason('band 1 nodata wrong.')
        return 'fail'

    b2 = ds.GetRasterBand(2)
    if abs(b2.GetNoDataValue() - 1000000.0) > 0.1:
        gdaltest.post_reason('band 2 nodata wrong.')
        return 'fail'

    b3 = ds.GetRasterBand(3)
    if abs(b3.GetNoDataValue() - 1000000.0) > 0.1:
        gdaltest.post_reason('band 3 nodata wrong.')
        return 'fail'

    # It would be nice to test srs and geotransform but they are
    # pretty much worthless on this dataset.

    # Test the xml:BAG metadata domain
    xmlBag = ds.GetMetadata('xml:BAG')[0]
    if xmlBag.find('<?xml') != 0:
        gdaltest.post_reason('did not get xml:BAG metadata')
        print(xmlBag)
        return 'fail'

    ds = None

    if gdaltest.is_file_open('data/true_n_nominal.bag'):
        gdaltest.post_reason('file still opened.')
        return 'fail'

    return 'success'