Esempio n. 1
0
def jpeg2000_online_3():

    if gdaltest.jpeg2000_drv is None:
        return 'skip'

    if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne1.j2k', 'Bretagne1.j2k'):
        return 'skip'
    if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne1.bmp', 'Bretagne1.bmp'):
        return 'skip'

    # Checksum = 14443 on my PC
    tst = gdaltest.GDALTest('JPEG2000', 'tmp/cache/Bretagne1.j2k', 1, None, filename_absolute=1)

    if tst.testOpen() != 'success':
        return 'fail'

    ds = gdal.Open('tmp/cache/Bretagne1.j2k')
    ds_ref = gdal.Open('tmp/cache/Bretagne1.bmp')
    maxdiff = gdaltest.compare_ds(ds, ds_ref)
    print(ds.GetRasterBand(1).Checksum())
    print(ds_ref.GetRasterBand(1).Checksum())

    ds = None
    ds_ref = None

    # Difference between the image before and after compression
    if maxdiff > 17:
        gdaltest.post_reason('Image too different from reference')
        return 'fail'

    return 'success'
Esempio n. 2
0
File: ecw.py Progetto: Joe-xXx/gdal
def ecw_online_4():

    if gdaltest.jp2ecw_drv is None:
        return "skip"

    if not gdaltest.download_file("http://www.openjpeg.org/samples/Bretagne2.j2k", "Bretagne2.j2k"):
        return "skip"
    if not gdaltest.download_file("http://www.openjpeg.org/samples/Bretagne2.bmp", "Bretagne2.bmp"):
        return "skip"

    # Checksum = 53054 on my PC
    tst = gdaltest.GDALTest("JP2ECW", "tmp/cache/Bretagne2.j2k", 1, None, filename_absolute=1)

    if tst.testOpen() != "success":
        return "fail"

    ds = gdal.Open("tmp/cache/Bretagne2.j2k")
    ds_ref = gdal.Open("tmp/cache/Bretagne2.bmp")
    maxdiff = gdaltest.compare_ds(ds, ds_ref, width=256, height=256)
    #    print(ds.GetRasterBand(1).Checksum())
    #    print(ds_ref.GetRasterBand(1).Checksum())

    ds = None
    ds_ref = None

    # Difference between the image before and after compression
    if maxdiff > 1:
        gdaltest.post_reason("Image too different from reference")
        return "fail"

    return "success"
Esempio n. 3
0
File: ecw.py Progetto: Joe-xXx/gdal
def ecw_online_3():
    if gdaltest.jp2ecw_drv is None:
        return "skip"

    if gdaltest.ecw_drv.major_version > 3:
        gdaltest.post_reason("4.x SDK gets unreliable results for jp2")
        return "skip"

    if not gdaltest.download_file("http://www.openjpeg.org/samples/Bretagne1.j2k", "Bretagne1.j2k"):
        return "skip"
    if not gdaltest.download_file("http://www.openjpeg.org/samples/Bretagne1.bmp", "Bretagne1.bmp"):
        return "skip"

    # checksum = 16481 on my PC
    tst = gdaltest.GDALTest("JP2ECW", "tmp/cache/Bretagne1.j2k", 1, None, filename_absolute=1)

    if tst.testOpen() != "success":
        return "fail"

    ds = gdal.Open("tmp/cache/Bretagne1.j2k")
    ds_ref = gdal.Open("tmp/cache/Bretagne1.bmp")
    maxdiff = gdaltest.compare_ds(ds, ds_ref)
    print(ds.GetRasterBand(1).Checksum())
    print(ds_ref.GetRasterBand(1).Checksum())

    ds = None
    ds_ref = None

    # Difference between the image before and after compression
    if maxdiff > 16:
        gdaltest.post_reason("Image too different from reference")
        return "fail"

    return "success"
Esempio n. 4
0
def validate_xml(filename):

    if ogr.GetDriverByName('GMLAS') is None:
        return 'skip'

    if not gdaltest.download_file('https://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1800.xsd',
                                  'pds.nasa.gov_pds4_pds_v1_PDS4_PDS_1800.xsd',
                                  force_download=True):
        return 'skip'

    if not gdaltest.download_file('https://pds.nasa.gov/pds4/disp/v1/PDS4_DISP_1800.xsd',
                                  'pds.nasa.gov_pds4_disp_v1_PDS4_DISP_1800.xsd',
                                  force_download=True):
        return 'skip'

    if not gdaltest.download_file('https://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1700.xsd',
                                  'pds.nasa.gov_pds4_pds_v1_PDS4_PDS_1700.xsd',
                                  force_download=True):
        return 'skip'

    if not gdaltest.download_file('https://pds.nasa.gov/pds4/cart/v1/PDS4_CART_1700.xsd',
                                  'pds.nasa.gov_pds4_cart_v1_PDS4_CART_1700.xsd',
                                  force_download=True):
        return 'skip'

    ds = gdal.OpenEx('GMLAS:' + filename, open_options=[
        'VALIDATE=YES',
        'FAIL_IF_VALIDATION_ERROR=YES',
        'CONFIG_FILE=<Configuration><AllowRemoteSchemaDownload>false</AllowRemoteSchemaDownload><SchemaCache><Directory>tmp/cache</Directory></SchemaCache></Configuration>'])
    if ds is None:
        return 'fail'
    return 'success'
Esempio n. 5
0
File: ecw.py Progetto: bpass/gdal
def ecw_online_3():
    if gdaltest.jp2ecw_drv is None:
        return 'skip'

    if gdaltest.ecw_drv.major_version > 3:
        gdaltest.post_reason( '4.x SDK gets unreliable results for jp2')
        return 'skip'

    if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne1.j2k', 'Bretagne1.j2k'):
        return 'skip'
    if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne1.bmp', 'Bretagne1.bmp'):
        return 'skip'

    # checksum = 16481 on my PC
    tst = gdaltest.GDALTest( 'JP2ECW', 'tmp/cache/Bretagne1.j2k', 1, None, filename_absolute = 1 )

    if tst.testOpen() != 'success':
        return 'fail'

    ds = gdal.Open('tmp/cache/Bretagne1.j2k')
    ds_ref = gdal.Open('tmp/cache/Bretagne1.bmp')
    maxdiff = gdaltest.compare_ds(ds, ds_ref)
    print(ds.GetRasterBand(1).Checksum())
    print(ds_ref.GetRasterBand(1).Checksum())

    ds = None
    ds_ref = None

    # Difference between the image before and after compression
    if maxdiff > 16:
        gdaltest.post_reason('Image too different from reference')
        return 'fail'

    return 'success'
Esempio n. 6
0
def test_jpeg2000_online_3():

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

    if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne1.j2k', 'Bretagne1.j2k'):
        pytest.skip()
    if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne1.bmp', 'Bretagne1.bmp'):
        pytest.skip()

    # Checksum = 14443 on my PC
    tst = gdaltest.GDALTest('JPEG2000', 'tmp/cache/Bretagne1.j2k', 1, None, filename_absolute=1)

    tst.testOpen()

    ds = gdal.Open('tmp/cache/Bretagne1.j2k')
    ds_ref = gdal.Open('tmp/cache/Bretagne1.bmp')
    maxdiff = gdaltest.compare_ds(ds, ds_ref)
    print(ds.GetRasterBand(1).Checksum())
    print(ds_ref.GetRasterBand(1).Checksum())

    ds = None
    ds_ref = None

    # Difference between the image before and after compression
    assert maxdiff <= 17, 'Image too different from reference'
Esempio n. 7
0
def mrsid_online_4():

    if gdaltest.jp2mrsid_drv is None:
        return 'skip'

    if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne2.j2k', 'Bretagne2.j2k'):
        return 'skip'
    if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne2.bmp', 'Bretagne2.bmp'):
        return 'skip'

    # Checksum = 53186 on my PC
    tst = gdaltest.GDALTest('JP2MrSID', 'tmp/cache/Bretagne2.j2k', 1, None, filename_absolute=1)

    if tst.testOpen() != 'success':
        return 'fail'

    ds = gdal.Open('tmp/cache/Bretagne2.j2k')
    ds_ref = gdal.Open('tmp/cache/Bretagne2.bmp')
    maxdiff = gdaltest.compare_ds(ds, ds_ref, width=256, height=256)

    ds = None
    ds_ref = None

    # Difference between the image before and after compression
    if maxdiff > 1:
        print(ds.GetRasterBand(1).Checksum())
        print(ds_ref.GetRasterBand(1).Checksum())
        gdaltest.post_reason('Image too different from reference')
        return 'fail'

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

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

    if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne1.j2k', 'Bretagne1.j2k'):
        pytest.skip()
    if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne1.bmp', 'Bretagne1.bmp'):
        pytest.skip()

    # checksum = 14443 on my PC
    tst = gdaltest.GDALTest('JP2MrSID', 'tmp/cache/Bretagne1.j2k', 1, None, filename_absolute=1)

    tst.testOpen()

    ds = gdal.Open('tmp/cache/Bretagne1.j2k')
    ds_ref = gdal.Open('tmp/cache/Bretagne1.bmp')
    maxdiff = gdaltest.compare_ds(ds, ds_ref, verbose=0)

    ds = None
    ds_ref = None

    # Difference between the image before and after compression
    if maxdiff > 17:
        print(ds.GetRasterBand(1).Checksum())
        print(ds_ref.GetRasterBand(1).Checksum())

        gdaltest.compare_ds(ds, ds_ref, verbose=1)
        pytest.fail('Image too different from reference')
Esempio n. 9
0
def jpeg2000_online_4():

    if gdaltest.jpeg2000_drv is None:
        return 'skip'

    if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne2.j2k', 'Bretagne2.j2k'):
        return 'skip'
    if not gdaltest.download_file('http://www.openjpeg.org/samples/Bretagne2.bmp', 'Bretagne2.bmp'):
        return 'skip'

    tst = gdaltest.GDALTest('JPEG2000', 'tmp/cache/Bretagne2.j2k', 1, None, filename_absolute=1)

    # Jasper cannot handle this image
    # Actually, a patched Jasper can ;-)
    if tst.testOpen() != 'success':
        gdaltest.post_reason('Expected failure: Jasper cannot handle this image yet')
        return 'expected_fail'

    ds = gdal.Open('tmp/cache/Bretagne2.j2k')
    ds_ref = gdal.Open('tmp/cache/Bretagne2.bmp')
    maxdiff = gdaltest.compare_ds(ds, ds_ref)
    print(ds.GetRasterBand(1).Checksum())
    print(ds_ref.GetRasterBand(1).Checksum())

    ds = None
    ds_ref = None

    # Difference between the image before and after compression
    if maxdiff > 17:
        gdaltest.post_reason('Image too different from reference')
        return 'fail'

    return 'success'
Esempio n. 10
0
def download_ogc_schemas(ogc_schemas_url = 'http://schemas.opengis.net/SCHEMAS_OPENGIS_NET.zip', \
                         xlink_xsd_url = 'http://www.w3.org/1999/xlink.xsd', \
                         xml_xsd_url = 'http://www.w3.org/2001/xml.xsd', \
                         target_dir = '.', \
                         target_subdir = 'SCHEMAS_OPENGIS_NET',
                         force_download = False,
                         max_download_duration = None):
    try:
        os.mkdir(target_dir)
    except:
        pass

    try:
        os.stat(target_dir + '/' + 'SCHEMAS_OPENGIS_NET.zip')
    except:
        if not gdaltest.download_file(ogc_schemas_url, target_dir + '/' + 'SCHEMAS_OPENGIS_NET.zip', base_dir = '.', force_download = force_download, max_download_duration = max_download_duration):
            return False

    try:
        os.stat(target_dir + '/' + target_subdir + '/wfs')
    except:
        try:
            os.mkdir(target_dir + '/' + target_subdir)
        except:
            pass

        gdaltest.unzip(target_dir + '/' + target_subdir, target_dir + '/' + 'SCHEMAS_OPENGIS_NET.zip')
        try:
            os.stat(target_dir + '/' + target_subdir + '/wfs')
        except:
            print('Cannot unzip SCHEMAS_OPENGIS_NET.zip')
            return False

    try:
        os.stat(target_dir + '/' + target_subdir + '/xlink.xsd')
    except:
         if not gdaltest.download_file(xlink_xsd_url, target_dir + '/' + target_subdir + '/xlink.xsd', base_dir = '.', force_download = force_download, max_download_duration = max_download_duration):
             if not gdaltest.download_file('http://even.rouault.free.fr/xlink.xsd', target_dir + '/' + target_subdir + '/xlink.xsd', base_dir = '.', force_download = force_download, max_download_duration = max_download_duration):
                return False

    try:
        os.stat(target_dir + '/' + target_subdir + '/xml.xsd')
    except:
        if not gdaltest.download_file(xml_xsd_url, target_dir + '/' + target_subdir + '/xml.xsd', base_dir = '.', force_download = force_download, max_download_duration = max_download_duration):
            if not gdaltest.download_file('http://even.rouault.free.fr/xml.xsd', target_dir + '/' + target_subdir + '/xml.xsd', base_dir = '.', force_download = force_download, max_download_duration = max_download_duration):
                return False

    transform_abs_links_to_ref_links(target_dir + '/' + target_subdir)

    return True
Esempio n. 11
0
def ogr_s57_online_3():

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/s57/enctds/GB5X01SW.001', 'GB5X01SW.001'):
        return 'skip'

    shutil.copy( 'tmp/cache/GB5X01SW.001', 'tmp/GB5X01SW.001' )
    ds = ogr.Open( 'tmp/GB5X01SW.000' )
    if ds is None:
        return 'fail'

    lyr = ds.GetLayerByName('LIGHTS')
    feat = lyr.GetFeature(542)

    if feat is None:
        gdaltest.post_reason( 'Did not get expected feature at all.' )
        return 'fail'

    if feat.rver != 2:
        gdaltest.post_reason( 'Did not get expected RVER value (%d).' % feat.rver )
        return 'fail'

    lyr = ds.GetLayerByName('BOYCAR')
    feat = lyr.GetFeature(975)
    if feat is None:
        gdaltest.post_reason( 'unexpected did not get feature id 975 '
                              'after update!' )
        return 'fail'

    feat = None

    ds = None

    gdaltest.clean_tmp()

    return 'success'
Esempio n. 12
0
def rik_online_1():

    try:
        if gdal.GetDriverByName('RIK') is None:
            return 'skip'
    except:
        return 'skip'

    if not gdaltest.download_file('http://www.lantmateriet.se/upload/filer/kartor/programvaror/sverige500_swe99.zip', 'sverige500_swe99.zip'):
        return 'skip'

    try:
        os.stat('tmp/cache/sverige500_swe99.rik')
        file_to_test = 'tmp/cache/sverige500_swe99.rik'
    except:
        try:
            print('Uncompressing ZIP file...')
            import zipfile
            zfobj = zipfile.ZipFile('tmp/cache/sverige500_swe99.zip')
            outfile = open('tmp/cache/sverige500_swe99.rik', 'wb')
            outfile.write(zfobj.read('sverige500_swe99.rik'))
            outfile.close()
            file_to_test = 'tmp/cache/sverige500_swe99.rik'
        except:
            return 'skip'

    tst = gdaltest.GDALTest('RIK', file_to_test, 1, 17162, filename_absolute = 1 )
    return tst.testOpen()
Esempio n. 13
0
def ogr_s57_online_4():

    if not gdaltest.download_file('http://www1.kaiho.mlit.go.jp/KOKAI/ENC/images/sample/sample.zip', 'sample.zip'):
        return 'skip'

    try:
        os.stat('tmp/cache/ENC_ROOT/JP34NC94.000')
    except:
        try:
            gdaltest.unzip( 'tmp/cache', 'tmp/cache/sample.zip')
            try:
                os.stat('tmp/cache/ENC_ROOT/JP34NC94.000')
            except:
                return 'skip'
        except:
            return 'skip'

    gdal.SetConfigOption('OGR_S57_OPTIONS', 'RETURN_PRIMITIVES=ON,RETURN_LINKAGES=ON,LNAM_REFS=ON,RECODE_BY_DSSI=ON')
    ds = ogr.Open('tmp/cache/ENC_ROOT/JP34NC94.000')
    gdal.SetConfigOption('OGR_S57_OPTIONS', None)
    lyr = ds.GetLayerByName('LNDMRK')
    for feat in lyr:
        mystr = feat.NOBJNM
        if mystr and sys.version_info < (3,0,0):
            mystr.decode('UTF-8').encode('UTF-8')

    return 'success'
Esempio n. 14
0
def test_rfc30_1():

    if version_info >= (3, 0, 0):
        filename = 'xx\u4E2D\u6587.\u4E2D\u6587'
        filename_escaped = gdaltest.urlescape(filename)
    else:
        exec("filename =  u'xx\u4E2D\u6587.\u4E2D\u6587'")
        filename_escaped = gdaltest.urlescape(filename.encode('utf-8'))

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/gtiff/' + filename_escaped, filename):
        pytest.skip()

    filename = 'tmp/cache/' + filename

    ds = gdal.Open(filename)

    file_list = ds.GetFileList()

    assert ds is not None, 'failed to open utf filename.'

    ds = None

    ds = gdal.Open(file_list[0])

    assert ds is not None, 'failed to open utf filename (2).'
Esempio n. 15
0
def mrsid_online_2():

    if gdaltest.jp2mrsid_drv is None:
        return 'skip'

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/jpeg2000/gcp.jp2', 'gcp.jp2'):
        return 'skip'

    # Checksum = 209 on my PC
    tst = gdaltest.GDALTest('JP2MrSID', 'tmp/cache/gcp.jp2', 1, None, filename_absolute=1)

    if tst.testOpen() != 'success':
        return 'fail'

    # The JP2MrSID driver doesn't handle GCPs
    ds = gdal.Open('tmp/cache/gcp.jp2')
    ds.GetRasterBand(1).Checksum()
    # if len(ds.GetGCPs()) != 15:
    #    gdaltest.post_reason('bad number of GCP')
    #    return 'fail'
    #
    # expected_wkt = """GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]"""
    # if ds.GetGCPProjection() != expected_wkt:
    #    gdaltest.post_reason('bad GCP projection')
    #    return 'fail'

    ds = None

    return 'success'
Esempio n. 16
0
def ogr_tiger_1():

    ogrtest.tiger_ds = None

    if not gdaltest.download_file('http://www2.census.gov/geo/tiger/tiger2006se/AL/TGR01001.ZIP', 'TGR01001.ZIP'):
        return 'skip'

    try:
        os.stat('tmp/cache/TGR01001/TGR01001.MET')
    except:
        try:
            os.mkdir('tmp/cache/TGR01001')
            gdaltest.unzip( 'tmp/cache/TGR01001', 'tmp/cache/TGR01001.ZIP')
            try:
                os.stat('tmp/cache/TGR01001/TGR01001.MET')
            except:
                return 'skip'
        except:
            return 'skip'

    ogrtest.tiger_ds = ogr.Open('tmp/cache/TGR01001')
    if ogrtest.tiger_ds is None:
        return 'fail'

    return 'success'
Esempio n. 17
0
def ogr_shape_sbn_1():

    if not gdaltest.download_file('http://pubs.usgs.gov/sim/3194/contents/Cochiti_shapefiles.zip', 'Cochiti_shapefiles.zip' ):
        return 'skip'

    try:
        os.stat('tmp/cache/CochitiDamShapeFiles/CochitiBoundary.shp')
    except:
        try:
            gdaltest.unzip( 'tmp/cache', 'tmp/cache/Cochiti_shapefiles.zip')
            try:
                os.stat('tmp/cache/CochitiDamShapeFiles/CochitiBoundary.shp')
            except:
                return 'skip'
        except:
            return 'skip'

    ds = ogr.Open('tmp/cache/CochitiDamShapeFiles')
    for i in range(ds.GetLayerCount()):
        lyr = ds.GetLayer(i)
        ret = search_all_features(lyr)
        if ret != 'success':
            return ret

    return 'success'
Esempio n. 18
0
def test_pcidsk_online_1():
    if gdaltest.pcidsk_new == 0:
        pytest.skip()

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/pcidsk/sdk_testsuite/irvine_gcp2.pix', 'irvine_gcp2.pix'):
        pytest.skip()

    ds = gdal.Open('tmp/cache/irvine_gcp2.pix')

    band = ds.GetRasterBand(6)

    names = band.GetRasterCategoryNames()

    exp_names = ['', '', '', '', '', '', '', '', '', '', '', 'Residential', 'Commercial', 'Industrial', 'Transportation', 'Commercial/Industrial', 'Mixed', 'Other', '', '', '', 'Crop/Pasture', 'Orchards', 'Feeding', 'Other', '', '', '', '', '', '', 'Herbaceous', 'Shrub', 'Mixed', '', '', '', '', '', '', '', 'Deciduous', 'Evergreen', 'Mixed', '', '', '', '', '', '', '', 'Streams/Canals', 'Lakes', 'Reservoirs', 'Bays/Estuaries', '', '', '', '', '', '', 'Forested', 'Nonforested', '', '', '', '', '', '', '', '', 'Dry_Salt_Flats', 'Beaches', 'Sandy_Areas', 'Exposed_Rock', 'Mines/Quarries/Pits', 'Transitional_Area', 'Mixed', '', '', '', 'Shrub/Brush', 'Herbaceous', 'Bare', 'Wet', 'Mixed', '', '', '', '', '', 'Perennial_Snow', 'Glaciers']

    if names != exp_names:
        print(names)
        gdaltest.post_reason('did not get expected category names.')
        return 'false'

    band = ds.GetRasterBand(20)
    assert band.GetDescription() == 'Training site for type 2 crop', \
        'did not get expected band 20 description'

    exp_checksum = 2057
    checksum = band.Checksum()
    assert exp_checksum == checksum, 'did not get right bitmap checksum.'

    md = band.GetMetadata('IMAGE_STRUCTURE')
    assert md['NBITS'] == '1', 'did not get expected NBITS=1 metadata.'
Esempio n. 19
0
def hdf4_read_online_8():

    if gdaltest.hdf4_drv is None:
        return 'skip'

    # 5 MB
    if not gdaltest.download_file('ftp://e4ftl01u.ecs.nasa.gov/MODIS_Composites/MOLT/MOD13Q1.005/2006.06.10/MOD13Q1.A2006161.h21v13.005.2008234103220.hdf', 'MOD13Q1.A2006161.h21v13.005.2008234103220.hdf'):
        return 'skip'

    tst = gdaltest.GDALTest( 'HDF4Image', 'HDF4_EOS:EOS_GRID:tmp/cache/MOD13Q1.A2006161.h21v13.005.2008234103220.hdf:MODIS_Grid_16DAY_250m_500m_VI:250m 16 days NDVI', 1, 53837, filename_absolute = 1 )

    ret = tst.testOpen()
    if ret != 'success':
        return ret

    ds = gdal.Open('HDF4_EOS:EOS_GRID:tmp/cache/MOD13Q1.A2006161.h21v13.005.2008234103220.hdf:MODIS_Grid_16DAY_250m_500m_VI:250m 16 days NDVI')

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

    if 'GetBlockSize' in dir(gdal.Band):
        (blockx, blocky) = ds.GetRasterBand(1).GetBlockSize()
        if blockx != 4800 or blocky == 1:
            print('blockx=%d, blocky=%d' % (blockx, blocky))
            gdaltest.post_reason("Did not get expected block size")
            return 'fail'

    ds = None

    return 'success'
Esempio n. 20
0
def ogr_s57_online_1():

    if not gdaltest.download_file('ftp://sdg.ivs90.nl/ENC/1R5MK050.000', '1R5MK050.000'):
        return 'skip'

    ds = ogr.Open( 'tmp/cache/1R5MK050.000' )
    if ds is None:
        return 'fail'

    lyr = ds.GetLayerByName('BUISGL')
    feat = lyr.GetNextFeature()

    if feat is None:
        gdaltest.post_reason( 'Did not get expected feature at all.' )
        return 'fail'

    exp_wkt = 'POLYGON ((5.6666667 53.0279027,5.6666667 53.0281667,5.6667012 53.0281685,5.666673 53.0282377,5.666788 53.0282616,5.6669018 53.0281507,5.6668145 53.0281138,5.6668121 53.0280649,5.6666686 53.0280248,5.6666713 53.0279647,5.6667572 53.0279713,5.6667568 53.0279089,5.6666667 53.0279027))'

    if ogrtest.check_feature_geometry( feat, exp_wkt ):
        return 'fail'

    feat = None

    ds = None

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

    if gdaltest.hdf4_drv is None:
        return 'skip'

    # 4 MB
    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/hdf4/MOD09A1.A2010041.h06v03.005.2010051001103.hdf', 'MOD09A1.A2010041.h06v03.005.2010051001103.hdf'):
        return 'skip'

    tst = gdaltest.GDALTest( 'HDF4Image', 'HDF4_EOS:EOS_GRID:tmp/cache/MOD09A1.A2010041.h06v03.005.2010051001103.hdf:MOD_Grid_500m_Surface_Reflectance:sur_refl_b01', 1, 54894, filename_absolute = 1 )

    ret = tst.testOpen()
    if ret != 'success':
        return ret

    ds = gdal.Open('HDF4_EOS:EOS_GRID:tmp/cache/MOD09A1.A2010041.h06v03.005.2010051001103.hdf:MOD_Grid_500m_Surface_Reflectance:sur_refl_b01')

    if 'GetBlockSize' in dir(gdal.Band):
        (blockx, blocky) = ds.GetRasterBand(1).GetBlockSize()
        if blockx != 2400 or blocky != 32:
            gdaltest.post_reason("Did not get expected block size")
            return 'fail'

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

    ds = None

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

    if gdaltest.hdf4_drv is None:
        return 'skip'

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/hdf4/MO36MW14.chlor_MODIS.ADD2001089.004.2002186190207.hdf', 'MO36MW14.chlor_MODIS.ADD2001089.004.2002186190207.hdf'):
        return 'skip'

    tst = gdaltest.GDALTest( 'HDF4Image', 'tmp/cache/MO36MW14.chlor_MODIS.ADD2001089.004.2002186190207.hdf', 1, 34723, filename_absolute = 1 )

    ret = tst.testOpen()
    if ret != 'success':
        return ret

    ds = gdal.Open('tmp/cache/MO36MW14.chlor_MODIS.ADD2001089.004.2002186190207.hdf')
    gt = ds.GetGeoTransform()
    expected_gt = [-180.0, 0.3515625, 0.0, 90.0, 0.0, -0.3515625]
    for i in range(6):
        if (abs(gt[i] - expected_gt[i]) > 1e-8):
            print(gt)
            gdaltest.post_reason('did not get expected gt')
            return 'fail'

    srs = ds.GetProjectionRef()
    if srs.find('Clarke') == -1:
        gdaltest.post_reason('did not get expected projection')
        return 'fail'

    ds = None

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

    if not gdaltest.download_file('http://www.falconview.org/trac/FalconView/downloads/17', 'ECRG_Sample.zip'):
        return 'skip'

    try:
        os.stat('tmp/cache/ECRG_Sample.zip')
    except:
        return 'skip'

    ds = gdal.Open('/vsizip/tmp/cache/ECRG_Sample.zip/ECRG_Sample/EPF/TOC.xml')
    if ds is None:
        return 'fail'

    expected_gt = (-85.43147208121826, 0.00059486040609137061, 0.0, 35.239923224568145, 0.0, -0.00044985604606525913)
    gt = ds.GetGeoTransform()
    for i in range(6):
        if abs(gt[i] - expected_gt[i]) > 1e-10:
            gdaltest.post_reason('did not get expected geotransform')
            print(gt)

    wkt = ds.GetProjectionRef()
    if wkt.find('WGS 84') == -1:
        gdaltest.post_reason('did not get expected SRS')
        print(wkt)
        return 'fail'

    filelist = ds.GetFileList()
    if len(filelist) != 7:
        gdaltest.post_reason('did not get expected filelist')
        print(filelist)
        return 'fail'

    return 'success'
Esempio n. 24
0
def hdf4_read_online_10():

    if gdaltest.hdf4_drv is None:
        return 'skip'

    if not gdaltest.download_file('http://trac.osgeo.org/gdal/raw-attachment/ticket/4672/MOD16A2.A2000M01.h14v02.105.2010357183410.hdf', 'MOD16A2.A2000M01.h14v02.105.2010357183410.hdf'):
        return 'skip'

    ds = gdal.Open('HDF4_EOS:EOS_GRID:"tmp/cache/MOD16A2.A2000M01.h14v02.105.2010357183410.hdf":MOD_Grid_MOD16A2:ET_1km')

    if 'GetBlockSize' in dir(gdal.Band):
        (blockx, blocky) = ds.GetRasterBand(1).GetBlockSize()
        if blockx != 1200 or blocky != 833:
            gdaltest.post_reason("Did not get expected block size")
            return 'fail'

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

    ds = None

    return 'success'
Esempio n. 25
0
def rfc30_1():

    if version_info >= (3,0,0):
        filename =  'xx\u4E2D\u6587.\u4E2D\u6587'
        filename_escaped = gdaltest.urlescape(filename)
    else:
        exec("filename =  u'xx\u4E2D\u6587.\u4E2D\u6587'")
        filename_escaped = gdaltest.urlescape(filename.encode( 'utf-8' ))

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/gtiff/' + filename_escaped, filename):
        return 'skip'

    filename = 'tmp/cache/' + filename

    ds = gdal.Open( filename )

    file_list = ds.GetFileList()

    if ds is None:
        gdaltest.post_reason( 'failed to open utf filename.' )
        return 'failure'

    ds = None

    ds = gdal.Open( file_list[0] )

    if ds is None:
        gdaltest.post_reason( 'failed to open utf filename (2).' )
        return 'failure'

    return 'success'
Esempio n. 26
0
def hdf5_12():

    if gdaltest.hdf5_drv is None:
        return 'skip'

    if not gdaltest.download_file('http://trac.osgeo.org/gdal/raw-attachment/ticket/5032/norsa.ss.ppi-00.5-dbz.aeqd-1000.20070601T000039Z.hdf', 'norsa.ss.ppi-00.5-dbz.aeqd-1000.20070601T000039Z.hdf'):
        return 'skip'

    ds = gdal.Open( 'tmp/cache/norsa.ss.ppi-00.5-dbz.aeqd-1000.20070601T000039Z.hdf' )
    got_projection = ds.GetProjection()
    if got_projection.find('Azimuthal_Equidistant') < 0 :
        print(got_projection)
        gdaltest.post_reason('fail')
        return 'fail'

    got_gt = ds.GetGeoTransform()
    expected_gt = (-240890.02470187756, 1001.7181388478905, 0.0, 239638.21326987055, 0.0, -1000.3790932482976)
    # Proj 4.9.3
    expected_gt2 = (-240889.94573659054, 1001.7178235672992, 0.0, 239638.28570609915, 0.0, -1000.3794089534567)

    if max([abs(got_gt[i] - expected_gt[i]) for i in range(6)]) > 1e-5 and \
       max([abs(got_gt[i] - expected_gt2[i]) for i in range(6)]) > 1e-5:
        print(got_gt)
        gdaltest.post_reason('fail')
        return 'fail'

    return 'success'
Esempio n. 27
0
File: ecw.py Progetto: Joe-xXx/gdal
def ecw_online_2():
    if gdaltest.jp2ecw_drv is None:
        return "skip"

    if not gdaltest.download_file("http://download.osgeo.org/gdal/data/jpeg2000/gcp.jp2", "gcp.jp2"):
        return "skip"

    # checksum = 1292 on my PC
    tst = gdaltest.GDALTest("JP2ECW", "tmp/cache/gcp.jp2", 1, None, filename_absolute=1)

    if tst.testOpen() != "success":
        return "fail"

    ds = gdal.Open("tmp/cache/gcp.jp2")
    ds.GetRasterBand(1).Checksum()
    if len(ds.GetGCPs()) != 15:
        gdaltest.post_reason("bad number of GCP")
        return "fail"

    expected_wkt = """GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]"""
    if ds.GetGCPProjection() != expected_wkt:
        gdaltest.post_reason("bad GCP projection")
        return "fail"

    ds = None

    return "success"
Esempio n. 28
0
def ogr_pcidsk_online_1():

    if ogr.GetDriverByName('PCIDSK') is None:
        return 'skip'

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/pcidsk/sdk_testsuite/polygon.pix', 'polygon.pix'):
        return 'skip'

    ds = ogr.Open('tmp/cache/polygon.pix')
    if ds is None:
        gdaltest.post_reason('failure')
        return 'fail'

    lyr = ds.GetLayer(0)
    if lyr is None:
        gdaltest.post_reason('failure')
        return 'fail'

    feat = lyr.GetNextFeature()
    if feat is None:
        gdaltest.post_reason('failure')
        return 'fail'

    geom = 'POLYGON ((479819.84375 4765180.5 0,479690.1875 4765259.5 0,479647.0 4765369.5 0,479730.375 4765400.5 0,480039.03125 4765539.5 0,480035.34375 4765558.5 0,480159.78125 4765610.5 0,480202.28125 4765482.0 0,480365.0 4765015.5 0,480389.6875 4764950.0 0,480133.96875 4764856.5 0,480080.28125 4764979.5 0,480082.96875 4765049.5 0,480088.8125 4765139.5 0,480059.90625 4765239.5 0,480019.71875 4765319.5 0,479980.21875 4765409.5 0,479909.875 4765370.0 0,479859.875 4765270.0 0,479819.84375 4765180.5 0))'
    if ogrtest.check_feature_geometry(feat, geom) != 0:
        gdaltest.post_reason('failure')
        feat.DumpReadable()
        return 'fail'

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

    if gdaltest.hdf4_drv is None:
        return 'skip'

    # 1 MB
    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/hdf4/MOD09Q1G_EVI.A2006233.h07v03.005.2008338190308.hdf', 'MOD09Q1G_EVI.A2006233.h07v03.005.2008338190308.hdf'):
        return 'skip'

    tst = gdaltest.GDALTest( 'HDF4Image', 'HDF4_EOS:EOS_GRID:tmp/cache/MOD09Q1G_EVI.A2006233.h07v03.005.2008338190308.hdf:MODIS_NACP_EVI:MODIS_EVI', 1, 12197, filename_absolute = 1 )

    ret = tst.testOpen()
    if ret != 'success':
        return ret

    ds = gdal.Open('HDF4_EOS:EOS_GRID:tmp/cache/MOD09Q1G_EVI.A2006233.h07v03.005.2008338190308.hdf:MODIS_NACP_EVI:MODIS_EVI')

    if 'GetBlockSize' in dir(gdal.Band):
        (blockx, blocky) = ds.GetRasterBand(1).GetBlockSize()
        if blockx != 4800 or blocky != 4800:
            gdaltest.post_reason("Did not get expected block size")
            return 'fail'

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

    ds = None

    return 'success'
Esempio n. 30
0
File: ecw.py Progetto: bpass/gdal
def ecw_online_5():

    if gdaltest.ecw_drv is None:
        return 'skip'

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/ecw/red_flower.ecw', 'red_flower.ecw'):
        return 'skip'

    ds = gdal.Open('tmp/cache/red_flower.ecw')

    if gdaltest.ecw_drv.major_version == 3:    
        (exp_mean, exp_stddev) = (112.801,52.0431)
        # on Tamas slavebots, (mean,stddev)  = (113.301,52.0434)
        mean_tolerance = 1
    else:
        (exp_mean, exp_stddev) = (114.337,52.1751)
        mean_tolerance = 0.5

    (mean, stddev) = ds.GetRasterBand(2).ComputeBandStats()

    if abs(mean-exp_mean) > mean_tolerance or abs(stddev-exp_stddev) > 0.5:
        gdaltest.post_reason( 'mean/stddev of (%g,%g) diffs from expected(%g,%g)' % (mean, stddev,exp_mean, exp_stddev) )
        return 'fail'

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

    if ogr.GetDriverByName('SOSI') is None:
        pytest.skip()

    if not gdaltest.download_file('http://trac.osgeo.org/gdal/raw-attachment/ticket/3638/20BygnAnlegg.SOS', '20BygnAnlegg.SOS'):
        pytest.skip()

    import test_cli_utilities
    if test_cli_utilities.get_test_ogrsf_path() is None:
        pytest.skip()

    ret = gdaltest.runexternal(test_cli_utilities.get_test_ogrsf_path() + ' -ro tmp/cache/20BygnAnlegg.SOS')

    assert ret.find('INFO') != -1 and ret.find('ERROR') == -1
Esempio n. 32
0
def test_ogr_pcidsk_online_2():

    import test_cli_utilities
    if test_cli_utilities.get_test_ogrsf_path() is None:
        pytest.skip()

    if ogr.GetDriverByName('PCIDSK') is None:
        pytest.skip()

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/pcidsk/sdk_testsuite/polygon.pix', 'polygon.pix'):
        pytest.skip()

    ret = gdaltest.runexternal(test_cli_utilities.get_test_ogrsf_path() + ' -ro tmp/cache/polygon.pix')

    assert ret.find('INFO') != -1 and ret.find('ERROR') == -1
Esempio n. 33
0
def test_jpeg2000_online_6():

    if not gdaltest.download_file(
            'http://www.gwg.nga.mil/ntb/baseline/software/testfile/Jpeg2000/jp2_03/file3.jp2',
            'file3.jp2'):
        pytest.skip()

    ds = gdal.Open('tmp/cache/file3.jp2')
    cs1 = ds.GetRasterBand(1).Checksum()
    cs2 = ds.GetRasterBand(2).Checksum()
    cs3 = ds.GetRasterBand(3).Checksum()
    assert cs1 == 25337 and cs2 == 28262 and cs3 == 59580, \
        'Did not get expected checksums'

    ds = None
Esempio n. 34
0
def jp2openjpeg_online_4():

    if gdaltest.jp2openjpeg_drv is None:
        return 'skip'

    if not gdaltest.download_file(
            'http://www.openjpeg.org/samples/Bretagne2.j2k', 'Bretagne2.j2k'):
        return 'skip'
    if not gdaltest.download_file(
            'http://www.openjpeg.org/samples/Bretagne2.bmp', 'Bretagne2.bmp'):
        return 'skip'

    tst = gdaltest.GDALTest('JP2OpenJPEG',
                            'tmp/cache/Bretagne2.j2k',
                            1,
                            None,
                            filename_absolute=1)

    if tst.testOpen() != 'success':
        return 'expected_fail'

    ds = gdal.Open('tmp/cache/Bretagne2.j2k')
    ds_ref = gdal.Open('tmp/cache/Bretagne2.bmp')
    maxdiff = gdaltest.compare_ds(ds, ds_ref, 0, 0, 1024, 1024)
    print(ds.GetRasterBand(1).Checksum())
    print(ds_ref.GetRasterBand(1).Checksum())

    ds = None
    ds_ref = None

    # Difference between the image before and after compression
    if maxdiff > 10:
        gdaltest.post_reason('Image too different from reference')
        return 'fail'

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

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

    if not gdaltest.download_file(
            'http://www.openjpeg.org/samples/Bretagne2.j2k', 'Bretagne2.j2k'):
        pytest.skip()
    if not gdaltest.download_file(
            'http://www.openjpeg.org/samples/Bretagne2.bmp', 'Bretagne2.bmp'):
        pytest.skip()

    tst = gdaltest.GDALTest('JPEG2000',
                            'tmp/cache/Bretagne2.j2k',
                            1,
                            None,
                            filename_absolute=1)

    # Jasper cannot handle this image
    # Actually, a patched Jasper can ;-)
    if tst.testOpen() != 'success':
        gdaltest.post_reason(
            'Expected failure: Jasper cannot handle this image yet')
        return 'expected_fail'

    ds = gdal.Open('tmp/cache/Bretagne2.j2k')
    ds_ref = gdal.Open('tmp/cache/Bretagne2.bmp')
    maxdiff = gdaltest.compare_ds(ds, ds_ref)
    print(ds.GetRasterBand(1).Checksum())
    print(ds_ref.GetRasterBand(1).Checksum())

    ds = None
    ds_ref = None

    # Difference between the image before and after compression
    assert maxdiff <= 17, 'Image too different from reference'
Esempio n. 36
0
def validate_xml(filename):

    if ogr.GetDriverByName('GMLAS') is None:
        pytest.skip()

    if not gdaltest.download_file(
            'https://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1800.xsd',
            'pds.nasa.gov_pds4_pds_v1_PDS4_PDS_1800.xsd',
            force_download=True):
        pytest.skip()

    if not gdaltest.download_file(
            'https://pds.nasa.gov/pds4/disp/v1/PDS4_DISP_1800.xsd',
            'pds.nasa.gov_pds4_disp_v1_PDS4_DISP_1800.xsd',
            force_download=True):
        pytest.skip()

    if not gdaltest.download_file(
            'https://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1700.xsd',
            'pds.nasa.gov_pds4_pds_v1_PDS4_PDS_1700.xsd',
            force_download=True):
        pytest.skip()

    if not gdaltest.download_file(
            'https://pds.nasa.gov/pds4/cart/v1/PDS4_CART_1700.xsd',
            'pds.nasa.gov_pds4_cart_v1_PDS4_CART_1700.xsd',
            force_download=True):
        pytest.skip()

    ds = gdal.OpenEx(
        'GMLAS:' + filename,
        open_options=[
            'VALIDATE=YES', 'FAIL_IF_VALIDATION_ERROR=YES',
            'CONFIG_FILE=<Configuration><AllowRemoteSchemaDownload>false</AllowRemoteSchemaDownload><SchemaCache><Directory>tmp/cache</Directory></SchemaCache></Configuration>'
        ])
    assert ds is not None
Esempio n. 37
0
    def test( self ):
        if not gdaltest.download_file(self.downloadURL + '/' + self.fileName, self.fileName, self.download_size):
            return 'skip'

        ds = gdal.Open('tmp/cache/' + self.fileName)

        if ds.GetRasterBand(1).Checksum() != self.checksum:
            gdaltest.post_reason('Bad checksum. Expected %d, got %d' % (self.checksum, ds.GetRasterBand(1).Checksum()))
            return 'fail'

        if len(ds.GetGCPs()) != self.gcpNumber:
            gdaltest.post_reason('Bad GCP number. Expected %d, got %d' % (self.gcpNumber, len(ds.GetGCPs())))
            return 'fail'

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

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

    if not gdaltest.download_file(
            'ftp://ftp.maps.canada.ca/pub/nrcan_rncan/archive/image/landsat_7/geobase_hdf/L71002025_02520010722/L71002025_02520010722_MTL.L1G',
            'L71002025_02520010722_MTL.L1G'):
        pytest.skip()

    if not gdaltest.download_file(
            'ftp://ftp.maps.canada.ca/pub/nrcan_rncan/archive/image/landsat_7/geobase_hdf/L71002025_02520010722/L71002025_02520010722_HDF.L1G',
            'L71002025_02520010722_HDF.L1G'):
        pytest.skip()

    f = open('tmp/cache/L71002025_02520010722_B10.L1G', 'wb')
    f.close()

    ds = gdal.Open(
        'HDF4_SDS:UNKNOWN:"tmp/cache/L71002025_02520010722_HDF.L1G":0')
    gcp_count = ds.GetGCPCount()
    ds = None

    assert gcp_count == 4, 'did not get expected gcp count'
Esempio n. 39
0
def hdf4_read_online_9():

    if gdaltest.hdf4_drv is None:
        return 'skip'

    if not gdaltest.download_file('http://www.geogratis.cgdi.gc.ca/download/landsat_7/hdf/L71002025_02520010722/L71002025_02520010722_MTL.L1G', 'L71002025_02520010722_MTL.L1G'):
        return 'skip'

    if not gdaltest.download_file('http://www.geogratis.cgdi.gc.ca/download/landsat_7/hdf/L71002025_02520010722/L71002025_02520010722_HDF.L1G', 'L71002025_02520010722_HDF.L1G'):
        return 'skip'

    f = open('tmp/cache/L71002025_02520010722_B10.L1G', 'wb')
    f.close()

    ds = gdal.Open('HDF4_SDS:UNKNOWN:"tmp/cache/L71002025_02520010722_HDF.L1G":0')
    gcp_count = ds.GetGCPCount()
    ds = None

    if gcp_count != 4:
        gdaltest.post_reason('did not get expected gcp count')
        print(gcp_count)
        return 'fail'

    return 'success'
Esempio n. 40
0
def test_hdf4_read_online_9():

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

    if not gdaltest.download_file(
            'http://www.geogratis.cgdi.gc.ca/download/landsat_7/hdf/L71002025_02520010722/L71002025_02520010722_MTL.L1G',
            'L71002025_02520010722_MTL.L1G'):
        pytest.skip()

    if not gdaltest.download_file(
            'http://www.geogratis.cgdi.gc.ca/download/landsat_7/hdf/L71002025_02520010722/L71002025_02520010722_HDF.L1G',
            'L71002025_02520010722_HDF.L1G'):
        pytest.skip()

    f = open('tmp/cache/L71002025_02520010722_B10.L1G', 'wb')
    f.close()

    ds = gdal.Open(
        'HDF4_SDS:UNKNOWN:"tmp/cache/L71002025_02520010722_HDF.L1G":0')
    gcp_count = ds.GetGCPCount()
    ds = None

    assert gcp_count == 4, 'did not get expected gcp count'
Esempio n. 41
0
def test_ozi_online_1():

    if not gdaltest.download_file(
            'http://www.oziexplorer2.com/maps/Europe2001_setup.exe',
            'Europe2001_setup.exe'):
        pytest.skip()

    try:
        os.stat('tmp/cache/Europe 2001_OZF.map')
    except OSError:
        try:
            gdaltest.unzip('tmp/cache', 'tmp/cache/Europe2001_setup.exe')
            try:
                os.stat('tmp/cache/Europe 2001_OZF.map')
            except OSError:
                pytest.skip()
        except:
            pytest.skip()

    ds = gdal.Open('tmp/cache/Europe 2001_OZF.map')
    assert ds is not None

    if False:  # pylint: disable=using-constant-test
        gt = ds.GetGeoTransform()
        wkt = ds.GetProjectionRef()

        expected_gt = (-1841870.2731215316, 3310.9550245520159,
                       -13.025246304875619, 8375316.4662204208,
                       -16.912440131236657, -3264.1162527118681)
        for i in range(6):
            assert abs(gt[i] - expected_gt[i]) <= 1e-7, 'bad geotransform'

    else:
        gcps = ds.GetGCPs()

        assert len(gcps) == 4, 'did not get expected gcp count.'

        gcp0 = gcps[0]
        assert gcp0.GCPPixel == 61 and gcp0.GCPLine == 436 and abs(gcp0.GCPX - (-1653990.4525324)) <= 0.001 and abs(gcp0.GCPY - 6950885.0402214) <= 0.001, \
            'did not get expected gcp.'

        wkt = ds.GetGCPProjection()

    expected_wkt = 'PROJCS["unnamed",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",40],PARAMETER["standard_parallel_2",56],PARAMETER["latitude_of_origin",4],PARAMETER["central_meridian",10],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["Meter",1]]'
    assert wkt == expected_wkt, 'bad WKT'

    cs = ds.GetRasterBand(1).Checksum()
    assert cs == 16025, 'bad checksum'
Esempio n. 42
0
def netcdf_34():

    filename = 'utm-big-chunks.nc'
    # this timeout is more than enough - on my system takes <1s with fix, about 25 seconds without
    timeout = 5

    if gdaltest.netcdf_drv is None:
        return 'skip'

    if not gdaltest.netcdf_drv_has_nc4:
        return 'skip'

    if not gdaltest.run_slow_tests():
        return 'skip'

    try:
        from multiprocessing import Process
    except:
        print('from multiprocessing import Process failed')
        return 'skip'

    if not gdaltest.download_file(
            'http://download.osgeo.org/gdal/data/netcdf/' + filename,
            filename):
        return 'skip'

    sys.stdout.write('.')
    sys.stdout.flush()

    tst = gdaltest.GDALTest('NetCDF', '../tmp/cache/' + filename, 1, 31621)
    #tst.testOpen()

    gdal.PushErrorHandler('CPLQuietErrorHandler')
    proc = Process(target=tst.testOpen)
    proc.start()
    proc.join(timeout)
    gdal.PopErrorHandler()

    # if proc is alive after timeout we must terminate it, and return fail
    # valgrind detects memory leaks when this occurs (although it should never happen)
    if proc.is_alive():
        proc.terminate()
        print(
            'testOpen() for file %s has reached timeout limit of %d seconds' %
            (filename, timeout))
        return 'fail'

    return 'success'
Esempio n. 43
0
def test_mg4lidar_1():

    drv = gdal.GetDriverByName('MG4Lidar')
    if drv is None:
        pytest.skip()

    if not gdaltest.download_file('http://home.gdal.org/tmp/GDAL_MG4Lidar_Src.zip', 'GDAL_MG4Lidar_Src.zip'):
        pytest.skip()

    try:
        os.stat('tmp/cache/GDAL_MG4Lidar_Src')
    except OSError:
        try:
            gdaltest.unzip('tmp/cache', 'tmp/cache/GDAL_MG4Lidar_Src.zip')
            try:
                os.stat('tmp/cache/GDAL_MG4Lidar_Src')
            except OSError:
                pytest.skip()
        except OSError:
            pytest.skip()

    ds = gdal.Open('tmp/cache/GDAL_MG4Lidar_Src/Tetons_200k.view')
    assert ds is not None, 'could not open dataset'

    prj = ds.GetProjectionRef()
    if prj.find('NAD83 / UTM zone 12N') == -1:
        gdaltest.post_reason('did not get expected projection')
        print(prj)
        return

    gt = ds.GetGeoTransform()
    ref_gt = (504489.919999999983702, 3.078227571115974, 0, 4795848.389999999664724, 0, -3.078259860787739)
    for i in range(6):
        assert abs(gt[i] - ref_gt[i]) <= 1e-6, 'did not get expected geotransform'

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

    cs = ds.GetRasterBand(1).GetOverview(0).Checksum()
    if cs != 64099:
        gdaltest.post_reason('did not get expected overview checksum')
        print(cs)
        return

    ds = None
Esempio n. 44
0
def test_rik_online_2():

    if gdal.GetDriverByName('RIK') is None:
        pytest.skip()

    if not gdaltest.download_file(
            'http://trac.osgeo.org/gdal/raw-attachment/ticket/3674/ab-del.rik',
            'ab-del.rik'):
        pytest.skip()

    tst = gdaltest.GDALTest('RIK',
                            'tmp/cache/ab-del.rik',
                            1,
                            44974,
                            filename_absolute=1)
    return tst.testOpen()
Esempio n. 45
0
def hdf4_read_online_5():

    if gdaltest.hdf4_drv is None:
        return 'skip'

    # 13 MB
    if not gdaltest.download_file('ftp://data.nodc.noaa.gov/pub/data.nodc/pathfinder/Version5.0/Monthly/1991/199101.s04m1pfv50-sst-16b.hdf', '199101.s04m1pfv50-sst-16b.hdf'):
        return 'skip'

    tst = gdaltest.GDALTest( 'HDF4Image', 'tmp/cache/199101.s04m1pfv50-sst-16b.hdf', 1, 41173, filename_absolute = 1 )

    ret = tst.testOpen()
    if ret != 'success':
        return ret

    return 'success'
Esempio n. 46
0
def test_hdf5_13():

    if not gdaltest.download_file(
            'http://oceandata.sci.gsfc.nasa.gov/cgi/getfile/A2016273115000.L2_LAC_OC.nc',
            'A2016273115000.L2_LAC_OC.nc'):
        pytest.skip()

    ds = gdal.Open(
        'HDF5:"tmp/cache/A2016273115000.L2_LAC_OC.nc"://geophysical_data/Kd_490'
    )

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

    assert (abs(got_gcps[0].GCPPixel - 0.5) <= 1e-5 and abs(got_gcps[0].GCPLine - 0.5) <= 1e-5 and \
       abs(got_gcps[0].GCPX - 33.1655693) <= 1e-5 and abs(got_gcps[0].GCPY - 39.3207207) <= 1e-5)
Esempio n. 47
0
def test_hdf4_read_online_4():

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

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/hdf4/S2002196124536.L1A_HDUN.BartonBendish.extract.hdf', 'S2002196124536.L1A_HDUN.BartonBendish.extract.hdf'):
        pytest.skip()

    tst = gdaltest.GDALTest('HDF4Image', 'tmp/cache/S2002196124536.L1A_HDUN.BartonBendish.extract.hdf', 1, 33112, filename_absolute=1)

    tst.testOpen()

    ds = gdal.Open('tmp/cache/S2002196124536.L1A_HDUN.BartonBendish.extract.hdf')
    assert ds.RasterCount == 8, 'did not get expected band number'

    ds = None
Esempio n. 48
0
def test_gff_1():
    # 12088 = 2048 + 8 * 1255
    if not gdaltest.download_file(
            'http://sandia.gov/RADAR/complex_data/MiniSAR20050519p0001image008.gff',
            'MiniSAR20050519p0001image008.gff', 12088):
        pytest.skip()

    tst = gdaltest.GDALTest('GFF',
                            'tmp/cache/MiniSAR20050519p0001image008.gff',
                            1,
                            29757,
                            filename_absolute=1)
    gdal.PushErrorHandler('CPLQuietErrorHandler')
    ret = tst.testOpen()
    gdal.PopErrorHandler()
    return ret
Esempio n. 49
0
def ogr_dgn_online_1():

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/dgn/DGNSample_v7.dgn', 'DGNSample_v7.dgn'):
        return 'skip'

    ds = ogr.Open('tmp/cache/DGNSample_v7.dgn')
    if ds is None:
        return 'fail'
    lyr = ds.GetLayer(0)
    feat = lyr.GetFeature(35)
    wkt = 'LINESTRING (82.9999500717185 23.2084166997284,83.0007450788903 23.2084495986816,83.00081490524 23.2068095339824,82.9999503769036 23.2067737968078)'

    if ogrtest.check_feature_geometry(feat, wkt):
        return 'fail'

    return 'success'
Esempio n. 50
0
def test_hdf5_13():

    if not gdaltest.download_file(
            'http://oceandata.sci.gsfc.nasa.gov/cgi/getfile/A2016273115000.L2_LAC_OC.nc',
            'A2016273115000.L2_LAC_OC.nc'):
        pytest.skip()

    ds = gdal.Open(
        'HDF5:"tmp/cache/A2016273115000.L2_LAC_OC.nc"://geophysical_data/Kd_490'
    )

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

    assert (got_gcps[0].GCPPixel == pytest.approx(0.5, abs=1e-5) and got_gcps[0].GCPLine == pytest.approx(0.5, abs=1e-5) and \
       got_gcps[0].GCPX == pytest.approx(33.1655693, abs=1e-5) and got_gcps[0].GCPY == pytest.approx(39.3207207, abs=1e-5))
Esempio n. 51
0
def test_hdf5_12():

    if not gdaltest.download_file('http://trac.osgeo.org/gdal/raw-attachment/ticket/5032/norsa.ss.ppi-00.5-dbz.aeqd-1000.20070601T000039Z.hdf', 'norsa.ss.ppi-00.5-dbz.aeqd-1000.20070601T000039Z.hdf'):
        pytest.skip()

    ds = gdal.Open('tmp/cache/norsa.ss.ppi-00.5-dbz.aeqd-1000.20070601T000039Z.hdf')
    got_projection = ds.GetProjection()
    assert 'Azimuthal_Equidistant' in got_projection

    got_gt = ds.GetGeoTransform()
    expected_gt = (-240890.02470187756, 1001.7181388478905, 0.0, 239638.21326987055, 0.0, -1000.3790932482976)
    # Proj 4.9.3
    expected_gt2 = (-240889.94573659054, 1001.7178235672992, 0.0, 239638.28570609915, 0.0, -1000.3794089534567)

    assert (max([abs(got_gt[i] - expected_gt[i]) for i in range(6)]) <= 1e-5 or \
       max([abs(got_gt[i] - expected_gt2[i]) for i in range(6)]) <= 1e-5)
Esempio n. 52
0
def test_hdf4_read_online_11():

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

    if not gdaltest.download_file(
            'https://gamma.hdfgroup.org/ftp/pub/outgoing/NASAHDFfiles2/eosweb/hdf4/hdfeos2-swath-wo-dimmaps/AMSR_E_L2_Ocean_B01_200206182340_A.hdf',
            'AMSR_E_L2_Ocean_B01_200206182340_A.hdf'):
        pytest.skip()

    ds = gdal.Open(
        'HDF4_EOS:EOS_SWATH:"tmp/cache/AMSR_E_L2_Ocean_B01_200206182340_A.hdf":Swath1:Ocean_products_quality_flag'
    )

    cs = ds.GetRasterBand(1).Checksum()
    assert cs == 7809, 'did not get expected checksum'
Esempio n. 53
0
def hdf4_read_online_1():

    try:
        gdaltest.hdf4_drv = gdal.GetDriverByName('HDF4')
    except:
        gdaltest.hdf4_drv = None

    if gdaltest.hdf4_drv is None:
        return 'skip'

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/hdf4/A2004259075000.L2_LAC_SST.hdf', 'A2004259075000.L2_LAC_SST.hdf'):
        return 'skip'

    tst = gdaltest.GDALTest( 'HDF4Image', 'tmp/cache/A2004259075000.L2_LAC_SST.hdf', 1, 28189, filename_absolute = 1 )

    return tst.testOpen()
Esempio n. 54
0
def test_mrsid_online_1():

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

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/jpeg2000/7sisters200.j2k', '7sisters200.j2k'):
        pytest.skip()

    # Checksum = 29473 on my PC
    tst = gdaltest.GDALTest('JP2MrSID', 'tmp/cache/7sisters200.j2k', 1, None, filename_absolute=1)

    tst.testOpen()

    ds = gdal.Open('tmp/cache/7sisters200.j2k')
    ds.GetRasterBand(1).Checksum()
    ds = None
Esempio n. 55
0
def ogr_ntf_1():

    if not gdaltest.download_file('http://www.ordnancesurvey.co.uk/oswebsite/products/strategi/sampledata/stratntf.exe', 'stratntf.exe'):
        return 'skip'

    try:
        os.stat('tmp/cache/SS.ntf')
    except:
        try:
            gdaltest.unzip('tmp/cache', 'tmp/cache/stratntf.exe')
            try:
                os.stat('tmp/cache/SS.ntf')
            except:
                return 'skip'
        except:
            return 'skip'

    ds = ogr.Open('tmp/cache/SS.ntf')
    if ds.GetLayerCount() != 5:
        return 'fail'

    layers = [ ('STRATEGI_POINT', ogr.wkbPoint, 9193),
               ('STRATEGI_LINE', ogr.wkbLineString, 8369),
               ('STRATEGI_TEXT', ogr.wkbPoint, 1335),
               ('STRATEGI_NODE', ogr.wkbNone, 10991),
               ('FEATURE_CLASSES', ogr.wkbNone, 224) ]

    for l in layers:
        lyr = ds.GetLayerByName(l[0])
        if lyr.GetLayerDefn().GetGeomType() != l[1]:
            return 'fail'
        if lyr.GetFeatureCount() != l[2]:
            print(lyr.GetFeatureCount())
            return 'fail'
        if l[1] != ogr.wkbNone:
            if lyr.GetSpatialRef().ExportToWkt().find('OSGB 1936') == -1:
                return 'fail'

    lyr = ds.GetLayerByName('STRATEGI_POINT')
    feat = lyr.GetNextFeature()
    if feat.GetGeometryRef().ExportToWkt() != 'POINT (222904 127850)':
        print(feat.GetGeometryRef().ExportToWkt())
        return 'fail'

    ds.Destroy()

    return 'success'
Esempio n. 56
0
def pdf_online_1():

    try:
        if gdal.GetDriverByName('PDF') is None:
            return 'skip'
    except:
        return 'skip'

    if not gdaltest.download_file('http://www.agc.army.mil/GeoPDFgallery/Imagery/Cherrydale_eDOQQ_1m_0_033_R1C1.pdf', 'Cherrydale_eDOQQ_1m_0_033_R1C1.pdf'):
        return 'skip'

    try:
        os.stat('tmp/cache/Cherrydale_eDOQQ_1m_0_033_R1C1.pdf')
    except:
        return 'skip'

    ds = gdal.Open('tmp/cache/Cherrydale_eDOQQ_1m_0_033_R1C1.pdf')
    if ds is None:
        return 'fail'

    if ds.RasterXSize != 620:
        gdaltest.post_reason('bad dimensions')
        return 'fail'

    gt = ds.GetGeoTransform()
    wkt = ds.GetProjectionRef()

    expected_gt = (-77.112328333299999, 1.8333311999999999e-05, 0.0, 38.897842488372, -0.0, -1.8333311999999999e-05)
    for i in range(6):
        if abs(gt[i] - expected_gt[i]) > 1e-15:
            gdaltest.post_reason('bad geotransform')
            print(gt)
            print(expected_gt)
            return 'fail'

    expected_wkt = '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 wkt != expected_wkt:
        gdaltest.post_reason('bad WKT')
        print(wkt)
        return 'fail'

    cs = ds.GetRasterBand(1).Checksum()
    if cs == 0:
        gdaltest.post_reason('bad checksum')
        return 'fail'

    return 'success'
Esempio n. 57
0
def test_ogr_tiger_1():

    ogrtest.tiger_ds = None

    if not gdaltest.download_file('http://www2.census.gov/geo/tiger/tiger2006se/AL/TGR01001.ZIP', 'TGR01001.ZIP'):
        pytest.skip()

    try:
        os.stat('tmp/cache/TGR01001/TGR01001.MET')
    except OSError:
        try:
            try:
                os.stat('tmp/cache/TGR01001')
            except OSError:
                os.mkdir('tmp/cache/TGR01001')
            gdaltest.unzip('tmp/cache/TGR01001', 'tmp/cache/TGR01001.ZIP')
            try:
                os.stat('tmp/cache/TGR01001/TGR01001.MET')
            except OSError:
                pytest.skip()
        except:
            pytest.skip()

    ogrtest.tiger_ds = ogr.Open('tmp/cache/TGR01001')
    assert ogrtest.tiger_ds is not None

    ogrtest.tiger_ds = None
    # also test opening with a filename (#4443)
    ogrtest.tiger_ds = ogr.Open('tmp/cache/TGR01001/TGR01001.RT1')
    assert ogrtest.tiger_ds is not None

    # Check a few features.
    cc_layer = ogrtest.tiger_ds.GetLayerByName('CompleteChain')
    assert cc_layer.GetFeatureCount() == 19289, 'wrong cc feature count'

    feat = cc_layer.GetNextFeature()
    feat = cc_layer.GetNextFeature()
    feat = cc_layer.GetNextFeature()

    assert feat.TLID == 2833200 and feat.FRIADDL is None and feat.BLOCKL == 5000, \
        'wrong attribute on cc feature.'

    assert ogrtest.check_feature_geometry(feat, 'LINESTRING (-86.4402 32.504137,-86.440313 32.504009,-86.440434 32.503884,-86.440491 32.503805,-86.44053 32.503757,-86.440578 32.503641,-86.440593 32.503515,-86.440588 32.503252,-86.440596 32.50298)', max_error=0.000001) == 0

    feat = ogrtest.tiger_ds.GetLayerByName('TLIDRange').GetNextFeature()
    assert feat.MODULE == 'TGR01001' and feat.TLMINID == 2822718, \
        'got wrong TLIDRange attributes'
Esempio n. 58
0
    def download_file(self):
        # download and decompress
        if not gdaltest.download_file(self.downloadURL, os.path.basename(self.downloadURL), -1):
            return False

        filename = os.path.join('tmp', 'cache', self.fileName)
        if os.path.exists(filename):
            return True

        # decompress
        f_in = gzip.open(os.path.join('tmp', 'cache', os.path.basename(self.downloadURL)))
        f_out = open(filename, 'wb')
        f_out.write(f_in.read())
        f_in.close()
        f_out.close()

        return True
Esempio n. 59
0
def test_ogr_pdf_online_1():

    if not has_read_support():
        pytest.skip()

    if not gdaltest.download_file(
            'http://www.terragotech.com/images/pdf/webmap_urbansample.pdf',
            'webmap_urbansample.pdf'):
        pytest.skip()

    expected_layers = [
        ["Cadastral Boundaries", ogr.wkbPolygon],
        ["Water Lines", ogr.wkbLineString],
        ["Sewerage Lines", ogr.wkbLineString],
        ["Sewerage Jump-Ups", ogr.wkbLineString],
        ["Roads", ogr.wkbUnknown],
        ["Water Points", ogr.wkbPoint],
        ["Sewerage Pump Stations", ogr.wkbPoint],
        ["Sewerage Man Holes", ogr.wkbPoint],
        ["BPS - Buildings", ogr.wkbPolygon],
        ["BPS - Facilities", ogr.wkbPolygon],
        ["BPS - Water Sources", ogr.wkbPoint],
    ]

    ds = ogr.Open('tmp/cache/webmap_urbansample.pdf')
    assert ds is not None

    assert ds.GetLayerCount() == len(expected_layers)

    for i in range(ds.GetLayerCount()):
        assert ds.GetLayer(i).GetName() == expected_layers[i][0], \
            ('%d : %s' % (i, ds.GetLayer(i).GetName()))

        assert ds.GetLayer(i).GetGeomType() == expected_layers[i][1], \
            ('%d : %d' % (i, ds.GetLayer(i).GetGeomType()))

    lyr = ds.GetLayerByName('Water Points')
    feat = lyr.GetNextFeature()
    if ogrtest.check_feature_geometry(
            feat,
            ogr.CreateGeometryFromWkt(
                'POINT (724431.316665166523308 7672947.212302438914776)')
    ) != 0:
        feat.DumpReadable()
        pytest.fail()
    assert feat.GetField('ID') == 'VL46'
Esempio n. 60
0
def test_ogr_ntf_2():

    if not gdaltest.download_file(
            'http://www.ordnancesurvey.co.uk/oswebsite/products/meridian2/sampledata/meridian2ntf.exe',
            'meridian2ntf.exe'):
        pytest.skip()

    try:
        os.stat('tmp/cache/Port_Talbot_NTF/SS78.ntf')
    except OSError:
        try:
            gdaltest.unzip('tmp/cache', 'tmp/cache/meridian2ntf.exe')
            try:
                os.stat('tmp/cache/Port_Talbot_NTF/SS78.ntf')
            except OSError:
                pytest.skip()
        except OSError:
            pytest.skip()

    ds = ogr.Open('tmp/cache/Port_Talbot_NTF/SS78.ntf')
    assert ds.GetLayerCount() == 5

    layers = [('MERIDIAN2_POINT', ogr.wkbPoint, 408),
              ('MERIDIAN2_LINE', ogr.wkbLineString, 513),
              ('MERIDIAN2_TEXT', ogr.wkbPoint, 7),
              ('MERIDIAN2_NODE', ogr.wkbNone, 397),
              ('FEATURE_CLASSES', ogr.wkbNone, 50)]

    for l in layers:
        lyr = ds.GetLayerByName(l[0])
        assert lyr.GetLayerDefn().GetGeomType() == l[1]
        assert lyr.GetFeatureCount() == l[2]
        if l[1] != ogr.wkbNone:
            assert lyr.GetSpatialRef().ExportToWkt().find('OSGB 1936') != -1

    lyr = ds.GetLayerByName('MERIDIAN2_POINT')
    feat = lyr.GetNextFeature()
    assert feat.GetGeometryRef().ExportToWkt() == 'POINT (275324 189274)'

    lyr = ds.GetLayerByName('MERIDIAN2_LINE')
    feat = lyr.GetNextFeature()
    assert feat.GetGeometryRef().ExportToWkt(
    ) == 'LINESTRING (275324 189274,275233 189114,275153 189048)'

    ds.Destroy()