Exemple #1
0
def ogr_gft_read():
    if ogrtest.gft_drv is None:
        return 'skip'

    old_auth = gdal.GetConfigOption('GFT_AUTH', None)
    old_email = gdal.GetConfigOption('GFT_EMAIL', None)
    old_password = gdal.GetConfigOption('GFT_PASSWORD', None)
    gdal.SetConfigOption('GFT_AUTH', None)
    gdal.SetConfigOption('GFT_EMAIL', None)
    gdal.SetConfigOption('GFT_PASSWORD', None)
    ds = ogr.Open('GFT:tables=224453')
    gdal.SetConfigOption('GFT_AUTH', old_auth)
    gdal.SetConfigOption('GFT_EMAIL', old_email)
    gdal.SetConfigOption('GFT_PASSWORD', old_password)
    if ds is None:
        return 'fail'

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

    lyr.SetSpatialFilterRect(67, 31.5, 67.5, 32)
    lyr.SetAttributeFilter("'Attack on' = 'ENEMY'")

    count = lyr.GetFeatureCount()
    if count == 0:
        gdaltest.post_reason('did not get expected feature count')
        print(count)
        return 'fail'

    return 'success'
Exemple #2
0
def netcdf_27():

    if gdaltest.netcdf_drv is None:
        return 'skip'

    #test default config
    test = gdaltest.GDALTest('NETCDF', '../data/int16-nogeo.nc', 1, 4672)
    config_bak = gdal.GetConfigOption('GDAL_NETCDF_BOTTOMUP')
    gdal.SetConfigOption('GDAL_NETCDF_BOTTOMUP', None)
    result = test.testOpen()
    gdal.SetConfigOption('GDAL_NETCDF_BOTTOMUP', config_bak)

    if result != 'success':
        print('failed open without GDAL_NETCDF_BOTTOMUP')
        return result

    #test GDAL_NETCDF_BOTTOMUP=NO
    test = gdaltest.GDALTest('NETCDF', '../data/int16-nogeo.nc', 1, 4855)
    config_bak = gdal.GetConfigOption('GDAL_NETCDF_BOTTOMUP')
    gdal.SetConfigOption('GDAL_NETCDF_BOTTOMUP', 'NO')
    result = test.testOpen()
    gdal.SetConfigOption('GDAL_NETCDF_BOTTOMUP', config_bak)

    if result != 'success':
        print('failed open with GDAL_NETCDF_BOTTOMUP')
        return result

    return 'success'
Exemple #3
0
def ogr_gft_read():
    if ogrtest.gft_drv is None:
        return 'skip'

    table_id = '15eIgEVTUNlC649ODphJVHXeb4nsOb49WJUlnhw'

    old_auth = gdal.GetConfigOption('GFT_AUTH', None)
    old_access = gdal.GetConfigOption('GFT_ACCESS_TOKEN', None)
    old_refresh = gdal.GetConfigOption('GFT_REFRESH_TOKEN', None)
    gdal.SetConfigOption('GFT_AUTH', None)
    gdal.SetConfigOption('GFT_ACCESS_TOKEN', None)
    gdal.SetConfigOption('GFT_REFRESH_TOKEN', None)
    ds = ogr.Open('GFT:tables=' + table_id)
    gdal.SetConfigOption('GFT_AUTH', old_auth)
    gdal.SetConfigOption('GFT_ACCESS_TOKEN', old_access)
    gdal.SetConfigOption('GFT_REFRESH_TOKEN', old_refresh)
    if ds is None:
        return 'fail'

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

    lyr.SetSpatialFilterRect(67, 31.5, 67.5, 32)
    lyr.SetAttributeFilter("'Attack on' = 'ENEMY'")

    count = lyr.GetFeatureCount()
    if count == 0:
        gdaltest.post_reason('did not get expected feature count')
        print(count)
        if gdaltest.skip_on_travis():
            ogrtest.gft_drv = None
            return 'skip'
        return 'fail'

    sql_lyr = ds.ExecuteSQL(
        "SELECT Latitude, Longitude FROM " + table_id +
        " WHERE ST_INTERSECTS('Latitude', RECTANGLE(LATLNG(31.5,67.0), LATLNG(32.0,67.5))) AND 'Attack on' = 'ENEMY'"
    )
    if sql_lyr is None:
        gdaltest.post_reason('SQL request failed')
        return 'fail'
    sql_lyr_count = sql_lyr.GetFeatureCount()
    ds.ReleaseResultSet(sql_lyr)

    if sql_lyr_count != count:
        gdaltest.post_reason(
            'did not get expected feature count. Got %d, expected %d' %
            (sql_lyr_count, count))
        return 'fail'

    return 'success'
Exemple #4
0
def ogr_gft_read():
    if ogrtest.gft_drv is None:
        return 'skip'

    old_auth = gdal.GetConfigOption('GFT_AUTH', None)
    old_email = gdal.GetConfigOption('GFT_EMAIL', None)
    old_password = gdal.GetConfigOption('GFT_PASSWORD', None)
    gdal.SetConfigOption('GFT_AUTH', None)
    gdal.SetConfigOption('GFT_EMAIL', None)
    gdal.SetConfigOption('GFT_PASSWORD', None)
    ds = ogr.Open('GFT:tables=224453')
    gdal.SetConfigOption('GFT_AUTH', old_auth)
    gdal.SetConfigOption('GFT_EMAIL', old_email)
    gdal.SetConfigOption('GFT_PASSWORD', old_password)
    if ds is None:
        return 'fail'

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

    lyr.SetSpatialFilterRect(67, 31.5, 67.5, 32)
    lyr.SetAttributeFilter("'Attack on' = 'ENEMY'")

    count = lyr.GetFeatureCount()
    if count == 0:
        gdaltest.post_reason('did not get expected feature count')
        print(count)
        if gdaltest.skip_on_travis():
            ogrtest.gft_drv = None
            return 'skip'
        return 'fail'

    sql_lyr = ds.ExecuteSQL(
        "SELECT Latitude, Longitude FROM 224453 WHERE ST_INTERSECTS('Latitude', RECTANGLE(LATLNG(31.5,67.0), LATLNG(32.0,67.5))) AND 'Attack on' = 'ENEMY'"
    )
    if sql_lyr is None:
        gdaltest.post_reason('SQL request failed')
        return 'fail'
    sql_lyr_count = sql_lyr.GetFeatureCount()
    ds.ReleaseResultSet(sql_lyr)

    if sql_lyr_count != count:
        gdaltest.post_reason(
            'did not get expected feature count. Got %d, expected %d' %
            (sql_lyr_count, count))
        return 'fail'

    return 'success'
Exemple #5
0
def pam_1():

    gdaltest.pam_setting = gdal.GetConfigOption( 'GDAL_PAM_ENABLED', "NULL" )
    gdal.SetConfigOption( 'GDAL_PAM_ENABLED', 'YES' )

    ds = gdal.Open( "data/byte.pnm" )

    base_md = ds.GetMetadata()
    if len(base_md) != 2 or base_md['other'] != 'red' \
       or base_md['key'] != 'value':
        gdaltest.post_reason( 'Default domain metadata missing' )
        return 'fail'

    xml_md = ds.GetMetadata( 'xml:test' )

    if len(xml_md) != 1:
        gdaltest.post_reason( 'xml:test metadata missing' )
        return 'fail'

    if type(xml_md) != type(['abc']):
        gdaltest.post_reason( 'xml:test metadata not returned as list.' )
        return 'fail'

    expected_xml = """<?xml version="2.0"?>
<TestXML>Value</TestXML>
"""

    if xml_md[0] != expected_xml:
        gdaltest.post_reason( 'xml does not match' )
        print(xml_md)
        return 'fail'
    
    return 'success' 
Exemple #6
0
def run_py_script(script_path, script_name, concatenated_argv):

    run_as_external_script = gdal.GetConfigOption('RUN_AS_EXTERNAL_SCRIPT',
                                                  'NO')

    if run_as_external_script == 'yes' or run_as_external_script == 'YES':
        return run_py_script_as_external_script(script_path, script_name,
                                                concatenated_argv)
    else:
        return run_py_script_as_py_module(script_path, script_name,
                                          concatenated_argv)
Exemple #7
0
def ogr_osm_9():

    if ogrtest.osm_drv is None:
        return 'skip'

    old_val = gdal.GetConfigOption('OSM_USE_CUSTOM_INDEXING')
    gdal.SetConfigOption('OSM_USE_CUSTOM_INDEXING', 'NO')
    ret = ogr_osm_8()
    gdal.SetConfigOption('OSM_USE_CUSTOM_INDEXING', old_val)

    return ret
Exemple #8
0
	def allowUnsafeSSL(unsafeSSL):
		if (unsafeSSL) :
			value='YES'
		else :
			value='NO'
		current_value = gdal.GetConfigOption('GDAL_HTTP_UNSAFESSL')
		if ((current_value is None) or (current_value != value)):
			gdal.SetConfigOption('GDAL_HTTP_UNSAFESSL', value)
			# We clear curl's cache. Curl caches failed requests, and returns
			# errors from the cache.
			gdal.VSICurlClearCache()			
Exemple #9
0
def test_gdalwarp_cleanup():

    # We don't clean up when run in debug mode.
    if gdal.GetConfigOption('CPL_DEBUG', 'OFF') == 'ON':
        return 'success'

    for i in range(29):
        try:
            os.remove('tmp/testgdalwarp' + str(i + 1) + '.tif')
        except:
            pass
        try:
            os.remove('tmp/testgdalwarp' + str(i + 1) + '.vrt')
        except:
            pass
        try:
            os.remove('tmp/testgdalwarp' + str(i + 1) + '.tif.aux.xml')
        except:
            pass
    try:
        os.remove('tmp/testgdalwarp_gcp.tif')
    except:
        pass
    try:
        os.remove('tmp/testgdalwarp24src.tif')
    except:
        pass
    try:
        os.remove('tmp/testgdalwarp24dst.tif')
    except:
        pass
    try:
        os.remove('tmp/testgdalwarp30_1.tif')
    except:
        pass
    try:
        os.remove('tmp/testgdalwarp30_2.tif')
    except:
        pass
    try:
        os.remove('tmp/testgdalwarp31.tif')
    except:
        pass
    try:
        os.remove('tmp/testgdalwarp32.tif')
    except:
        pass
    try:
        os.remove('tmp/testgdalwarp33.tif')
        os.remove('tmp/testgdalwarp33_mask.tif')
    except:
        pass
    return 'success'
Exemple #10
0
def ogr_wkbwkt_test_import_bad_multipoint_wkb():

    import struct
    wkb = struct.pack('B' * 30, 0, 0, 0, 0, 6, 0, 0, 0, 1, 0, 0, 0, 0, 1, 64, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0 )
    gdal.PushErrorHandler('CPLQuietErrorHandler')
    old_val = gdal.GetConfigOption('CPL_DEBUG')
    gdal.SetConfigOption('CPL_DEBUG', 'ON')
    geom =  ogr.CreateGeometryFromWkb(wkb)
    gdal.SetConfigOption('CPL_DEBUG', old_val)
    gdal.PopErrorHandler()
    if geom is not None:
        return 'fail'

    return 'success'
Exemple #11
0
def ogr_s57_1():

    gdaltest.s57_ds = None

    # Clear S57 options if set or our results will be messed up.
    if gdal.GetConfigOption( 'OGR_S57_OPTIONS', '' ) != '':
        gdal.SetConfigOption( 'OGR_S57_OPTIONS', '' )
        
    gdaltest.s57_ds = ogr.Open( 'data/1B5X02NE.000' )    
    if gdaltest.s57_ds is None:
        gdaltest.post_reason( 'failed to open test file.' )
        return 'fail'

    return 'success'
Exemple #12
0
def hfa_use_rrd():

    shutil.copyfile('data/small_ov.img', 'tmp/small.img')

    old_value = gdal.GetConfigOption('HFA_USE_RRD', 'NO')
    gdal.SetConfigOption('HFA_USE_RRD', 'YES')
    ds = gdal.Open('tmp/small.img', gdal.GA_Update)
    result = ds.BuildOverviews(overviewlist=[2])
    gdal.SetConfigOption('HFA_USE_RRD', old_value)

    if result != 0:
        print(result)
        gdaltest.post_reason('BuildOverviews() failed.')
        return 'fail'
    ds = None

    try:
        fd = open('tmp/small.rrd')
    except:
        fd = None

    if fd is None:
        gdaltest.post_reason('small.rrd not present.')
        return 'fail'
    fd.close()

    ds = gdal.Open('tmp/small.img')
    if ds.GetRasterBand(1).GetOverview(0).Checksum() != 26148:
        print(ds.GetRasterBand(1).GetOverview(0).Checksum())
        gdaltest.post_reason('Unexpected checksum.')
        return 'fail'

    ds = None

    gdal.GetDriverByName('HFA').Delete('tmp/small.img')

    return 'success'