Ejemplo n.º 1
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'
Ejemplo n.º 2
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 OSError:
        try:
            gdaltest.unzip('tmp/cache', 'tmp/cache/Cochiti_shapefiles.zip')
            try:
                os.stat('tmp/cache/CochitiDamShapeFiles/CochitiBoundary.shp')
            except OSError:
                return 'skip'
        except OSError:
            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'
Ejemplo n.º 3
0
def ogr_s57_online_4():
    if gdaltest.s57_ds is None:
        return 'skip'

    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'
Ejemplo n.º 4
0
def test_aigrid_online_2():

    if not gdaltest.download_file(
            'http://download.osgeo.org/gdal/data/aig/ai_bug_6886.zip',
            'ai_bug_6886.zip'):
        pytest.skip()

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

    tst = gdaltest.GDALTest('AIG',
                            'tmp/cache/ai_bug/ai_bug/hdr.adf',
                            1,
                            16018,
                            filename_absolute=1)
    return tst.testOpen()
Ejemplo n.º 5
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'
Ejemplo n.º 6
0
def ogr_fgdb_16():
    if ogrtest.fgdb_drv is None or ogrtest.openfilegdb_drv is None:
        return 'skip'

    try:
        gdaltest.unzip( 'tmp/cache', 'data/ESSENCE_NAIPF_ORI_PROV_sub93.gdb.zip')
    except:
        pass
    try:
        os.stat('tmp/cache/ESSENCE_NAIPF_ORI_PROV_sub93.gdb')
    except:
        return 'skip'

    ogrtest.fgdb_drv.Deregister()

    # Force FileGDB first
    ogrtest.fgdb_drv.Register()
    ogrtest.openfilegdb_drv.Register()

    ds = ogr.Open('tmp/cache/ESSENCE_NAIPF_ORI_PROV_sub93.gdb')
    if ds is None:
        ret = 'fail'
    else:
        ret = 'success'

    # Deregister OpenFileGDB again
    ogrtest.openfilegdb_drv.Deregister()
    
    shutil.rmtree('tmp/cache/ESSENCE_NAIPF_ORI_PROV_sub93.gdb')

    return ret
Ejemplo n.º 7
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'
Ejemplo n.º 8
0
def ogr_nas_2():

    drv = ogr.GetDriverByName('NAS')
    if drv is None:
        return 'skip'

    if not gdaltest.download_file(
            'http://trac.wheregroup.com/PostNAS/browser/trunk/demodaten/lverm_geo_rlp/gid-6.0/gm2566-testdaten-gid60-2008-11-11.xml.zip?format=raw',
            'gm2566-testdaten-gid60-2008-11-11.xml.zip'):
        return 'skip'

    try:
        os.stat('tmp/cache/gm2566-testdaten-gid60-2008-11-11.xml')
    except OSError:
        try:
            gdaltest.unzip(
                'tmp/cache',
                'tmp/cache/gm2566-testdaten-gid60-2008-11-11.xml.zip')
            try:
                os.stat('tmp/cache/gm2566-testdaten-gid60-2008-11-11.xml')
            except OSError:
                return 'skip'
        except OSError:
            return 'skip'

    try:
        os.remove('tmp/cache/gm2566-testdaten-gid60-2008-11-11.gfs')
    except OSError:
        pass

    ds = ogr.Open('tmp/cache/gm2566-testdaten-gid60-2008-11-11.xml')
    if ds is None:
        gdaltest.post_reason('could not open dataset')
        return 'fail'

    if ds.GetLayerCount() != 85:
        gdaltest.post_reason('did not get expected layer count')
        print(ds.GetLayerCount())
        return 'fail'

    lyr = ds.GetLayerByName('AX_Flurstueck')

    # Loop until a feature that has a complex geometry including <gml:Arc>
    feat = lyr.GetNextFeature()
    while feat is not None and feat.GetField(
            'identifier') != 'urn:adv:oid:DERP1234000002Iz':
        feat = lyr.GetNextFeature()
    if feat is None:
        return 'fail'

    # expected_geom = 'POLYGON ((350821.045 5532031.37,350924.309 5532029.513,350938.493 5532026.622,350951.435 5532021.471,350978.7 5532007.18,351026.406 5531971.088,351032.251 5531951.162,351080.623 5531942.67,351154.886 5531963.718,351207.689 5532019.797,351211.063 5532044.067,351203.83 5532074.034,351165.959 5532114.315,351152.85 5532135.774,351141.396 5532140.355,351110.659 5532137.542,351080.17 5532132.742,351002.887 5532120.75,350925.682 5532108.264,350848.556 5532095.285,350771.515 5532081.814,350769.548 5532071.196,350812.194 5532034.716,350821.045 5532031.37))'
    expected_geom = 'CURVEPOLYGON (COMPOUNDCURVE ((350821.045 5532031.37,350924.309 5532029.513,350938.493 5532026.622,350951.435 5532021.471,350978.7 5532007.18,351026.406 5531971.088,351032.251 5531951.16199999955),(351032.251 5531951.16199999955,351080.623 5531942.67,351154.886 5531963.718),(351154.886 5531963.718,351207.689 5532019.797),(351207.689 5532019.797,351211.063 5532044.06699999981,351203.83 5532074.034,351165.959 5532114.315,351152.85 5532135.774),(351152.85 5532135.774,351141.396 5532140.355),CIRCULARSTRING (351141.396 5532140.355,351110.659 5532137.542,351080.17 5532132.74199999962),CIRCULARSTRING (351080.17 5532132.74199999962,351002.887 5532120.75,350925.682 5532108.264),CIRCULARSTRING (350925.682 5532108.264,350848.556 5532095.285,350771.515 5532081.814),(350771.515 5532081.814,350769.548 5532071.196,350812.194 5532034.716,350821.045 5532031.37)))'
    if ogrtest.check_feature_geometry(feat, expected_geom) != 0:
        geom = feat.GetGeometryRef()
        print(geom)
        return 'fail'

    ds = None

    return 'success'
Ejemplo n.º 9
0
def test_ogr_s57_online_4():

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

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

    gdal.SetConfigOption(
        'OGR_S57_OPTIONS',
        'RETURN_PRIMITIVES=ON,RETURN_LINKAGES=ON,LNAM_REFS=ON')
    ds = ogr.Open('tmp/cache/ENC_ROOT/JP34NC94.000')
    gdal.SetConfigOption('OGR_S57_OPTIONS', None)
    lyr = ds.GetLayerByName('LNDMRK')
    for feat in lyr:
        feat.NOBJNM
Ejemplo n.º 10
0
def test_loslas_online_1():

    if not gdaltest.download_file(
            'http://www.ngs.noaa.gov/PC_PROD/NADCON/NADCON.zip', 'NADCON.zip'):
        pytest.skip()

    try:
        os.stat('tmp/cache/NADCON.zip')
    except OSError:
        pytest.skip()

    try:
        gdaltest.unzip('tmp/cache/NADCON', 'tmp/cache/NADCON.zip')
        os.stat('tmp/cache/NADCON/nadcon.jar')
        gdaltest.unzip('tmp/cache/NADCON', 'tmp/cache/NADCON/nadcon.jar')
        os.stat('tmp/cache/NADCON/grids/wyhpgn.los')
    except OSError:
        pytest.skip()

    tst = gdaltest.GDALTest('LOSLAS',
                            'tmp/cache/NADCON/grids/wyhpgn.los',
                            1,
                            0,
                            filename_absolute=1)
    gt = (-111.625, 0.25, 0.0, 45.625, 0.0, -0.25)
    stats = (-0.0080000003799796, 0.031125999987125001, 0.0093017323318172005,
             0.0075646520354096004)
    return tst.testOpen(check_gt=gt, check_stat=stats, check_prj='WGS84')
Ejemplo n.º 11
0
def ogr_nas_2():

    try:
        drv = ogr.GetDriverByName('NAS')
    except:
        drv = None

    if drv is None:
        return 'skip'

    if not gdaltest.download_file('http://trac.wheregroup.com/PostNAS/browser/trunk/demodaten/lverm_geo_rlp/gid-6.0/gm2566-testdaten-gid60-2008-11-11.xml.zip?format=raw', 'gm2566-testdaten-gid60-2008-11-11.xml.zip'):
        return 'skip'

    try:
        os.stat('tmp/cache/gm2566-testdaten-gid60-2008-11-11.xml')
    except:
        try:
            gdaltest.unzip( 'tmp/cache', 'tmp/cache/gm2566-testdaten-gid60-2008-11-11.xml.zip')
            try:
                os.stat('tmp/cache/gm2566-testdaten-gid60-2008-11-11.xml')
            except:
                return 'skip'
        except:
            return 'skip'

    try:
        os.remove( 'tmp/cache/gm2566-testdaten-gid60-2008-11-11.gfs' )
    except:
        pass

    ds = ogr.Open('tmp/cache/gm2566-testdaten-gid60-2008-11-11.xml')
    if ds is None:
        gdaltest.post_reason('could not open dataset')
        return 'fail'

    if ds.GetLayerCount() != 85:
        gdaltest.post_reason('did not get expected layer count')
        print(ds.GetLayerCount())
        return 'fail'

    lyr = ds.GetLayerByName('AX_Flurstueck')

    # Loop until a feature that has a complex geometry including <gml:Arc>
    feat = lyr.GetNextFeature()
    while feat is not None and feat.GetField('identifier') != 'urn:adv:oid:DERP1234000002Iz':
        feat = lyr.GetNextFeature()
    if feat is None:
        return 'fail'

    #expected_geom = 'POLYGON ((350821.045 5532031.37,350924.309 5532029.513,350938.493 5532026.622,350951.435 5532021.471,350978.7 5532007.18,351026.406 5531971.088,351032.251 5531951.162,351080.623 5531942.67,351154.886 5531963.718,351207.689 5532019.797,351211.063 5532044.067,351203.83 5532074.034,351165.959 5532114.315,351152.85 5532135.774,351141.396 5532140.355,351110.659 5532137.542,351080.17 5532132.742,351002.887 5532120.75,350925.682 5532108.264,350848.556 5532095.285,350771.515 5532081.814,350769.548 5532071.196,350812.194 5532034.716,350821.045 5532031.37))'
    expected_geom = 'CURVEPOLYGON (COMPOUNDCURVE ((350821.045 5532031.37,350924.309 5532029.513,350938.493 5532026.622,350951.435 5532021.471,350978.7 5532007.18,351026.406 5531971.088,351032.251 5531951.16199999955),(351032.251 5531951.16199999955,351080.623 5531942.67,351154.886 5531963.718),(351154.886 5531963.718,351207.689 5532019.797),(351207.689 5532019.797,351211.063 5532044.06699999981,351203.83 5532074.034,351165.959 5532114.315,351152.85 5532135.774),(351152.85 5532135.774,351141.396 5532140.355),CIRCULARSTRING (351141.396 5532140.355,351110.659 5532137.542,351080.17 5532132.74199999962),CIRCULARSTRING (351080.17 5532132.74199999962,351002.887 5532120.75,350925.682 5532108.264),CIRCULARSTRING (350925.682 5532108.264,350848.556 5532095.285,350771.515 5532081.814),(350771.515 5532081.814,350769.548 5532071.196,350812.194 5532034.716,350821.045 5532031.37)))'
    if ogrtest.check_feature_geometry(feat, expected_geom) != 0:
        geom = feat.GetGeometryRef()
        print(geom)
        return 'fail'

    ds = None

    return 'success'
Ejemplo n.º 12
0
def mg4lidar_1():

    try:
        drv = gdal.GetDriverByName('MG4Lidar')
    except:
        drv = None

    if drv is None:
        return 'skip'

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

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

    ds = gdal.Open('tmp/cache/GDAL_MG4Lidar_Src/Tetons_200k.view')
    if ds is None:
        gdaltest.post_reason('could not open dataset')
        return 'fail'

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

    gt = ds.GetGeoTransform()
    ref_gt = (504489.919999999983702,3.078227571115974,0,4795848.389999999664724,0,-3.078259860787739)
    for i in range(6):
        if abs(gt[i]-ref_gt[i]) > 1e-6:
            gdaltest.post_reason('did not get expected geotransform')
            print(gt)
            return 'fail'

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

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

    ds = None

    return 'success'
Ejemplo n.º 13
0
def switch_driver(tested_driver='PGeo', other_driver='MDB'):

    ogrtest.pgeo_ds = None

    ogrtest.other_driver = ogr.GetDriverByName(other_driver)
    if ogrtest.other_driver is not None:
        print('Unregistering %s driver' % ogrtest.other_driver.GetName())
        ogrtest.other_driver.Deregister()
        if other_driver == 'PGeo':
            # Re-register Geomedia and WALK at the end, *after* MDB
            geomedia_driver = ogr.GetDriverByName('Geomedia')
            if geomedia_driver is not None:
                geomedia_driver.Deregister()
                geomedia_driver.Register()
            walk_driver = ogr.GetDriverByName('WALK')
            if walk_driver is not None:
                walk_driver.Deregister()
                walk_driver.Register()

    drv = ogr.GetDriverByName(tested_driver)

    if drv is None:
        pytest.skip("Driver not available: %s" % tested_driver)

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/pgeo/PGeoTest.zip', 'PGeoTest.zip'):
        pytest.skip()

    try:
        os.stat('tmp/cache/Autodesk Test.mdb')
    except OSError:
        try:
            gdaltest.unzip('tmp/cache', 'tmp/cache/PGeoTest.zip')
            try:
                os.stat('tmp/cache/Autodesk Test.mdb')
            except OSError:
                pytest.skip()
        except:
            pytest.skip()

    ogrtest.pgeo_ds = ogr.Open('tmp/cache/Autodesk Test.mdb')
    if ogrtest.pgeo_ds is None:
        pytest.skip('could not open DB. Driver probably misconfigured')

    assert ogrtest.pgeo_ds.GetLayerCount() == 3, 'did not get expected layer count'

    lyr = ogrtest.pgeo_ds.GetLayer(0)
    feat = lyr.GetNextFeature()
    if feat.GetField('OBJECTID') != 1 or \
       feat.GetField('IDNUM') != 9424 or \
       feat.GetField('OWNER') != 'City':
        feat.DumpReadable()
        pytest.fail('did not get expected attributes')

    if ogrtest.check_feature_geometry(feat, 'LINESTRING (1910941.703951031 445833.57942859828 0,1910947.927691862 445786.43811868131 0)', max_error=0.0000001) != 0:
        feat.DumpReadable()
        pytest.fail('did not get expected geometry')

    feat_count = lyr.GetFeatureCount()
    assert feat_count == 9418, 'did not get expected feature count'
Ejemplo n.º 14
0
def mg4lidar_1():

    try:
        drv = gdal.GetDriverByName("MG4Lidar")
    except:
        drv = None

    if drv is None:
        return "skip"

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

    try:
        os.stat("tmp/cache/GDAL_MG4Lidar_Src")
    except:
        try:
            gdaltest.unzip("tmp/cache", "tmp/cache/GDAL_MG4Lidar_Src.zip")
            try:
                os.stat("tmp/cache/GDAL_MG4Lidar_Src")
            except:
                return "skip"
        except:
            return "skip"

    ds = gdal.Open("tmp/cache/GDAL_MG4Lidar_Src/Tetons_200k.view")
    if ds is None:
        gdaltest.post_reason("could not open dataset")
        return "fail"

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

    gt = ds.GetGeoTransform()
    ref_gt = (504489.919999999983702, 3.078227571115974, 0, 4795848.389999999664724, 0, -3.078259860787739)
    for i in range(6):
        if abs(gt[i] - ref_gt[i]) > 1e-6:
            gdaltest.post_reason("did not get expected geotransform")
            print(gt)
            return "fail"

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

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

    ds = None

    return "success"
Ejemplo n.º 15
0
def mg4lidar_1():

    try:
        drv = gdal.GetDriverByName('MG4Lidar')
    except:
        drv = None

    if drv is None:
        return 'skip'

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

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

    ds = gdal.Open('tmp/cache/GDAL_MG4Lidar_Src/Tetons_200k.view')
    if ds is None:
        gdaltest.post_reason('could not open dataset')
        return 'fail'

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

    gt = ds.GetGeoTransform()
    ref_gt = (504489.919999999983702,3.078227571115974,0,4795848.389999999664724,0,-3.078259860787739)
    for i in range(6):
        if abs(gt[i]-ref_gt[i]) > 1e-6:
            gdaltest.post_reason('did not get expected geotransform')
            print(gt)
            return 'fail'

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

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

    ds = None

    return 'success'
Ejemplo n.º 16
0
def test_ogr_ogdi_1():

    ogrtest.ogdi_ds = None

    # Skip tests when -fsanitize is used because of memleaks in libogdi
    if gdaltest.is_travis_branch('sanitize'):
        ogrtest.ogdi_drv = None
        pytest.skip('Skipping because of memory leaks in OGDI')

    ogrtest.ogdi_drv = ogr.GetDriverByName('OGDI')
    if ogrtest.ogdi_drv is None:
        pytest.skip()

    if not gdaltest.download_file(
            'http://freefr.dl.sourceforge.net/project/ogdi/OGDI_Test_Suite/3.1/ogdits-3.1.0.zip',
            'ogdits-3.1.0.zip'):
        pytest.skip()

    try:
        os.stat('tmp/cache/ogdits-3.1')
    except OSError:
        try:
            gdaltest.unzip('tmp/cache', 'tmp/cache/ogdits-3.1.0.zip')
            try:
                os.stat('tmp/cache/ogdits-3.1')
            except OSError:
                pytest.skip()
        except OSError:
            pytest.skip()

    url_name = 'gltp:/vrf/' + os.getcwd(
    ) + '/tmp/cache/ogdits-3.1/data/vpf/vm2alv2/texash'

    ds = ogr.Open(url_name)
    ogrtest.ogdi_ds = ds
    assert ds is not None, ('cannot open ' + url_name)
    assert ds.GetLayerCount() == 57, 'did not get expected layer count'

    layers = [('libref@libref(*)_line', ogr.wkbLineString, 15),
              ('libreft@libref(*)_text', ogr.wkbPoint, 4),
              ('markersp@bnd(*)_point', ogr.wkbPoint, 40),
              ('polbnda@bnd(*)_area', ogr.wkbPolygon, 6)]

    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:
        #    if lyr.GetSpatialRef().ExportToWkt().find('WGS 84') == -1:
        #        return 'fail'

    lyr = ds.GetLayerByName('libref@libref(*)_line')
    feat = lyr.GetNextFeature()

    wkt = 'LINESTRING (-97.570159912109375 31.242000579833984,-97.569938659667969 31.242116928100586,-97.562828063964844 31.245765686035156,-97.558868408203125 31.247797012329102,-97.555778503417969 31.249361038208008,-97.55413818359375 31.250171661376953)'
    ref_geom = ogr.CreateGeometryFromWkt(wkt)

    assert ogrtest.check_feature_geometry(feat, ref_geom) == 0, \
        feat.GetGeometryRef().ExportToWkt()
Ejemplo n.º 17
0
def switch_driver(tested_driver='PGeo', other_driver='MDB'):

    ogrtest.pgeo_ds = None

    ogrtest.other_driver = ogr.GetDriverByName(other_driver)
    if ogrtest.other_driver is not None:
        print('Unregistering %s driver' % ogrtest.other_driver.GetName())
        ogrtest.other_driver.Deregister()
        if other_driver == 'PGeo':
            # Re-register Geomedia and WALK at the end, *after* MDB
            geomedia_driver = ogr.GetDriverByName('Geomedia')
            if geomedia_driver is not None:
                geomedia_driver.Deregister()
                geomedia_driver.Register()
            walk_driver = ogr.GetDriverByName('WALK')
            if walk_driver is not None:
                walk_driver.Deregister()
                walk_driver.Register()

    drv = ogr.GetDriverByName(tested_driver)

    if drv is None:
        pytest.skip("Driver not available: %s" % tested_driver)

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/pgeo/PGeoTest.zip', 'PGeoTest.zip'):
        pytest.skip()

    try:
        os.stat('tmp/cache/Autodesk Test.mdb')
    except OSError:
        try:
            gdaltest.unzip('tmp/cache', 'tmp/cache/PGeoTest.zip')
            try:
                os.stat('tmp/cache/Autodesk Test.mdb')
            except OSError:
                pytest.skip()
        except:
            pytest.skip()

    ogrtest.pgeo_ds = ogr.Open('tmp/cache/Autodesk Test.mdb')
    if ogrtest.pgeo_ds is None:
        pytest.skip('could not open DB. Driver probably misconfigured')

    assert ogrtest.pgeo_ds.GetLayerCount() == 3, 'did not get expected layer count'

    lyr = ogrtest.pgeo_ds.GetLayer(0)
    feat = lyr.GetNextFeature()
    if feat.GetField('OBJECTID') != 1 or \
       feat.GetField('IDNUM') != 9424 or \
       feat.GetField('OWNER') != 'City':
        feat.DumpReadable()
        pytest.fail('did not get expected attributes')

    if ogrtest.check_feature_geometry(feat, 'LINESTRING (1910941.703951031 445833.57942859828 0,1910947.927691862 445786.43811868131 0)', max_error=0.0000001) != 0:
        feat.DumpReadable()
        pytest.fail('did not get expected geometry')

    feat_count = lyr.GetFeatureCount()
    assert feat_count == 9418, 'did not get expected feature count'
Ejemplo n.º 18
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:
            try:
                os.stat('tmp/cache/TGR01001')
            except:
                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:
        gdaltest.post_reason('fail')
        return 'fail'

    ogrtest.tiger_ds = None
    # also test opening with a filename (#4443)
    ogrtest.tiger_ds = ogr.Open('tmp/cache/TGR01001/TGR01001.RT1')
    if ogrtest.tiger_ds is None:
        gdaltest.post_reason('fail')
        return 'fail'

    # Check a few features.
    cc_layer = ogrtest.tiger_ds.GetLayerByName('CompleteChain')
    if cc_layer.GetFeatureCount() != 19289:
        gdaltest.post_reason( 'wrong cc feature count' )
        return 'fail'
    
    feat = cc_layer.GetNextFeature()
    feat = cc_layer.GetNextFeature()
    feat = cc_layer.GetNextFeature()

    if feat.TLID != 2833200 or feat.FRIADDL != None or feat.BLOCKL != 5000:
        gdaltest.post_reason( 'wrong attribute on cc feature.' )
        return 'fail'

    if 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:
        return 'fail'

    feat = ogrtest.tiger_ds.GetLayerByName('TLIDRange').GetNextFeature()
    if feat.MODULE != 'TGR01001' or feat.TLMINID != 2822718:
        gdaltest.post_reason( 'got wrong TLIDRange attributes' )
        return 'fail'
    
    return 'success'
Ejemplo n.º 19
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:
            try:
                os.stat('tmp/cache/TGR01001')
            except:
                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:
        gdaltest.post_reason('fail')
        return 'fail'

    ogrtest.tiger_ds = None
    # also test opening with a filename (#4443)
    ogrtest.tiger_ds = ogr.Open('tmp/cache/TGR01001/TGR01001.RT1')
    if ogrtest.tiger_ds is None:
        gdaltest.post_reason('fail')
        return 'fail'

    # Check a few features.
    cc_layer = ogrtest.tiger_ds.GetLayerByName('CompleteChain')
    if cc_layer.GetFeatureCount() != 19289:
        gdaltest.post_reason( 'wrong cc feature count' )
        return 'fail'

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

    if feat.TLID != 2833200 or feat.FRIADDL != None or feat.BLOCKL != 5000:
        gdaltest.post_reason( 'wrong attribute on cc feature.' )
        return 'fail'

    if 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:
        return 'fail'

    feat = ogrtest.tiger_ds.GetLayerByName('TLIDRange').GetNextFeature()
    if feat.MODULE != 'TGR01001' or feat.TLMINID != 2822718:
        gdaltest.post_reason( 'got wrong TLIDRange attributes' )
        return 'fail'

    return 'success'
Ejemplo n.º 20
0
def ogr_nas_1():

    try:
        drv = ogr.GetDriverByName('NAS')
    except:
        drv = None

    if drv is None:
        return 'skip'

    if not gdaltest.download_file('http://www.geodatenzentrum.de/gdz1/abgabe/testdaten/vektor/nas_testdaten_peine.zip', 'nas_testdaten_peine.zip'):
        return 'skip'

    try:
        os.stat('tmp/cache/BKG_NAS_Peine.xml')
    except:
        try:
            gdaltest.unzip( 'tmp/cache', 'tmp/cache/nas_testdaten_peine.zip')
            try:
                os.stat('tmp/cache/BKG_NAS_Peine.xml')
            except:
                return 'skip'
        except:
            return 'skip'

    try:
        os.remove( 'tmp/cache/BKG_NAS_Peine.gfs' )
    except:
        pass

    ds = ogr.Open('tmp/cache/BKG_NAS_Peine.xml')
    if ds is None:
        gdaltest.post_reason('could not open dataset')
        return 'fail'

    if ds.GetLayerCount() != 41:
        gdaltest.post_reason('did not get expected layer count')
        return 'fail'

    lyr = ds.GetLayerByName('AX_Wohnplatz')
    feat = lyr.GetNextFeature()
    geom = feat.GetGeometryRef()

    if feat.GetField('name') != 'Ziegelei' or geom.ExportToWkt() != 'POINT (3575300 5805100)':
        feat.DumpReadable()
        return 'fail'

    relation_lyr = ds.GetLayerByName('ALKIS_beziehungen')
    feat = relation_lyr.GetNextFeature()
    if feat.GetField('beziehung_von') != 'DENIBKG1000001UG' or \
       feat.GetField('beziehungsart') != 'istTeilVon' or \
       feat.GetField('beziehung_zu') != 'DENIBKG1000000T6':
        feat.DumpReadable()
        return 'fail'

    ds = None

    return 'success'
Ejemplo n.º 21
0
def ogr_nas_1():

    try:
        drv = ogr.GetDriverByName('NAS')
    except:
        drv = None

    if drv is None:
        return 'skip'

    if not gdaltest.download_file('http://www.geodatenzentrum.de/gdz1/abgabe/testdaten/vektor/nas_testdaten_peine.zip', 'nas_testdaten_peine.zip'):
        return 'skip'

    try:
        os.stat('tmp/cache/BKG_NAS_Peine.xml')
    except:
        try:
            gdaltest.unzip( 'tmp/cache', 'tmp/cache/nas_testdaten_peine.zip')
            try:
                os.stat('tmp/cache/BKG_NAS_Peine.xml')
            except:
                return 'skip'
        except:
            return 'skip'

    try:
        os.remove( 'tmp/cache/BKG_NAS_Peine.gfs' )
    except:
        pass

    ds = ogr.Open('tmp/cache/BKG_NAS_Peine.xml')
    if ds is None:
        gdaltest.post_reason('could not open dataset')
        return 'fail'

    if ds.GetLayerCount() != 41:
        gdaltest.post_reason('did not get expected layer count')
        return 'fail'

    lyr = ds.GetLayerByName('AX_Wohnplatz')
    feat = lyr.GetNextFeature()
    geom = feat.GetGeometryRef()

    if feat.GetField('name') != 'Ziegelei' or geom.ExportToWkt() != 'POINT (3575300 5805100)':
        feat.DumpReadable()
        return 'fail'

    relation_lyr = ds.GetLayerByName('ALKIS_beziehungen')
    feat = relation_lyr.GetNextFeature()
    if feat.GetField('beziehung_von') != 'DENIBKG1000001UG' or \
       feat.GetField('beziehungsart') != 'istTeilVon' or \
       feat.GetField('beziehung_zu') != 'DENIBKG1000000T6':
        feat.DumpReadable()
        return 'fail'

    ds = None

    return 'success'
Ejemplo n.º 22
0
def test_ogr_ogdi_1():

    ogrtest.ogdi_ds = None

    # Skip tests when -fsanitize is used because of memleaks in libogdi
    if gdaltest.is_travis_branch('sanitize'):
        ogrtest.ogdi_drv = None
        pytest.skip('Skipping because of memory leaks in OGDI')

    ogrtest.ogdi_drv = ogr.GetDriverByName('OGDI')
    if ogrtest.ogdi_drv is None:
        pytest.skip()

    if not gdaltest.download_file('http://freefr.dl.sourceforge.net/project/ogdi/OGDI_Test_Suite/3.1/ogdits-3.1.0.zip', 'ogdits-3.1.0.zip'):
        pytest.skip()

    try:
        os.stat('tmp/cache/ogdits-3.1')
    except OSError:
        try:
            gdaltest.unzip('tmp/cache', 'tmp/cache/ogdits-3.1.0.zip')
            try:
                os.stat('tmp/cache/ogdits-3.1')
            except OSError:
                pytest.skip()
        except OSError:
            pytest.skip()

    url_name = 'gltp:/vrf/' + os.getcwd() + '/tmp/cache/ogdits-3.1/data/vpf/vm2alv2/texash'

    ds = ogr.Open(url_name)
    ogrtest.ogdi_ds = ds
    assert ds is not None, ('cannot open ' + url_name)
    assert ds.GetLayerCount() == 57, 'did not get expected layer count'

    layers = [('libref@libref(*)_line', ogr.wkbLineString, 15),
              ('libreft@libref(*)_text', ogr.wkbPoint, 4),
              ('markersp@bnd(*)_point', ogr.wkbPoint, 40),
              ('polbnda@bnd(*)_area', ogr.wkbPolygon, 6)]

    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:
        #    if lyr.GetSpatialRef().ExportToWkt().find('WGS 84') == -1:
        #        return 'fail'

    lyr = ds.GetLayerByName('libref@libref(*)_line')
    feat = lyr.GetNextFeature()

    wkt = 'LINESTRING (-97.570159912109375 31.242000579833984,-97.569938659667969 31.242116928100586,-97.562828063964844 31.245765686035156,-97.558868408203125 31.247797012329102,-97.555778503417969 31.249361038208008,-97.55413818359375 31.250171661376953)'
    ref_geom = ogr.CreateGeometryFromWkt(wkt)

    assert ogrtest.check_feature_geometry(feat, ref_geom) == 0, \
        feat.GetGeometryRef().ExportToWkt()
Ejemplo n.º 23
0
def ogr_ntf_2():

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

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

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

    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])
        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('MERIDIAN2_POINT')
    feat = lyr.GetNextFeature()
    if feat.GetGeometryRef().ExportToWkt() != 'POINT (275324 189274)':
        print(feat.GetGeometryRef().ExportToWkt())
        return 'fail'

    lyr = ds.GetLayerByName('MERIDIAN2_LINE')
    feat = lyr.GetNextFeature()
    if feat.GetGeometryRef().ExportToWkt(
    ) != 'LINESTRING (275324 189274,275233 189114,275153 189048)':
        print(feat.GetGeometryRef().ExportToWkt())
        return 'fail'

    ds.Destroy()

    return 'success'
Ejemplo n.º 24
0
def ogr_ntf_2():

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

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

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

    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])
        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('MERIDIAN2_POINT')
    feat = lyr.GetNextFeature()
    if feat.GetGeometryRef().ExportToWkt() != 'POINT (275324 189274)':
        print(feat.GetGeometryRef().ExportToWkt())
        return 'fail'

    lyr = ds.GetLayerByName('MERIDIAN2_LINE')
    feat = lyr.GetNextFeature()
    if feat.GetGeometryRef().ExportToWkt() != 'LINESTRING (275324 189274,275233 189114,275153 189048)':
        print(feat.GetGeometryRef().ExportToWkt())
        return 'fail'

    ds.Destroy()

    return 'success'
Ejemplo n.º 25
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'
Ejemplo n.º 26
0
def ogr_mitab_29():
    try:
        os.stat('tmp/cache/compr_symb_deleted_records.tab')
    except:
        try:
            gdaltest.unzip('tmp/cache', 'data/compr_symb_deleted_records.zip')
            try:
                os.stat('tmp/cache/compr_symb_deleted_records.tab')
            except:
                return 'skip'
        except:
            return 'skip'

    shutil.copy('tmp/cache/compr_symb_deleted_records.tab', 'tmp')
    shutil.copy('tmp/cache/compr_symb_deleted_records.dat', 'tmp')
    shutil.copy('tmp/cache/compr_symb_deleted_records.id', 'tmp')
    shutil.copy('tmp/cache/compr_symb_deleted_records.map', 'tmp')

    # Is a 100x100 point grid with only the 4 edge lines left (compressed points)
    ds = ogr.Open('tmp/compr_symb_deleted_records.tab', update=1)
    lyr = ds.GetLayer(0)
    # Re-add the 98x98 interior points
    i = 0
    N2 = 98
    N = N2 * N2
    permutation = generate_permutation(N)
    for n in permutation:
        x = 1 + int(n / N2)
        y = 1 + n % N2
        f = ogr.Feature(lyr.GetLayerDefn())
        f.SetGeometry(ogr.CreateGeometryFromWkt('POINT(%d %d)' % (x, y)))
        lyr.CreateFeature(f)
    ds = None

    # Check grid integrity that after reopening
    ds = ogr.Open('tmp/compr_symb_deleted_records.tab')
    lyr = ds.GetLayer(0)
    N2 = 100
    N = N2 * N2
    for n in range(N):
        x = int(n / N2)
        y = n % N2
        lyr.SetSpatialFilterRect(x - 0.01, y - 0.01, x + 0.01, y + 0.01)
        if lyr.GetFeatureCount() != 1:
            gdaltest.post_reason('fail')
            return 'fail'
    ds = None

    ogr.GetDriverByName('MapInfo File').DeleteDataSource(
        'tmp/compr_symb_deleted_records.tab')

    return 'success'
Ejemplo n.º 27
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 gt[i] == pytest.approx(
            ref_gt[i], abs=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
Ejemplo n.º 28
0
def ogr_mitab_29():
    try:
        os.stat('tmp/cache/compr_symb_deleted_records.tab')
    except:
        try:
            gdaltest.unzip( 'tmp/cache', 'data/compr_symb_deleted_records.zip')
            try:
                os.stat('tmp/cache/compr_symb_deleted_records.tab')
            except:
                return 'skip'
        except:
            return 'skip'

    shutil.copy('tmp/cache/compr_symb_deleted_records.tab', 'tmp')
    shutil.copy('tmp/cache/compr_symb_deleted_records.dat', 'tmp')
    shutil.copy('tmp/cache/compr_symb_deleted_records.id', 'tmp')
    shutil.copy('tmp/cache/compr_symb_deleted_records.map', 'tmp')

    # Is a 100x100 point grid with only the 4 edge lines left (compressed points)
    ds = ogr.Open('tmp/compr_symb_deleted_records.tab', update = 1)
    lyr = ds.GetLayer(0)
    # Re-add the 98x98 interior points
    i = 0
    N2 = 98
    N = N2 * N2
    permutation = generate_permutation(N)
    for n in permutation:
        x = 1 + int(n / N2)
        y = 1 + n % N2
        f = ogr.Feature(lyr.GetLayerDefn())
        f.SetGeometry(ogr.CreateGeometryFromWkt('POINT(%d %d)' % (x,y)))
        lyr.CreateFeature(f)
    ds = None

    # Check grid integrity that after reopening
    ds = ogr.Open('tmp/compr_symb_deleted_records.tab')
    lyr = ds.GetLayer(0)
    N2 = 100
    N = N2 * N2
    for n in range(N):
        x = int(n / N2)
        y = n % N2
        lyr.SetSpatialFilterRect(x-0.01,y-0.01,x+0.01,y+0.01)
        if lyr.GetFeatureCount() != 1:
            gdaltest.post_reason('fail')
            return 'fail'
    ds = None

    ogr.GetDriverByName('MapInfo File').DeleteDataSource('tmp/compr_symb_deleted_records.tab')

    return 'success'
Ejemplo n.º 29
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
Ejemplo n.º 30
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'
Ejemplo n.º 31
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'
Ejemplo n.º 32
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'
Ejemplo n.º 33
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()
Ejemplo n.º 34
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 - (9112088.39654255)) <= 0.001 and abs(gcp0.GCPY - -999503.568004833) <= 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["latitude_of_origin",4],PARAMETER["central_meridian",10],PARAMETER["standard_parallel_1",40],PARAMETER["standard_parallel_2",56],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["Meter",1],AXIS["Easting",EAST],AXIS["Northing",NORTH]]'
    assert wkt == expected_wkt, wkt

    cs = ds.GetRasterBand(1).Checksum()
    assert cs == 16025, 'bad checksum'
Ejemplo n.º 35
0
def test_aigrid_online_2():

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/aig/ai_bug_6886.zip', 'ai_bug_6886.zip'):
        pytest.skip()

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

    tst = gdaltest.GDALTest('AIG', 'tmp/cache/ai_bug/ai_bug/hdr.adf', 1, 16018, filename_absolute=1)
    return tst.testOpen()
Ejemplo n.º 36
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()
Ejemplo n.º 37
0
def download_test_data():
    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/pgeo/PGeoTest.zip', 'PGeoTest.zip'):
        pytest.skip("Test data could not be downloaded")

    try:
        os.stat('tmp/cache/Autodesk Test.mdb')
    except OSError:
        try:
            gdaltest.unzip('tmp/cache', 'tmp/cache/PGeoTest.zip')
            try:
                os.stat('tmp/cache/Autodesk Test.mdb')
            except OSError:
                pytest.skip()
        except:
            pytest.skip()

    pgeo_ds = ogr.Open('tmp/cache/Autodesk Test.mdb')
    if pgeo_ds is None:
        pytest.skip('could not open DB. Driver probably misconfigured')

    return pgeo_ds
Ejemplo n.º 38
0
def ogr_openfilegdb_5():

    try:
        shutil.rmtree('tmp/testopenfilegdb.gdb')
    except:
        pass
    try:
        gdaltest.unzip( 'tmp/', 'data/testopenfilegdb.gdb.zip')
    except:
        return 'skip'
    try:
        os.stat('tmp/testopenfilegdb.gdb')
    except:
        return 'skip'

    ds = ogr.Open('tmp/testopenfilegdb.gdb')
    if ds is None:
        gdaltest.post_reason('fail')
        return 'fail'

    return 'success'
Ejemplo n.º 39
0
def ogr_openfilegdb_5():

    try:
        shutil.rmtree('tmp/testopenfilegdb.gdb')
    except:
        pass
    try:
        gdaltest.unzip('tmp/', 'data/testopenfilegdb.gdb.zip')
    except:
        return 'skip'
    try:
        os.stat('tmp/testopenfilegdb.gdb')
    except:
        return 'skip'

    ds = ogr.Open('tmp/testopenfilegdb.gdb')
    if ds is None:
        gdaltest.post_reason('fail')
        return 'fail'

    return 'success'
Ejemplo n.º 40
0
def test_ogr_s57_more_than_255_updates_to_feature():

    if not gdaltest.download_file('https://www.charts.noaa.gov/ENCs/US5ME51M.zip', 'US5ME51M.zip'):
        pytest.skip()

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

    gdal.ErrorReset()
    ds = ogr.Open('tmp/cache/US5ME51M/ENC_ROOT/US5ME51M/US5ME51M.000')
    assert ds is not None
    assert gdal.GetLastErrorMsg() == ''
Ejemplo n.º 41
0
def test_ogr_shape_sbn_1():

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

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

    ds = ogr.Open('tmp/cache/CochitiDamShapeFiles')
    for i in range(ds.GetLayerCount()):
        lyr = ds.GetLayer(i)
        search_all_features(lyr)
Ejemplo n.º 42
0
def test_ogr_ntf_1():

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

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

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

    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])
        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('STRATEGI_POINT')
    feat = lyr.GetNextFeature()
    assert feat.GetGeometryRef().ExportToWkt() == 'POINT (222904 127850)'

    ds.Destroy()
Ejemplo n.º 43
0
def loslas_online_1():

    if not gdaltest.download_file('http://www.ngs.noaa.gov/PC_PROD/NADCON/NADCON.zip', 'NADCON.zip'):
        return 'skip'

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

    try:
        gdaltest.unzip('tmp/cache/NADCON', 'tmp/cache/NADCON.zip')
        os.stat('tmp/cache/NADCON/nadcon.jar')
        gdaltest.unzip('tmp/cache/NADCON', 'tmp/cache/NADCON/nadcon.jar')
        os.stat('tmp/cache/NADCON/grids/wyhpgn.los')
    except OSError:
        return 'skip'

    tst = gdaltest.GDALTest('LOSLAS', 'tmp/cache/NADCON/grids/wyhpgn.los', 1, 0, filename_absolute=1)
    gt = (-111.625, 0.25, 0.0, 45.625, 0.0, -0.25)
    stats = (-0.0080000003799796, 0.031125999987125001, 0.0093017323318172005, 0.0075646520354096004)
    return tst.testOpen(check_gt=gt, check_stat=stats, check_prj='WGS84')
Ejemplo n.º 44
0
def test_ogr_ntf_1():

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

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

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

    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])
        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('STRATEGI_POINT')
    feat = lyr.GetNextFeature()
    assert feat.GetGeometryRef().ExportToWkt() == 'POINT (222904 127850)'

    ds.Destroy()
Ejemplo n.º 45
0
def ogr_fgdb_15():
    if ogrtest.fgdb_drv is None:
        return 'skip'

    try:
        shutil.rmtree('tmp/test3005.gdb')
    except:
        pass
    gdaltest.unzip( 'tmp', 'data/test3005.gdb.zip')
    ds = ogr.Open('tmp/test3005.gdb')
    lyr = ds.GetLayer(0)
    got_wkt = lyr.GetSpatialRef().ExportToWkt()
    sr = osr.SpatialReference()
    sr.ImportFromEPSG(3005)
    expected_wkt = sr.ExportToWkt()
    if got_wkt != expected_wkt:
        gdaltest.post_reason('fail')
        print(got_wkt)
        print(expected_wkt)
        return 'fail'
    ds = None

    return 'success'
Ejemplo n.º 46
0
def download_inspire_schemas(target_dir = '.', \
                             target_subdir = 'inspire_schemas',
                             force_download = False):

    if not download_ogc_schemas(target_dir=target_dir,
                                force_download=force_download):
        return False

    try:
        os.stat(target_dir + '/' + 'inspire_common_1.0.1.zip')
    except:
        gdaltest.download_file(
            'http://inspire.ec.europa.eu/schemas/common/1.0.1.zip',
            target_dir + '/' + 'inspire_common_1.0.1.zip',
            base_dir='.',
            force_download=force_download)

    try:
        os.stat(target_dir + '/' + 'inspire_vs_1.0.1.zip')
    except:
        gdaltest.download_file(
            'http://inspire.ec.europa.eu/schemas/inspire_vs/1.0.1.zip',
            target_dir + '/' + 'inspire_vs_1.0.1.zip',
            base_dir='.',
            force_download=force_download)

    for subdir in [
            '', '/common', '/inspire_vs', '/inspire_dls', '/inspire_dls/1.0'
    ]:
        try:
            os.mkdir(target_dir + '/' + target_subdir + subdir)
        except:
            pass

    try:
        os.stat(target_dir + '/' + target_subdir + '/common/1.0')
    except:
        gdaltest.unzip(target_dir + '/' + target_subdir + '/common',
                       target_dir + '/' + 'inspire_common_1.0.1.zip')
        try:
            os.stat(target_dir + '/' + target_subdir + '/common/1.0')
        except:
            print('Cannot unzip inspire_common_1.0.1.zip')
            return False

    try:
        os.stat(target_dir + '/' + target_subdir + '/inspire_vs/1.0')
    except:
        gdaltest.unzip(target_dir + '/' + target_subdir + '/inspire_vs',
                       target_dir + '/' + 'inspire_vs_1.0.1.zip')
        try:
            os.stat(target_dir + '/' + target_subdir + '/inspire_vs/1.0')
        except:
            print('Cannot unzip inspire_vs_1.0.1.zip')
            return False

    try:
        os.stat(target_dir + '/' + target_subdir +
                '/inspire_dls/1.0/inspire_dls.xsd')
    except:
        gdaltest.download_file(
            'http://inspire.ec.europa.eu/schemas/inspire_dls/1.0/inspire_dls.xsd',
            target_dir + '/' + target_subdir +
            '/inspire_dls/1.0/inspire_dls.xsd',
            base_dir='.',
            force_download=force_download)

    try:
        os.stat(target_dir + '/' + target_subdir + '/oi/3.0/Orthoimagery.xsd')
    except:
        try:
            os.makedirs(target_dir + '/' + target_subdir + '/oi/3.0')
        except:
            pass
        gdaltest.download_file(
            'http://inspire.ec.europa.eu/schemas/oi/3.0/Orthoimagery.xsd',
            target_dir + '/' + target_subdir + '/oi/3.0/Orthoimagery.xsd',
            base_dir='.',
            force_download=force_download)
        gdaltest.download_file('http://portele.de/ShapeChangeAppinfo.xsd',
                               target_dir + '/' + target_subdir +
                               '/oi/3.0/ShapeChangeAppinfo.xsd',
                               base_dir='.',
                               force_download=force_download)

    try:
        os.stat(target_dir + '/' + target_subdir + '/base/3.3/BaseTypes.xsd')
    except:
        try:
            os.makedirs(target_dir + '/' + target_subdir + '/base/3.3')
        except:
            pass
        gdaltest.download_file(
            'http://inspire.ec.europa.eu/schemas/base/3.3/BaseTypes.xsd',
            target_dir + '/' + target_subdir + '/base/3.3/BaseTypes.xsd',
            base_dir='.',
            force_download=force_download)

    transform_inspire_abs_links_to_ref_links(target_dir + '/' + target_subdir)

    return True
Ejemplo n.º 47
0
def ozi_online_1():

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

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

    ds = gdal.Open('tmp/cache/Europe 2001_OZF.map')
    if ds is None:
        return 'fail'

    if False:
        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):
            if abs(gt[i] - expected_gt[i]) > 1e-7:
                gdaltest.post_reason('bad geotransform')
                print(gt)
                print(expected_gt)
                return 'fail'

    else:
        gcps = ds.GetGCPs()

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

        gcp0 = gcps[0]
        if gcp0.GCPPixel != 61 or gcp0.GCPLine != 436 \
                or abs(gcp0.GCPX- (-1653990.4525324)) > 0.001 \
                or abs(gcp0.GCPY- 6950885.0402214) > 0.001:
            gdaltest.post_reason( 'did not get expected gcp.')
            print(gcp0)
            return 'fail'

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



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

    return 'success'
Ejemplo n.º 48
0
def ozi_online_1():

    if not gdaltest.download_file(
            'http://www.oziexplorer2.com/maps/Europe2001_setup.exe',
            'Europe2001_setup.exe'):
        return '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:
                return 'skip'
        except:
            return 'skip'

    ds = gdal.Open('tmp/cache/Europe 2001_OZF.map')
    if ds is None:
        return 'fail'

    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):
            if abs(gt[i] - expected_gt[i]) > 1e-7:
                gdaltest.post_reason('bad geotransform')
                print(gt)
                print(expected_gt)
                return 'fail'

    else:
        gcps = ds.GetGCPs()

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

        gcp0 = gcps[0]
        if gcp0.GCPPixel != 61 or gcp0.GCPLine != 436 \
                or abs(gcp0.GCPX - (-1653990.4525324)) > 0.001 \
                or abs(gcp0.GCPY - 6950885.0402214) > 0.001:
            gdaltest.post_reason('did not get expected gcp.')
            print(gcp0)
            return 'fail'

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

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

    return 'success'
Ejemplo n.º 49
0
def ogr_pgeo_1(tested_driver = 'PGeo', other_driver = 'MDB'):

    ogrtest.pgeo_ds = None

    try:
        ogrtest.other_driver = ogr.GetDriverByName(other_driver)
    except:
        ogrtest.other_driver = None
    if ogrtest.other_driver is not None:
        print('Unregistering %s driver' % ogrtest.other_driver.GetName())
        ogrtest.other_driver.Deregister()
        if other_driver == 'PGeo':
            # Re-register Geomedia and WALK at the end, *after* MDB
            geomedia_driver = ogr.GetDriverByName('Geomedia')
            if geomedia_driver is not None:
                geomedia_driver.Deregister()
                geomedia_driver.Register()
            walk_driver = ogr.GetDriverByName('WALK')
            if walk_driver is not None:
                walk_driver.Deregister()
                walk_driver.Register()

    try:
        drv = ogr.GetDriverByName(tested_driver)
    except:
        drv = None

    if drv is None:
        return 'skip'

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/pgeo/PGeoTest.zip', 'PGeoTest.zip'):
        return 'skip'

    try:
        os.stat('tmp/cache/Autodesk Test.mdb')
    except:
        try:
            gdaltest.unzip( 'tmp/cache', 'tmp/cache/PGeoTest.zip')
            try:
                os.stat('tmp/cache/Autodesk Test.mdb')
            except:
                return 'skip'
        except:
            return 'skip'
            
    ogrtest.pgeo_ds = ogr.Open('tmp/cache/Autodesk Test.mdb')
    if ogrtest.pgeo_ds is None:
        gdaltest.post_reason('could not open DB. Driver probably misconfigured')
        return 'skip'
    
    if ogrtest.pgeo_ds.GetLayerCount() != 3:
        gdaltest.post_reason('did not get expected layer count')
        return 'fail'
        
    lyr = ogrtest.pgeo_ds.GetLayer(0)
    feat = lyr.GetNextFeature()
    if feat.GetField('OBJECTID') != 1 or \
       feat.GetField('IDNUM') != 9424 or \
       feat.GetField('OWNER') != 'City':
        gdaltest.post_reason('did not get expected attributes')
        feat.DumpReadable()
        return 'fail'
        
    if ogrtest.check_feature_geometry(feat,'LINESTRING (1910941.703951031 445833.57942859828 0,1910947.927691862 445786.43811868131 0)', max_error = 0.0000001) != 0:
        gdaltest.post_reason('did not get expected geometry')
        feat.DumpReadable()
        return 'fail'

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

    return 'success'
Ejemplo n.º 50
0
def ogr_ogdi_1():

    ogrtest.ogdi_ds = None

    try:
        drv = ogr.GetDriverByName('OGDI')
    except:
        drv = None
   
    if drv is None:
        return 'skip'

    if not gdaltest.download_file('http://freefr.dl.sourceforge.net/project/ogdi/OGDI_Test_Suite/3.1/ogdits-3.1.0.zip', 'ogdits-3.1.0.zip'):
        return 'skip'

    try:
        os.stat('tmp/cache/ogdits-3.1')
    except:
        try:
            gdaltest.unzip( 'tmp/cache', 'tmp/cache/ogdits-3.1.0.zip')
            try:
                os.stat('tmp/cache/ogdits-3.1')
            except:
                return 'skip'
        except:
            return 'skip'

    url_name ='gltp:/vrf/' + os.getcwd()+ '/tmp/cache/ogdits-3.1/data/vpf/vm2alv2/texash'

    ds = ogr.Open(url_name)
    ogrtest.ogdi_ds = ds
    if ds is None:
        gdaltest.post_reason('cannot open ' + url_name)
        return 'fail'
    if ds.GetLayerCount() != 57:
        print(ds.GetLayerCount())
        gdaltest.post_reason('did not get expected layer count')
        return 'fail'

    layers = [ ('libref@libref(*)_line', ogr.wkbLineString, 15),
               ('libreft@libref(*)_text', ogr.wkbPoint, 4),
               ('markersp@bnd(*)_point', ogr.wkbPoint, 40),
               ('polbnda@bnd(*)_area', ogr.wkbPolygon, 6)]

    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('WGS 84') == -1:
        #        return 'fail'

    lyr = ds.GetLayerByName('libref@libref(*)_line')
    feat = lyr.GetNextFeature()

    wkt = 'LINESTRING (-97.570159912109375 31.242000579833984,-97.569938659667969 31.242116928100586,-97.562828063964844 31.245765686035156,-97.558868408203125 31.247797012329102,-97.555778503417969 31.249361038208008,-97.55413818359375 31.250171661376953)'
    ref_geom = ogr.CreateGeometryFromWkt(wkt)

    if ogrtest.check_feature_geometry(feat, ref_geom) != 0:
        print(feat.GetGeometryRef().ExportToWkt())
        return 'fail'

    return 'success'
Ejemplo n.º 51
0
def ogr_pgeo_1(tested_driver = 'PGeo', other_driver = 'MDB'):

    ogrtest.pgeo_ds = None

    try:
        ogrtest.other_driver = ogr.GetDriverByName(other_driver)
    except:
        ogrtest.other_driver = None
    if ogrtest.other_driver is not None:
        print('Unregistering %s driver' % ogrtest.other_driver.GetName())
        ogrtest.other_driver.Deregister()
        if other_driver == 'PGeo':
            # Re-register Geomedia at the end, *after* MDB
            geomedia_driver = ogr.GetDriverByName('Geomedia')
            if geomedia_driver is not None:
                geomedia_driver.Deregister()
                geomedia_driver.Register()

    try:
        drv = ogr.GetDriverByName(tested_driver)
    except:
        drv = None

    if drv is None:
        return 'skip'

    if not gdaltest.download_file('http://download.osgeo.org/gdal/data/pgeo/PGeoTest.zip', 'PGeoTest.zip'):
        return 'skip'

    try:
        os.stat('tmp/cache/Autodesk Test.mdb')
    except:
        try:
            gdaltest.unzip( 'tmp/cache', 'tmp/cache/PGeoTest.zip')
            try:
                os.stat('tmp/cache/Autodesk Test.mdb')
            except:
                return 'skip'
        except:
            return 'skip'
            
    ogrtest.pgeo_ds = ogr.Open('tmp/cache/Autodesk Test.mdb')
    if ogrtest.pgeo_ds is None:
        gdaltest.post_reason('could not open DB. Driver probably misconfigured')
        return 'skip'
    
    if ogrtest.pgeo_ds.GetLayerCount() != 3:
        gdaltest.post_reason('did not get expected layer count')
        return 'fail'
        
    lyr = ogrtest.pgeo_ds.GetLayer(0)
    feat = lyr.GetNextFeature()
    if feat.GetField('OBJECTID') != 1 or \
       feat.GetField('IDNUM') != 9424 or \
       feat.GetField('OWNER') != 'City':
        gdaltest.post_reason('did not get expected attributes')
        feat.DumpReadable()
        return 'fail'
        
    if ogrtest.check_feature_geometry(feat,'LINESTRING (1910941.703951031 445833.57942859828 0,1910947.927691862 445786.43811868131 0)', max_error = 0.0000001) != 0:
        gdaltest.post_reason('did not get expected geometry')
        feat.DumpReadable()
        return 'fail'

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

    return 'success'
Ejemplo n.º 52
0
def download_inspire_schemas(target_dir = '.', \
                             target_subdir = 'inspire_schemas',
                             force_download = False):

    if not download_ogc_schemas(target_dir = target_dir, force_download = force_download):
        return False

    try:
        os.stat(target_dir + '/' + 'inspire_common_1.0.1.zip')
    except:
        gdaltest.download_file('http://inspire.ec.europa.eu/schemas/common/1.0.1.zip', target_dir + '/' + 'inspire_common_1.0.1.zip', base_dir = '.', force_download = force_download)

    try:
        os.stat(target_dir + '/' + 'inspire_vs_1.0.1.zip')
    except:
        gdaltest.download_file('http://inspire.ec.europa.eu/schemas/inspire_vs/1.0.1.zip', target_dir + '/' + 'inspire_vs_1.0.1.zip', base_dir = '.', force_download = force_download)

    for subdir in [ '', '/common', '/inspire_vs', '/inspire_dls', '/inspire_dls/1.0']:
        try:
            os.mkdir(target_dir + '/' + target_subdir + subdir)
        except:
            pass

    try:
        os.stat(target_dir + '/' + target_subdir + '/common/1.0')
    except:
        gdaltest.unzip(target_dir + '/' + target_subdir + '/common', target_dir + '/' + 'inspire_common_1.0.1.zip')
        try:
            os.stat(target_dir + '/' + target_subdir + '/common/1.0')
        except:
            print('Cannot unzip inspire_common_1.0.1.zip')
            return False

    try:
        os.stat(target_dir + '/' + target_subdir + '/inspire_vs/1.0')
    except:
        gdaltest.unzip(target_dir + '/' + target_subdir + '/inspire_vs', target_dir + '/' + 'inspire_vs_1.0.1.zip')
        try:
            os.stat(target_dir + '/' + target_subdir + '/inspire_vs/1.0')
        except:
            print('Cannot unzip inspire_vs_1.0.1.zip')
            return False

    try:
        os.stat(target_dir + '/' + target_subdir + '/inspire_dls/1.0/inspire_dls.xsd')
    except:
        gdaltest.download_file('http://inspire.ec.europa.eu/schemas/inspire_dls/1.0/inspire_dls.xsd', target_dir + '/' + target_subdir + '/inspire_dls/1.0/inspire_dls.xsd', base_dir = '.', force_download = force_download)

    try:
        os.stat(target_dir + '/' + target_subdir + '/oi/3.0/Orthoimagery.xsd')
    except:
        try:
            os.makedirs(target_dir + '/' + target_subdir + '/oi/3.0')
        except:
            pass
        gdaltest.download_file('http://inspire.ec.europa.eu/schemas/oi/3.0/Orthoimagery.xsd', target_dir + '/' + target_subdir + '/oi/3.0/Orthoimagery.xsd', base_dir = '.', force_download = force_download)
        gdaltest.download_file('http://portele.de/ShapeChangeAppinfo.xsd', target_dir + '/' + target_subdir + '/oi/3.0/ShapeChangeAppinfo.xsd', base_dir = '.', force_download = force_download)

    try:
        os.stat(target_dir + '/' + target_subdir + '/base/3.3/BaseTypes.xsd')
    except:
        try:
            os.makedirs(target_dir + '/' + target_subdir + '/base/3.3')
        except:
            pass
        gdaltest.download_file('http://inspire.ec.europa.eu/schemas/base/3.3/BaseTypes.xsd', target_dir + '/' + target_subdir + '/base/3.3/BaseTypes.xsd', base_dir = '.', force_download = force_download)

    transform_inspire_abs_links_to_ref_links(target_dir + '/' + target_subdir)

    return True
Ejemplo n.º 53
0
def ogr_ogdi_1():

    ogrtest.ogdi_ds = None

    try:
        drv = ogr.GetDriverByName('OGDI')
    except:
        drv = None

    if drv is None:
        return 'skip'

    if not gdaltest.download_file(
            'http://freefr.dl.sourceforge.net/project/ogdi/OGDI_Test_Suite/3.1/ogdits-3.1.0.zip',
            'ogdits-3.1.0.zip'):
        return 'skip'

    try:
        os.stat('tmp/cache/ogdits-3.1')
    except:
        try:
            gdaltest.unzip('tmp/cache', 'tmp/cache/ogdits-3.1.0.zip')
            try:
                os.stat('tmp/cache/ogdits-3.1')
            except:
                return 'skip'
        except:
            return 'skip'

    url_name = 'gltp:/vrf/' + os.getcwd(
    ) + '/tmp/cache/ogdits-3.1/data/vpf/vm2alv2/texash'

    ds = ogr.Open(url_name)
    ogrtest.ogdi_ds = ds
    if ds is None:
        gdaltest.post_reason('cannot open ' + url_name)
        return 'fail'
    if ds.GetLayerCount() != 57:
        print(ds.GetLayerCount())
        gdaltest.post_reason('did not get expected layer count')
        return 'fail'

    layers = [('libref@libref(*)_line', ogr.wkbLineString, 15),
              ('libreft@libref(*)_text', ogr.wkbPoint, 4),
              ('markersp@bnd(*)_point', ogr.wkbPoint, 40),
              ('polbnda@bnd(*)_area', ogr.wkbPolygon, 6)]

    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('WGS 84') == -1:
        #        return 'fail'

    lyr = ds.GetLayerByName('libref@libref(*)_line')
    feat = lyr.GetNextFeature()

    wkt = 'LINESTRING (-97.570159912109375 31.242000579833984,-97.569938659667969 31.242116928100586,-97.562828063964844 31.245765686035156,-97.558868408203125 31.247797012329102,-97.555778503417969 31.249361038208008,-97.55413818359375 31.250171661376953)'
    ref_geom = ogr.CreateGeometryFromWkt(wkt)

    if ogrtest.check_feature_geometry(feat, ref_geom) != 0:
        print(feat.GetGeometryRef().ExportToWkt())
        return 'fail'

    return 'success'