예제 #1
0
파일: warp.py 프로젝트: Joe-xXx/gdal
def warp_19_internal(size, datatype, resampling_string):

    ds = gdaltest.tiff_drv.Create('tmp/test.tif', size, size, 1, datatype)
    ds.SetGeoTransform( (10,5,0,30,0,-5) )
    ds.SetProjection('GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]')
    ds.GetRasterBand(1).Fill(10.1, 20.1)
    ds = None

    gdaltest.runexternal(test_cli_utilities.get_gdalwarp_path() + ' -r ' + resampling_string + ' tmp/test.tif tmp/testwarp.tif')

    ref_ds = gdal.Open( 'tmp/test.tif' )
    ds = gdal.Open( 'tmp/testwarp.tif' )
    checksum = ds.GetRasterBand(1).Checksum()
    checksum_ref = ref_ds.GetRasterBand(1).Checksum()
    ds = None
    ref_ds = None

    gdaltest.tiff_drv.Delete('tmp/testwarp.tif')

    if checksum != checksum_ref:
        print('got %d, expected %d' % (checksum, checksum_ref))
        gdaltest.post_reason('Result different from source')
        return 'fail'

    gdaltest.tiff_drv.Delete('tmp/test.tif')

    return 'success'
예제 #2
0
def test_gdal_translate_38():
    if test_cli_utilities.get_gdal_translate_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -q -of hfa tmp/test_gdal_translate_37.tif tmp/test_gdal_translate_38.img')

    ds = gdal.Open('tmp/test_gdal_translate_38.img')
    if ds is None:
        return 'fail'

    rat = ds.GetRasterBand(1).GetDefaultRAT()
    if not rat:
        gdaltest.post_reason('Did not get RAT')
        return 'fail'

    if not rat.GetRowCount() == 256:
        gdaltest.post_reason('RAT has incorrect row count')
        return 'fail'

    if rat.GetTableType() != 0:
        gdaltest.post_reason('RAT not thematic')
        return 'fail'
    rat = None
    ds = None

    return 'success'
예제 #3
0
def test_gdal_translate_26():
    if test_cli_utilities.get_gdal_translate_path() is None:
        return 'skip'

    f = open('tmp/test_gdal_translate_26.xyz', 'wb')
    f.write("""X Y Z
0 0 -999
1 0 10
0 1 15
1 1 20""".encode('ascii'))
    f.close()
    gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -a_nodata -999 -stats tmp/test_gdal_translate_26.xyz tmp/test_gdal_translate_26.tif')

    ds = gdal.Open('tmp/test_gdal_translate_26.tif')
    if ds.GetRasterBand(1).GetMinimum() != 10:
        gdaltest.post_reason('failure')
        print(ds.GetRasterBand(1).GetMinimum())
        return 'fail'
    if ds.GetRasterBand(1).GetNoDataValue() != -999:
        gdaltest.post_reason('failure')
        print(ds.GetRasterBand(1).GetNoDataValue())
        return 'fail'

    ds = None

    return 'success'
예제 #4
0
def test_gdalbuildvrt_2():
    if test_cli_utilities.get_gdalbuildvrt_path() is None:
        pytest.skip()
    if test_cli_utilities.get_gdaltindex_path() is None:
        pytest.skip()

    try:
        os.remove('tmp/tileindex.shp')
    except OSError:
        pass
    try:
        os.remove('tmp/tileindex.dbf')
    except OSError:
        pass
    try:
        os.remove('tmp/tileindex.shx')
    except OSError:
        pass
    try:
        os.remove('tmp/mosaic.vrt')
    except OSError:
        pass

    gdaltest.runexternal(test_cli_utilities.get_gdaltindex_path() + ' tmp/tileindex.shp tmp/gdalbuildvrt1.tif tmp/gdalbuildvrt2.tif tmp/gdalbuildvrt3.tif tmp/gdalbuildvrt4.tif')

    gdaltest.runexternal(test_cli_utilities.get_gdalbuildvrt_path() + ' tmp/mosaic.vrt tmp/tileindex.shp')

    return gdalbuildvrt_check()
예제 #5
0
def test_gdal_translate_19():
    if test_cli_utilities.get_gdal_translate_path() is None:
        return 'skip'

    ds = gdal.GetDriverByName('GTiff').Create('tmp/test_gdal_translate_19_src.tif', 1, 1, 2)
    ct = gdal.ColorTable()
    ct.SetColorEntry(127, (1, 2, 3, 255))
    ds.GetRasterBand(1).SetRasterColorTable(ct)
    ds.GetRasterBand(1).Fill(127)
    ds.GetRasterBand(2).Fill(250)
    ds = None

    gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -expand rgba tmp/test_gdal_translate_19_src.tif tmp/test_gdal_translate_19_dst.tif')

    ds = gdal.Open('tmp/test_gdal_translate_19_dst.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).Checksum() != 1:
        gdaltest.post_reason('Bad checksum for band 1')
        return 'fail'
    if ds.GetRasterBand(2).Checksum() != 2:
        gdaltest.post_reason('Bad checksum for band 2')
        return 'fail'
    if ds.GetRasterBand(3).Checksum() != 3:
        gdaltest.post_reason('Bad checksum for band 3')
        return 'fail'
    if ds.GetRasterBand(4).Checksum() != 250 % 7:
        gdaltest.post_reason('Bad checksum for band 4')
        return 'fail'

    ds = None

    return 'success'
예제 #6
0
def test_gdalbuildvrt_9():
    if test_cli_utilities.get_gdalbuildvrt_path() is None:
        return "skip"

    gdaltest.runexternal(
        test_cli_utilities.get_gdalbuildvrt_path()
        + " -te 1 46 5 50 tmp/mosaic2.vrt tmp/gdalbuildvrt1.tif tmp/gdalbuildvrt2.tif tmp/gdalbuildvrt3.tif tmp/gdalbuildvrt4.tif"
    )

    ds = gdal.Open("tmp/mosaic2.vrt")

    gt = ds.GetGeoTransform()
    expected_gt = [1, 0.1, 0, 50, 0, -0.1]
    for i in range(6):
        if abs(gt[i] - expected_gt[i] > 1e-5):
            gdaltest.post_reason("Expected : %s\nGot : %s" % (expected_gt, gt))
            return "fail"

    if ds.RasterXSize != 40 or ds.RasterYSize != 40:
        gdaltest.post_reason("Wrong raster dimensions : %d x %d" % (ds.RasterXSize, ds.RasterYSize))
        return "fail"

    gdaltest.runexternal(test_cli_utilities.get_gdalbuildvrt_path() + " -te 2 47 4 49 tmp/mosaic.vrt tmp/mosaic2.vrt")

    return test_gdalbuildvrt_check()
예제 #7
0
def test_gdalbuildvrt_14():
    if test_cli_utilities.get_gdalbuildvrt_path() is None:
        return "skip"
    if test_cli_utilities.get_gdal_translate_path() is None:
        return "skip"

    gdaltest.runexternal(
        test_cli_utilities.get_gdalbuildvrt_path()
        + " tmp/test_gdalbuildvrt_14.vrt ../gcore/data/byte.tif -r cubic -tr 30 30"
    )

    gdaltest.runexternal(
        test_cli_utilities.get_gdal_translate_path()
        + " -of VRT ../gcore/data/byte.tif tmp/test_gdalbuildvrt_14_ref.vrt -r cubic -outsize 40 40"
    )

    ds = gdal.Open("tmp/test_gdalbuildvrt_14.vrt")
    ds_ref = gdal.Open("tmp/test_gdalbuildvrt_14_ref.vrt")
    cs = ds.GetRasterBand(1).Checksum()
    cs_ref = ds_ref.GetRasterBand(1).Checksum()
    ds = None
    ds_ref = None

    if cs != cs_ref:
        gdaltest.post_reason("fail")
        print(cs)
        print(cs_ref)
        return "fail"

    return "success"
예제 #8
0
파일: ogr_osm.py 프로젝트: afarnham/gdal
def ogr_osm_3(options = None):

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

    import test_cli_utilities
    if test_cli_utilities.get_ogr2ogr_path() is None:
        return 'skip'

    try:
        os.stat('tmp/ogr_osm_3')
        ogr.GetDriverByName('ESRI Shapefile').DeleteDataSource('tmp/ogr_osm_3')
    except:
        pass

    if options is not None:
        options = ' ' + options
    else:
        options = ''
    gdaltest.runexternal(test_cli_utilities.get_ogr2ogr_path() + ' tmp/ogr_osm_3 data/test.pbf points lines polygons multipolygons multilinestrings -progress' + options)

    ret = ogr_osm_1('tmp/ogr_osm_3')

    ogr.GetDriverByName('ESRI Shapefile').DeleteDataSource('tmp/ogr_osm_3')

    return ret
예제 #9
0
def test_gdalbuildvrt_6():
    if test_cli_utilities.get_gdalbuildvrt_path() is None:
        return "skip"

    gdaltest.runexternal(
        test_cli_utilities.get_gdalbuildvrt_path()
        + " -separate tmp/stacked.vrt tmp/gdalbuildvrt1.tif tmp/gdalbuildvrt2.tif tmp/gdalbuildvrt3.tif tmp/gdalbuildvrt4.tif"
    )

    ds = gdal.Open("tmp/stacked.vrt")
    if ds.GetProjectionRef().find("WGS 84") == -1:
        gdaltest.post_reason("Expected WGS 84\nGot : %s" % (ds.GetProjectionRef()))
        return "fail"

    gt = ds.GetGeoTransform()
    expected_gt = [2, 0.1, 0, 49, 0, -0.1]
    for i in range(6):
        if abs(gt[i] - expected_gt[i] > 1e-5):
            gdaltest.post_reason("Expected : %s\nGot : %s" % (expected_gt, gt))
            return "fail"

    if ds.RasterXSize != 20 or ds.RasterYSize != 20:
        gdaltest.post_reason("Wrong raster dimensions : %d x %d" % (ds.RasterXSize, ds.RasterYSize))
        return "fail"

    if ds.RasterCount != 4:
        gdaltest.post_reason("Wrong raster count : %d " % (ds.RasterCount))
        return "fail"

    if ds.GetRasterBand(1).Checksum() != 0:
        gdaltest.post_reason("Wrong checksum")
        return "fail"

    return "success"
예제 #10
0
def test_gdalinfo_32():
    if test_cli_utilities.get_gdalinfo_path() is None:
        return 'skip'

    try:
        os.remove('../gcore/data/byte.tif.aux.xml')
    except:
        pass
    
    ret = gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' -json ../gcore/data/byte.tif')
    ret = json.loads(ret)
    if '' in ret['bands'][0]['metadata']:
        gdaltest.post_reason( 'got wrong minimum.' )
        print(ret)
        return 'fail'

    ret = gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' -json -stats ../gcore/data/byte.tif')
    ret = json.loads(ret)
    if ret['bands'][0]['metadata']['']['STATISTICS_MINIMUM'] != '74':
        gdaltest.post_reason( 'got wrong minimum (2).' )
        print(ret)
        return 'fail'

    # We will blow an exception if the file does not exist now!
    os.remove('../gcore/data/byte.tif.aux.xml')
    
    return 'success'
예제 #11
0
def test_ogr2ogr_py_7():

    import ogr_pg

    script_path = test_py_scripts.get_py_script('ogr2ogr')
    if script_path is None:
        return 'skip'
    if test_cli_utilities.get_ogrinfo_path() is None:
        return 'skip'

    import gdal
    ogr_pg.ogr_pg_1()
    if gdaltest.pg_ds is None:
        return 'skip'
    gdaltest.pg_ds.Destroy()

    gdaltest.runexternal(test_cli_utilities.get_ogrinfo_path() + ' PG:"' + gdaltest.pg_connection_string + '" -sql "DELLAYER:tpoly"')

    test_py_scripts.run_py_script(script_path, 'ogr2ogr', '-f PostgreSQL PG:"' + gdaltest.pg_connection_string + '" ../ogr/data/poly.shp -nln tpoly -gt 1')

    ds = ogr.Open('PG:' + gdaltest.pg_connection_string)
    if ds is None or ds.GetLayerByName('tpoly').GetFeatureCount() != 10:
        return 'fail'
    ds.Destroy()

    gdaltest.runexternal(test_cli_utilities.get_ogrinfo_path() + ' PG:"' + gdaltest.pg_connection_string + '" -sql "DELLAYER:tpoly"')

    return 'success'
예제 #12
0
def test_ogr2ogr_py_23():
    script_path = test_py_scripts.get_py_script('ogr2ogr')
    if script_path is None:
        return 'skip'
    if test_cli_utilities.get_ogr2ogr_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_ogr2ogr_path() +
        ' -f "MapInfo File" tmp/testogr2ogr23.mif ../utilities/data/dataforogr2ogr21.csv ' +
        '-sql "SELECT comment, name FROM dataforogr2ogr21" -select comment,name -nlt POINT')
    ds = ogr.Open('tmp/testogr2ogr23.mif')

    if ds is None:
        return 'fail'
    layer_defn = ds.GetLayer(0).GetLayerDefn()
    lyr = ds.GetLayer(0)
    feat = lyr.GetNextFeature()
    if feat.GetFieldAsString('name') != 'NAME' or \
       feat.GetFieldAsString('comment') != 'COMMENT':
        print(feat.GetFieldAsString('name'))
        print(feat.GetFieldAsString('comment'))
        ds.Destroy()
        ogr.GetDriverByName('MapInfo File').DeleteDataSource('tmp/testogr2ogr23.mif')
        return 'fail'

    ds.Destroy()
    ogr.GetDriverByName('MapInfo File').DeleteDataSource('tmp/testogr2ogr23.mif')

    return 'success'
예제 #13
0
def test_gdalinfo_35():
    if test_cli_utilities.get_gdalinfo_path() is None:
        return 'skip'

    try:
        os.remove('../gcore/data/byte.tif.aux.xml')
    except:
        pass
    
    ret = gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' -json ../gcore/data/byte.tif')
    ret = json.loads(ret)
    if 'histogram' in ret['bands'][0]:
        gdaltest.post_reason( 'did not expect histogram.' )
        print(ret)
        return 'fail'

    ret = gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' -json -hist ../gcore/data/byte.tif')
    ret = json.loads(ret)
    if ret['bands'][0]['histogram']['buckets'] != [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 37, 0, 0, 0, 0, 0, 0, 0, 57, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 ]:
        gdaltest.post_reason( 'did not get expected histogram.' )
        print(ret)
        return 'fail'

    # We will blow an exception if the file does not exist now!
    os.remove('../gcore/data/byte.tif.aux.xml')
    
    return 'success'
예제 #14
0
def test_gdal_translate_8():
    if test_cli_utilities.get_gdal_translate_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -a_srs EPSG:26711 -gcp 0 0  440720.000 3751320.000 -gcp 20 0 441920.000 3751320.000 -gcp 20 20 441920.000 3750120.000 0 -gcp 0 20 440720.000 3750120.000 ../gcore/data/byte.tif tmp/test8.tif')

    ds = gdal.Open('tmp/test8.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).Checksum() != 4672:
        gdaltest.post_reason('Bad checksum')
        return 'fail'

    gcps = ds.GetGCPs()
    if len(gcps) != 4:
        gdaltest.post_reason('GCP count wrong.')
        return 'fail'

    if ds.GetGCPProjection().find('26711') == -1:
        gdaltest.post_reason('Bad GCP projection.')
        return 'fail'

    ds = None

    return 'success'
예제 #15
0
def test_gdaladdo_3():
    if test_cli_utilities.get_gdaladdo_path() is None:
        return 'skip'

    shutil.copyfile( '../gcore/data/nodata_byte.tif', 'tmp/test_gdaladdo_3.tif' )

    gdaltest.runexternal(test_cli_utilities.get_gdaladdo_path() + ' -ro tmp/test_gdaladdo_3.tif 2')

    ds = gdal.Open('tmp/test_gdaladdo_3.tif')
    cs = ds.GetRasterBand(1).GetOverview(0).Checksum()
    exp_cs = 1152

    if cs != exp_cs:
        gdaltest.post_reason( 'got wrong overview checksum.' )
        print(exp_cs, cs)
        return 'fail'

    ds = None

    try:
        os.stat('tmp/test_gdaladdo_3.tif.ovr')
    except:
        gdaltest.post_reason( 'no external overview.' )
        return 'fail'

    return 'success'
예제 #16
0
def test_gdal_contour_2():
    if test_cli_utilities.get_gdal_contour_path() is None:
        return 'skip'

    try:
        os.remove('tmp/contour.shp')
    except:
        pass
    try:
        os.remove('tmp/contour.dbf')
    except:
        pass
    try:
        os.remove('tmp/contour.shx')
    except:
        pass

    # put -3d just after -fl to test #2793
    gdaltest.runexternal(test_cli_utilities.get_gdal_contour_path() + ' -a elev -fl 10 20 25 -3d tmp/gdal_contour.tif tmp/contour.shp')

    size = 160
    precision = 1. / size

    ds = ogr.Open('tmp/contour.shp')

    expected_envelopes = [ [ 1.25, 1.75, 49.25, 49.75 ],
                           [ 1.25+0.125, 1.75-0.125, 49.25+0.125, 49.75-0.125 ],
                           [ 1.25+0.125+0.0625, 1.75-0.125-0.0625, 49.25+0.125+0.0625, 49.75-0.125-0.0625 ] ]
    expected_height = [ 10, 20, 25 ]

    lyr = ds.ExecuteSQL("select * from contour order by elev asc")

    if lyr.GetFeatureCount() != len(expected_envelopes):
        print('Got %d features. Expected %d' % (lyr.GetFeatureCount(), len(expected_envelopes)))
        return 'fail'

    i = 0
    feat = lyr.GetNextFeature()
    while feat is not None:
        if feat.GetGeometryRef().GetZ(0) != expected_height[i]:
            print('Got %f as z. Expected %f' % (feat.GetGeometryRef().GetZ(0), expected_height[i]))
            return 'fail'
        envelope = feat.GetGeometryRef().GetEnvelope()
        if feat.GetField('elev') != expected_height[i]:
            print('Got %f. Expected %f' % (feat.GetField('elev'), expected_height[i]))
            return 'fail'
        for j in range(4):
            if abs(expected_envelopes[i][j] - envelope[j]) > precision/2*1.001:
                print('i=%d, wkt=%s' % (i, feat.GetGeometryRef().ExportToWkt()))
                print(feat.GetGeometryRef().GetEnvelope())
                print(expected_envelopes[i])
                print('%f, %f' % (expected_envelopes[i][j] - envelope[j], precision / 2))
                return 'fail'
        i = i + 1
        feat = lyr.GetNextFeature()

    ds.ReleaseResultSet(lyr)
    ds.Destroy()

    return 'success'
예제 #17
0
def test_gdal_translate_23():
    if test_cli_utilities.get_gdal_translate_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -stats ../gcore/data/byte.tif tmp/test_gdal_translate_23.tif')

    ds = gdal.Open('tmp/test_gdal_translate_23.tif')
    md = ds.GetRasterBand(1).GetMetadata()
    ds = None

    if md['STATISTICS_MINIMUM'] != '74':
        gdaltest.post_reason('STATISTICS_MINIMUM is wrong.')
        print(md['STATISTICS_MINIMUM'])
        return 'fail'

    try:
        os.stat('tmp/test_gdal_translate_23.tif.aux.xml')
        gdaltest.post_reason('did not expect .aux.xml file presence')
        return 'fail'
    except OSError:
        pass

    gdal.Unlink('../gcore/data/byte.tif.aux.xml')

    return 'success'
예제 #18
0
파일: ogr_osm.py 프로젝트: Mavrx-inc/gdal
def ogr_osm_6():

    if ogrtest.osm_drv is None:
        return 'skip'

    import test_cli_utilities
    if test_cli_utilities.get_ogr2ogr_path() is None:
        return 'skip'

    try:
        os.stat('tmp/ogr_osm_6')
        ogr.GetDriverByName('ESRI Shapefile').DeleteDataSource('tmp/ogr_osm_6')
    except:
        pass

    gdaltest.runexternal(test_cli_utilities.get_ogr2ogr_path() + ' tmp/ogr_osm_6 data/test.pbf -sql "select * from multipolygons" -progress')

    ds = ogr.Open('tmp/ogr_osm_6')
    lyr = ds.GetLayer(0)
    count = lyr.GetFeatureCount()
    ds = None

    ogr.GetDriverByName('ESRI Shapefile').DeleteDataSource('tmp/ogr_osm_6')

    if count != 3:
        gdaltest.post_reason('fail')
        print(count)
        return 'fail'

    return 'success'
예제 #19
0
def test_gdal_translate_4():
    if test_cli_utilities.get_gdal_translate_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -b 3 -b 2 -b 1 ../gcore/data/rgbsmall.tif tmp/test4.tif')

    ds = gdal.Open('tmp/test4.tif')
    if ds is None:
        return 'fail'

    if ds.GetRasterBand(1).Checksum() != 21349:
        gdaltest.post_reason('Bad checksum')
        return 'fail'

    if ds.GetRasterBand(2).Checksum() != 21053:
        gdaltest.post_reason('Bad checksum')
        return 'fail'

    if ds.GetRasterBand(3).Checksum() != 21212:
        gdaltest.post_reason('Bad checksum')
        return 'fail'

    ds = None

    return 'success'
예제 #20
0
def test_gdaladdo_3():
    if test_cli_utilities.get_gdaladdo_path() is None:
        return 'skip'

    gdal.Translate('tmp/test_gdaladdo_3.tif', '../gcore/data/nodata_byte.tif', options='-outsize 1024 1024')

    gdaltest.runexternal(test_cli_utilities.get_gdaladdo_path() + ' -ro tmp/test_gdaladdo_3.tif 2')

    ds = gdal.Open('tmp/test_gdaladdo_3.tif')
    cs = ds.GetRasterBand(1).GetOverview(0).Checksum()
    exp_cs = 20683

    if cs != exp_cs:
        gdaltest.post_reason('got wrong overview checksum.')
        print(exp_cs, cs)
        return 'fail'

    ds = None

    try:
        os.stat('tmp/test_gdaladdo_3.tif.ovr')
    except OSError:
        gdaltest.post_reason('no external overview.')
        return 'fail'

    return 'success'
예제 #21
0
def test_gdalbuildvrt_2():
    if test_cli_utilities.get_gdalbuildvrt_path() is None:
        return "skip"
    if test_cli_utilities.get_gdaltindex_path() is None:
        return "skip"

    try:
        os.remove("tmp/tileindex.shp")
    except:
        pass
    try:
        os.remove("tmp/tileindex.dbf")
    except:
        pass
    try:
        os.remove("tmp/tileindex.shx")
    except:
        pass
    try:
        os.remove("tmp/mosaic.vrt")
    except:
        pass

    gdaltest.runexternal(
        test_cli_utilities.get_gdaltindex_path()
        + " tmp/tileindex.shp tmp/gdalbuildvrt1.tif tmp/gdalbuildvrt2.tif tmp/gdalbuildvrt3.tif tmp/gdalbuildvrt4.tif"
    )

    gdaltest.runexternal(test_cli_utilities.get_gdalbuildvrt_path() + " tmp/mosaic.vrt tmp/tileindex.shp")

    return test_gdalbuildvrt_check()
예제 #22
0
def test_gdalinfo_8():
    if test_cli_utilities.get_gdalinfo_path() is None:
        return 'skip'

    try:
        os.remove('../gcore/data/byte.tif.aux.xml')
    except:
        pass
    
    ret = gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' ../gcore/data/byte.tif')
    if ret.find('0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 37 0 0 0 0 0 0 0 57 0 0 0 0 0 0 0 62 0 0 0 0 0 0 0 66 0 0 0 0 0 0 0 0 72 0 0 0 0 0 0 0 31 0 0 0 0 0 0 0 24 0 0 0 0 0 0 0 12 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 12 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1') != -1:
        gdaltest.post_reason( 'did not expect histogram.' )
        print(ret)
        return 'fail'

    ret = gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' -hist ../gcore/data/byte.tif')
    if ret.find('0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 37 0 0 0 0 0 0 0 57 0 0 0 0 0 0 0 62 0 0 0 0 0 0 0 66 0 0 0 0 0 0 0 0 72 0 0 0 0 0 0 0 31 0 0 0 0 0 0 0 24 0 0 0 0 0 0 0 12 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 12 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1') == -1:
        gdaltest.post_reason( 'did not get expected histogram.' )
        print(ret)
        return 'fail'

    # We will blow an exception if the file does not exist now!
    os.remove('../gcore/data/byte.tif.aux.xml')
    
    return 'success'
예제 #23
0
def test_gdalbuildvrt_7():
    if test_cli_utilities.get_gdalbuildvrt_path() is None:
        return "skip"

    out_ds = gdal.GetDriverByName("GTiff").Create("tmp/vrtnull1.tif", 20, 10, 3, gdal.GDT_UInt16)
    out_ds.SetGeoTransform([2, 0.1, 0, 49, 0, -0.1])
    srs = osr.SpatialReference()
    srs.SetFromUserInput("EPSG:4326")
    out_ds.SetProjection(srs.ExportToWkt())
    out_ds.GetRasterBand(1).SetRasterColorInterpretation(gdal.GCI_RedBand)
    out_ds.GetRasterBand(2).SetRasterColorInterpretation(gdal.GCI_GreenBand)
    out_ds.GetRasterBand(3).SetRasterColorInterpretation(gdal.GCI_BlueBand)
    out_ds.GetRasterBand(1).SetNoDataValue(256)

    try:
        ff = "\xff".encode("latin1")
    except:
        ff = "\xff"

    out_ds.GetRasterBand(1).WriteRaster(0, 0, 10, 10, ff, buf_type=gdal.GDT_Byte, buf_xsize=1, buf_ysize=1)
    out_ds.GetRasterBand(2).WriteRaster(0, 0, 10, 10, "\x00", buf_type=gdal.GDT_Byte, buf_xsize=1, buf_ysize=1)
    out_ds.GetRasterBand(3).WriteRaster(0, 0, 10, 10, "\x00", buf_type=gdal.GDT_Byte, buf_xsize=1, buf_ysize=1)
    out_ds = None

    out_ds = gdal.GetDriverByName("GTiff").Create("tmp/vrtnull2.tif", 20, 10, 3, gdal.GDT_UInt16)
    out_ds.SetGeoTransform([2, 0.1, 0, 49, 0, -0.1])
    srs = osr.SpatialReference()
    srs.SetFromUserInput("EPSG:4326")
    out_ds.SetProjection(srs.ExportToWkt())
    out_ds.GetRasterBand(1).SetRasterColorInterpretation(gdal.GCI_RedBand)
    out_ds.GetRasterBand(2).SetRasterColorInterpretation(gdal.GCI_GreenBand)
    out_ds.GetRasterBand(3).SetRasterColorInterpretation(gdal.GCI_BlueBand)
    out_ds.GetRasterBand(1).SetNoDataValue(256)

    out_ds.GetRasterBand(1).WriteRaster(10, 0, 10, 10, "\x00", buf_type=gdal.GDT_Byte, buf_xsize=1, buf_ysize=1)
    out_ds.GetRasterBand(2).WriteRaster(10, 0, 10, 10, ff, buf_type=gdal.GDT_Byte, buf_xsize=1, buf_ysize=1)
    out_ds.GetRasterBand(3).WriteRaster(10, 0, 10, 10, "\x00", buf_type=gdal.GDT_Byte, buf_xsize=1, buf_ysize=1)
    out_ds = None

    gdaltest.runexternal(
        test_cli_utilities.get_gdalbuildvrt_path() + " tmp/gdalbuildvrt7.vrt tmp/vrtnull1.tif tmp/vrtnull2.tif"
    )

    ds = gdal.Open("tmp/gdalbuildvrt7.vrt")

    if ds.GetRasterBand(1).Checksum() != 1217:
        gdaltest.post_reason("Wrong checksum")
        return "fail"

    if ds.GetRasterBand(2).Checksum() != 1218:
        gdaltest.post_reason("Wrong checksum")
        return "fail"

    if ds.GetRasterBand(3).Checksum() != 0:
        gdaltest.post_reason("Wrong checksum")
        return "fail"

    ds = None

    return "success"
예제 #24
0
def test_gdalinfo_5():
    if test_cli_utilities.get_gdalinfo_path() is None:
        return 'skip'

    try:
        os.remove('../gcore/data/byte.tif.aux.xml')
    except:
        pass
    
    ret = gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' ../gcore/data/byte.tif')
    if ret.find('STATISTICS_MINIMUM=74') != -1:
        gdaltest.post_reason( 'got wrong minimum.' )
        print(ret)
        return 'fail'

    ret = gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' -stats ../gcore/data/byte.tif')
    if ret.find('STATISTICS_MINIMUM=74') == -1:
        gdaltest.post_reason( 'got wrong minimum (2).' )
        print(ret)
        return 'fail'

    # We will blow an exception if the file does not exist now!
    os.remove('../gcore/data/byte.tif.aux.xml')
    
    return 'success'
예제 #25
0
def test_gdalbuildvrt_12():
    if test_cli_utilities.get_gdalbuildvrt_path() is None:
        return "skip"

    (out, err) = gdaltest.runexternal_out_and_err(
        test_cli_utilities.get_gdalbuildvrt_path() + " -tap tmp/gdalbuildvrt12.vrt ../gcore/data/byte.tif",
        check_memleak=False,
    )
    if err.find("-tap option cannot be used without using -tr") == -1:
        gdaltest.post_reason("expected error")
        return "fail"

    gdaltest.runexternal(
        test_cli_utilities.get_gdalbuildvrt_path() + " -tr 100 50 -tap tmp/gdalbuildvrt12.vrt ../gcore/data/byte.tif"
    )

    ds = gdal.Open("tmp/gdalbuildvrt12.vrt")

    gt = ds.GetGeoTransform()
    expected_gt = [440700.0, 100.0, 0.0, 3751350.0, 0.0, -50.0]
    for i in range(6):
        if abs(gt[i] - expected_gt[i] > 1e-5):
            gdaltest.post_reason("Expected : %s\nGot : %s" % (expected_gt, gt))
            return "fail"

    if ds.RasterXSize != 13 or ds.RasterYSize != 25:
        gdaltest.post_reason("Wrong raster dimensions : %d x %d" % (ds.RasterXSize, ds.RasterYSize))
        return "fail"

    return "success"
예제 #26
0
def test_gdal_translate_33():
    if test_cli_utilities.get_gdal_translate_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -outsize 100 0 ../gdrivers/data/small_world.tif tmp/test_gdal_translate_33.tif')

    ds = gdal.Open('tmp/test_gdal_translate_33.tif')
    if ds.RasterYSize != 50:
        gdaltest.post_reason('fail')
        print(ds.RasterYSize)
        return 'fail'
    ds = None

    gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -outsize 0 100 ../gdrivers/data/small_world.tif tmp/test_gdal_translate_33.tif')

    ds = gdal.Open('tmp/test_gdal_translate_33.tif')
    if ds.RasterXSize != 200:
        gdaltest.post_reason('fail')
        print(ds.RasterYSize)
        return 'fail'
    ds = None

    os.unlink('tmp/test_gdal_translate_33.tif')

    (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' -outsize 0 0 ../gdrivers/data/small_world.tif tmp/test_gdal_translate_33.tif')
    if err.find('-outsize 0 0 invalid') < 0:
        gdaltest.post_reason('fail')
        return 'fail'

    return 'success'
예제 #27
0
def basic_test_8():

    ret = gdal.VersionInfo('RELEASE_DATE')
    if len(ret) != 8:
        gdaltest.post_reason('fail')
        print(ret)
        return 'fail'

    python_exe = sys.executable
    if sys.platform == 'win32':
        python_exe = python_exe.replace('\\', '/')

    ret = gdaltest.runexternal(python_exe + ' basic_test.py LICENSE 0')
    if ret.find('GDAL/OGR is released under the MIT/X license') != 0 and ret.find('GDAL/OGR Licensing') < 0:
        gdaltest.post_reason('fail')
        print(ret)
        return 'fail'

    f = open('tmp/LICENSE.TXT', 'wt')
    f.write('fake_license')
    f.close()
    ret = gdaltest.runexternal(python_exe + ' basic_test.py LICENSE 1')
    os.unlink('tmp/LICENSE.TXT')
    if ret.find('fake_license') != 0 and ret.find('GDAL/OGR Licensing') < 0:
        gdaltest.post_reason('fail')
        print(ret)
        return 'fail'

    return 'success'
예제 #28
0
def test_gdal_translate_32():
    if test_cli_utilities.get_gdal_translate_path() is None:
        return 'skip'

    gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' ../gcore/data/byte_rpc.tif tmp/test_gdal_translate_32.tif -srcwin 1 2 13 14 -outsize 150% 300%')
    ds = gdal.Open('tmp/test_gdal_translate_32.tif')
    md = ds.GetMetadata('RPC')
    if abs(float(md['LINE_OFF']) - 47496) > 1e-5 or \
       abs(float(md['LINE_SCALE']) - 47502) > 1e-5 or \
       abs(float(md['SAMP_OFF']) - 19676.6923076923) > 1e-5 or \
       abs(float(md['SAMP_SCALE']) - 19678.1538461538) > 1e-5:
        gdaltest.post_reason('fail')
        print(md)
        return 'fail'

    gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' ../gcore/data/byte_rpc.tif tmp/test_gdal_translate_32.tif -srcwin -10 -5 20 20')
    ds = gdal.Open('tmp/test_gdal_translate_32.tif')
    md = ds.GetMetadata('RPC')
    if abs(float(md['LINE_OFF']) - (15834 - -5)) > 1e-5 or \
       abs(float(md['LINE_SCALE']) - 15834) > 1e-5 or \
       abs(float(md['SAMP_OFF']) - (13464 - -10)) > 1e-5 or \
       abs(float(md['SAMP_SCALE']) - 13464) > 1e-5:
        gdaltest.post_reason('fail')
        print(md)
        return 'fail'

    return 'success'
예제 #29
0
def test_gdalbuildvrt_10():
    if test_cli_utilities.get_gdalbuildvrt_path() is None:
        pytest.skip()

    out_ds = gdal.GetDriverByName('GTiff').Create('tmp/test_gdalbuildvrt_10_1.tif', 10, 10, 1, gdal.GDT_Byte, options=['NBITS=1', 'PHOTOMETRIC=MINISWHITE'])
    out_ds.SetGeoTransform([2, 0.1, 0, 49, 0, -0.1])
    srs = osr.SpatialReference()
    srs.SetFromUserInput('EPSG:4326')
    out_ds.SetProjection(srs.ExportToWkt())

    out_ds.GetRasterBand(1).WriteRaster(1, 1, 3, 3, '\x01', buf_type=gdal.GDT_Byte, buf_xsize=1, buf_ysize=1)
    out_ds = None

    out_ds = gdal.GetDriverByName('GTiff').Create('tmp/test_gdalbuildvrt_10_2.tif', 10, 10, 1, gdal.GDT_Byte, options=['NBITS=1', 'PHOTOMETRIC=MINISWHITE'])
    out_ds.SetGeoTransform([2, 0.1, 0, 49, 0, -0.1])
    srs = osr.SpatialReference()
    srs.SetFromUserInput('EPSG:4326')
    out_ds.SetProjection(srs.ExportToWkt())

    out_ds.GetRasterBand(1).WriteRaster(6, 6, 3, 3, '\x01', buf_type=gdal.GDT_Byte, buf_xsize=1, buf_ysize=1)
    out_ds = None

    gdaltest.runexternal(test_cli_utilities.get_gdalbuildvrt_path() + ' -srcnodata 0 tmp/gdalbuildvrt10.vrt tmp/test_gdalbuildvrt_10_1.tif tmp/test_gdalbuildvrt_10_2.tif')

    ds = gdal.Open('tmp/gdalbuildvrt10.vrt')

    assert ds.GetRasterBand(1).Checksum() == 18, 'Wrong checksum'

    ds = None
예제 #30
0
def test_ogr_osm_6():

    if ogrtest.osm_drv is None:
        pytest.skip()

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

    try:
        os.stat('tmp/ogr_osm_6')
        ogr.GetDriverByName('ESRI Shapefile').DeleteDataSource('tmp/ogr_osm_6')
    except (OSError, AttributeError):
        pass

    gdaltest.runexternal(test_cli_utilities.get_ogr2ogr_path() + ' tmp/ogr_osm_6 data/test.pbf -sql "select * from multipolygons" -progress')

    ds = ogr.Open('tmp/ogr_osm_6')
    lyr = ds.GetLayer(0)
    count = lyr.GetFeatureCount()
    ds = None

    ogr.GetDriverByName('ESRI Shapefile').DeleteDataSource('tmp/ogr_osm_6')

    assert count == 3
예제 #31
0
def test_ogr_gpsbabel_init():

    # Test if the gpsbabel is accessible
    ogrtest.have_gpsbabel = False
    ogrtest.have_read_gpsbabel = False
    try:
        ret = gdaltest.runexternal('gpsbabel -V')
    except OSError:
        ret = ''
    if ret.find('GPSBabel') == -1:
        pytest.skip('Cannot access GPSBabel utility')

    ds = ogr.Open('data/gpx/test.gpx')

    if ds is None:
        print('GPX driver not configured for read support')
    else:
        ogrtest.have_read_gpsbabel = True

    ogrtest.have_gpsbabel = True
예제 #32
0
def test_ogr2ogr_34():

    if test_cli_utilities.get_ogr2ogr_path() is None:
        return 'skip'

    try:
        os.stat('tmp/test_ogr2ogr_34_dir')
        ogr.GetDriverByName('ESRI Shapefile').DeleteDataSource(
            'tmp/test_ogr2ogr_34_dir')
    except:
        pass

    gdaltest.runexternal(
        test_cli_utilities.get_ogr2ogr_path() +
        ' tmp/test_ogr2ogr_34_dir ../ogr/data/poly.shp -nln test_ogr2ogr_34_dir'
    )

    ds = ogr.Open('tmp/test_ogr2ogr_34_dir/test_ogr2ogr_34_dir.shp')
    if ds is None or ds.GetLayer(0).GetFeatureCount() != 10:
        gdaltest.post_reason('initial shapefile creation failed')
        return 'fail'
    ds = None

    gdaltest.runexternal(
        test_cli_utilities.get_ogr2ogr_path() +
        ' -append tmp/test_ogr2ogr_34_dir ../ogr/data/poly.shp -nln test_ogr2ogr_34_dir'
    )

    ds = ogr.Open('tmp/test_ogr2ogr_34_dir/test_ogr2ogr_34_dir.shp')
    if ds is None or ds.GetLayer(0).GetFeatureCount() != 20:
        gdaltest.post_reason('-append failed')
        return 'fail'
    ds = None

    gdaltest.runexternal(
        test_cli_utilities.get_ogr2ogr_path() +
        ' -overwrite tmp/test_ogr2ogr_34_dir ../ogr/data/poly.shp -nln test_ogr2ogr_34_dir'
    )

    ds = ogr.Open('tmp/test_ogr2ogr_34_dir/test_ogr2ogr_34_dir.shp')
    if ds is None or ds.GetLayer(0).GetFeatureCount() != 10:
        gdaltest.post_reason('-overwrite failed')
        return 'fail'
    ds = None

    ogr.GetDriverByName('ESRI Shapefile').DeleteDataSource(
        'tmp/test_ogr2ogr_34_dir')
    return 'success'
예제 #33
0
def test_gdaltransform_3():
    if test_cli_utilities.get_gdaltransform_path() is None:
        return 'skip'

    strin = '0 0\n' + '20 0\n' + '20 20\n' + '0 20\n'
    ret = gdaltest.runexternal(test_cli_utilities.get_gdaltransform_path() + ' -tps -gcp 0 0  440720.000 3751320.000 -gcp 20 0 441920.000 3751320.000 -gcp 20 20 441920.000 3750120.000 0 -gcp 0 20 440720.000 3750120.000', strin)

    if ret.find('440720 3751320') == -1:
        print(ret)
        return 'fail'
    if ret.find('441920 3751320') == -1:
        print(ret)
        return 'fail'
    if ret.find('441920 3750120') == -1:
        print(ret)
        return 'fail'
    if ret.find('440720 3750120') == -1:
        print(ret)
        return 'fail'

    return 'success'
예제 #34
0
def test_gdalwarp_30():
    if test_cli_utilities.get_gdalwarp_path() is None:
        pytest.skip()

    te = " -te -20037508.343 -16206629.152 20036845.112 16213801.068"

    # First run : no parameter
    gdaltest.runexternal(test_cli_utilities.get_gdalwarp_path() + " data/w_jpeg.tiff tmp/testgdalwarp30_1.tif  -t_srs EPSG:3785 -co COMPRESS=LZW -wm 500000  --config GDAL_CACHEMAX 1 -ts 1000 500 -co TILED=YES" + te)

    # Second run : with  -wo OPTIMIZE_SIZE=TRUE
    gdaltest.runexternal(test_cli_utilities.get_gdalwarp_path() + " data/w_jpeg.tiff tmp/testgdalwarp30_2.tif  -t_srs EPSG:3785 -co COMPRESS=LZW -wm 500000 -wo OPTIMIZE_SIZE=TRUE  --config GDAL_CACHEMAX 1 -ts 1000 500 -co TILED=YES" + te)

    # Third run : with  -wo STREAMABLE_OUTPUT=TRUE
    gdaltest.runexternal(test_cli_utilities.get_gdalwarp_path() + " data/w_jpeg.tiff tmp/testgdalwarp30_3.tif  -t_srs EPSG:3785 -co COMPRESS=LZW -wm 500000 -wo STREAMABLE_OUTPUT=TRUE  --config GDAL_CACHEMAX 1 -ts 1000 500 -co TILED=YES" + te)

    file_size1 = os.stat('tmp/testgdalwarp30_1.tif')[stat.ST_SIZE]
    file_size2 = os.stat('tmp/testgdalwarp30_2.tif')[stat.ST_SIZE]
    file_size3 = os.stat('tmp/testgdalwarp30_3.tif')[stat.ST_SIZE]

    ds = gdal.Open('tmp/testgdalwarp30_1.tif')
    assert ds is not None

    cs = ds.GetRasterBand(1).Checksum()
    assert cs == 64629 or cs == 1302, 'Bad checksum on testgdalwarp30_1'

    ds = None

    ds = gdal.Open('tmp/testgdalwarp30_2.tif')
    assert ds is not None

    cs = ds.GetRasterBand(1).Checksum()
    assert cs == 64629 or cs == 1302, 'Bad checksum on testgdalwarp30_2'

    ds = None

    ds = gdal.Open('tmp/testgdalwarp30_3.tif')
    assert ds is not None

    cs = ds.GetRasterBand(1).Checksum()
    assert cs == 64629 or cs == 1302, 'Bad checksum on testgdalwarp30_3'

    ds = None

    assert file_size1 > file_size2, \
        'Size with -wo OPTIMIZE_SIZE=TRUE larger than without !'

    assert file_size1 > file_size3, \
        'Size with -wo STREAMABLE_OUTPUT=TRUE larger than without !'
예제 #35
0
def is_buggy_jasper():
    if gdaltest.buggy_jasper is not None:
        return gdaltest.buggy_jasper

    gdaltest.buggy_jasper = False
    if gdal.GetDriverByName('JPEG2000') is None:
        return False

    # This test will cause a crash with an unpatched version of Jasper, such as the one of Ubuntu 8.04 LTS
    # --> "jpc_dec.c:1072: jpc_dec_tiledecode: Assertion `dec->numcomps == 3' failed."
    # Recent Debian/Ubuntu have the appropriate patch.
    # So we try to run in a subprocess first
    import test_cli_utilities
    if test_cli_utilities.get_gdalinfo_path() is not None:
        ret = gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' --config GDAL_SKIP "JP2ECW JP2MRSID JP2KAK JP2OpenJPEG" data/3_13bit_and_1bit.jp2')
        if ret.find('Band 1') == -1:
            gdaltest.post_reason('Jasper library would need patches')
            gdaltest.buggy_jasper = True
            return True

    return False
예제 #36
0
def test_gdal_translate_27():
    if test_cli_utilities.get_gdal_translate_path() is None:
        pytest.skip()
    if test_cli_utilities.get_gdalinfo_path() is None:
        pytest.skip()

    f = open('tmp/test_gdal_translate_27.asc', 'wb')
    f.write("""ncols        2
nrows        2
xllcorner    440720.000000000000
yllcorner    3750120.000000000000
cellsize     60.000000000000
 0 256
 0 0""".encode('ascii'))
    f.close()

    gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' -stats tmp/test_gdal_translate_27.asc')

    # Translate to an output type that accepts 256 as maximum
    gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' tmp/test_gdal_translate_27.asc tmp/test_gdal_translate_27.tif -ot UInt16')

    ds = gdal.Open('tmp/test_gdal_translate_27.tif')
    assert ds.GetRasterBand(1).GetMetadataItem('STATISTICS_MINIMUM') is not None
    ds = None

    # Translate to an output type that accepts 256 as maximum
    gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' tmp/test_gdal_translate_27.asc tmp/test_gdal_translate_27.tif -ot Float64')

    ds = gdal.Open('tmp/test_gdal_translate_27.tif')
    assert ds.GetRasterBand(1).GetMetadataItem('STATISTICS_MINIMUM') is not None
    ds = None

    # Translate to an output type that doesn't accept 256 as maximum
    gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' tmp/test_gdal_translate_27.asc tmp/test_gdal_translate_27.tif -ot Byte')

    ds = gdal.Open('tmp/test_gdal_translate_27.tif')
    assert ds.GetRasterBand(1).GetMetadataItem('STATISTICS_MINIMUM') is None
    ds = None
def test_gdalsrsinfo_8():
    if test_cli_utilities.get_gdalsrsinfo_path() is None:
        return 'skip'

    ret = gdaltest.runexternal(test_cli_utilities.get_gdalsrsinfo_path() +
                               ' -o wkt -p EPSG:4326')
    ret = ret.replace('\r\n', '\n')

    if ret.strip() != """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"]]""":
        return 'fail'

    return 'success'
def test_gdalsrsinfo_6():
    if test_cli_utilities.get_gdalsrsinfo_path() is None:
        return 'skip'

    ret = gdaltest.runexternal(test_cli_utilities.get_gdalsrsinfo_path() +
                               ' -o wkt_simple ../gcore/data/byte.tif')
    ret = ret.replace('\r\n', '\n')

    first_val = """PROJCS["NAD27 / UTM zone 11N",
    GEOGCS["NAD27",
        DATUM["North_American_Datum_1927",
            SPHEROID["Clarke 1866",6378206.4,294.9786982139006]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",-117],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1]]"""
    second_val = """PROJCS["NAD27 / UTM zone 11N",
    GEOGCS["NAD27",
        DATUM["North_American_Datum_1927",
            SPHEROID["Clarke 1866",6378206.4,294.9786982138982]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",-117],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1]]"""

    if ret.strip() != first_val and ret.strip() != second_val:
        print(ret.strip())
        return 'fail'

    return 'success'
예제 #39
0
def test_ogr2ogr_6():

    import ogr_pg

    if test_cli_utilities.get_ogr2ogr_path() is None:
        return 'skip'
    if test_cli_utilities.get_ogrinfo_path() is None:
        return 'skip'

    ogr_pg.ogr_pg_1()
    if gdaltest.pg_ds is None:
        return 'skip'
    gdaltest.pg_ds.Destroy()

    gdaltest.runexternal(test_cli_utilities.get_ogrinfo_path() + ' PG:"' +
                         gdaltest.pg_connection_string +
                         '" -sql "DELLAYER:tpoly"')

    gdaltest.runexternal(test_cli_utilities.get_ogr2ogr_path() +
                         ' -f PostgreSQL PG:"' +
                         gdaltest.pg_connection_string +
                         '" ../ogr/data/poly.shp -nln tpoly')
    gdaltest.runexternal(test_cli_utilities.get_ogr2ogr_path() +
                         ' -update -overwrite -f PostgreSQL PG:"' +
                         gdaltest.pg_connection_string +
                         '" ../ogr/data/poly.shp -nln tpoly')

    ds = ogr.Open('PG:' + gdaltest.pg_connection_string)
    if ds is None or ds.GetLayerByName('tpoly').GetFeatureCount() != 10:
        return 'fail'
    ds.Destroy()

    gdaltest.runexternal(test_cli_utilities.get_ogrinfo_path() + ' PG:"' +
                         gdaltest.pg_connection_string +
                         '" -sql "DELLAYER:tpoly"')

    return 'success'
예제 #40
0
파일: test_gdaladdo.py 프로젝트: ahhz/gdal
def test_gdaladdo_5():
    if test_cli_utilities.get_gdaladdo_path() is None:
        return 'skip'

    shutil.copyfile( '../gcore/data/nodata_byte.tif', 'tmp/test_gdaladdo_5.tif' )

    # Will not do anything given than the file is smaller than 256x256 already
    gdaltest.runexternal(test_cli_utilities.get_gdaladdo_path() + ' tmp/test_gdaladdo_5.tif')

    ds = gdal.Open('tmp/test_gdaladdo_5.tif')
    cnt = ds.GetRasterBand(1).GetOverviewCount()
    ds = None

    if cnt != 0:
        gdaltest.post_reason( 'fail' )
        print(cnt)
        return 'fail'

    # Will generate overviews of size 10 5 3 2 1
    gdaltest.runexternal(test_cli_utilities.get_gdaladdo_path() + ' -minsize 1 tmp/test_gdaladdo_5.tif')

    ds = gdal.Open('tmp/test_gdaladdo_5.tif')
    cnt = ds.GetRasterBand(1).GetOverviewCount()
    ds = None

    if cnt != 5:
        gdaltest.post_reason( 'fail' )
        print(cnt)
        return 'fail'

    gdal.Translate( 'tmp/test_gdaladdo_5.tif', '../gcore/data/nodata_byte.tif', options = '-outsize 257 257' )

    # Will generate overviews of size 129x129
    gdaltest.runexternal(test_cli_utilities.get_gdaladdo_path() + ' tmp/test_gdaladdo_5.tif')

    ds = gdal.Open('tmp/test_gdaladdo_5.tif')
    cnt = ds.GetRasterBand(1).GetOverviewCount()
    ds = None

    if cnt != 1:
        gdaltest.post_reason( 'fail' )
        print(cnt)
        return 'fail'

    os.remove('tmp/test_gdaladdo_5.tif')

    return 'success'
예제 #41
0
def ogr_ogdi_2():

    if ogrtest.ogdi_ds is None:
        return 'skip'

    import test_cli_utilities
    if test_cli_utilities.get_test_ogrsf_path() is None:
        return 'skip'

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

    ret = gdaltest.runexternal(
        test_cli_utilities.get_test_ogrsf_path() +
        ' --config OGR_OGDI_LAUNDER_LAYER_NAMES YES -ro "' + url_name +
        '" markersp_bnd contourl_elev polbnda_bnd extractp_ind')

    if ret.find('INFO') == -1 or ret.find('ERROR') != -1:
        print(ret)
        return 'fail'

    return 'success'
예제 #42
0
def grib_9():

    if gdaltest.grib_drv is None:
        return 'skip'

    import test_cli_utilities
    if test_cli_utilities.get_gdalinfo_path() is None:
        return 'skip'

    ret = gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' data/template4_15.grib -checksum')

    # This is a JPEG2000 compressed file, so just check we can open it
    if ret.find('Checksum=') < 0:
        gdaltest.post_reason('Could not open file')
        print(ret)
        return 'fail'

    #ds = gdal.Open('data/template4_15.grib')
    #if ds is None:
    #    return 'fail'

    return 'success' 
예제 #43
0
파일: ogr_sosi.py 프로젝트: ahhz/gdal
def ogr_sosi_1():

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

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

    import test_cli_utilities
    if test_cli_utilities.get_test_ogrsf_path() is None:
        return 'skip'

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

    if ret.find('INFO') == -1 or ret.find('ERROR') != -1:
        print(ret)
        return 'fail'

    return 'success'
예제 #44
0
def ogr_geojson_12():

    if gdaltest.geojson_drv is None:
        return 'skip'

    import os
    if os.name == 'nt':
        return 'skip'

    import test_cli_utilities

    if test_cli_utilities.get_ogrinfo_path() is None:
        return 'skip'

    ret = gdaltest.runexternal(
        test_cli_utilities.get_ogrinfo_path() +
        ' -ro -al \'{"type": "Point","coordinates": [100.0, 0.0]}\'')
    if ret.find(' POINT (100 0)') == -1:
        print(ret)
        return 'fail'

    return 'success'
예제 #45
0
def test_gdallocationinfo_6():
    if test_cli_utilities.get_gdallocationinfo_path() is None:
        return 'skip'

    src_ds = gdal.Open('../gcore/data/byte.tif')
    ds = gdal.GetDriverByName('GTiff').CreateCopy(
        'tmp/test_gdallocationinfo_6.tif', src_ds)
    ds.BuildOverviews('AVERAGE', overviewlist=[2])
    ds = None
    src_ds = None

    ret = gdaltest.runexternal(
        test_cli_utilities.get_gdallocationinfo_path() +
        ' tmp/test_gdallocationinfo_6.tif 10 10 -overview 1')

    gdal.GetDriverByName('GTiff').Delete('tmp/test_gdallocationinfo_6.tif')
    expected_ret = """Value: 130"""
    if ret.find(expected_ret) < 0:
        print(ret)
        return 'fail'

    return 'success'
예제 #46
0
파일: ogr_pcidsk.py 프로젝트: ghatwala/gdal
def ogr_pcidsk_online_2():

    import test_cli_utilities
    if test_cli_utilities.get_test_ogrsf_path() is None:
        return 'skip'

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

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

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

    if ret.find('INFO') == -1 or ret.find('ERROR') != -1:
        print(ret)
        return 'fail'

    return 'success'
예제 #47
0
def test_ogr_carto_test_ogrsf():
    if gdal.GetConfigOption('SKIP_SLOW') is not None:
        pytest.skip()

    if gdaltest.skip_on_travis():
        pytest.skip()

    ogrtest.carto_test_server = 'https://gdalautotest2.carto.com'

    if gdaltest.gdalurlopen(ogrtest.carto_test_server) is None:
        pytest.skip('cannot open %s' % ogrtest.carto_test_server)

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

    ret = gdaltest.runexternal(
        test_cli_utilities.get_test_ogrsf_path() +
        ' --config CARTO_HTTPS NO --config CARTO_PAGE_SIZE 300 -ro "CARTO:gdalautotest2 tables=tm_world_borders_simpl_0_3"'
    )

    assert ret.find('INFO') != -1 and ret.find('ERROR') == -1
예제 #48
0
def ogr_wfs_test_ogrsf():
    if gdaltest.wfs_drv is None:
        return 'skip'
    if not gdaltest.have_gml_reader:
        return 'skip'

    if gdaltest.deegree_wfs != True:
        return 'skip'

    import test_cli_utilities
    if test_cli_utilities.get_test_ogrsf_path() is None:
        return 'skip'

    ret = gdaltest.runexternal(
        test_cli_utilities.get_test_ogrsf_path() +
        ' -ro "WFS:http://demo.deegree.org/deegree-wfs/services?MAXFEATURES=10" app:Springs'
    )

    if ret.find('INFO') == -1 or ret.find('ERROR') != -1:
        print(ret)
        return 'fail'

    return 'success'
예제 #49
0
def test_gdalinfo_40():
    if test_cli_utilities.get_gdalinfo_path() is None:
        return 'skip'

    ret = gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' -json ../gdrivers/data/small_world.tif')
    ret = json.loads(ret)
    if 'wgs84Extent' not in ret:
        print(ret)
        return 'fail'
    if 'type' not in ret['wgs84Extent']:
        print(ret)
        return 'fail'
    if ret['wgs84Extent']['type'] != 'Polygon':
        print(ret)
        return 'fail'
    if 'coordinates' not in ret['wgs84Extent']:
        print(ret)
        return 'fail'
    if ret['wgs84Extent']['coordinates'] != [[[-180.0, 90.0], [-180.0, -90.0], [180.0, -90.0], [180.0, 90.0], [-180.0, 90.0]]]:
        print(ret)
        return 'fail'

    return 'success'
예제 #50
0
def ogr_virtualogr_3():

    if not ogrtest.has_sqlite_dialect:
        return 'skip'

    # Find path of libgdal
    libgdal_name = gdaltest.find_lib('gdal')
    if libgdal_name is None:
        return 'skip'
    print('Found ' + libgdal_name)

    # Find path of libsqlite3 or libspatialite
    libsqlite_name = gdaltest.find_lib('sqlite3')
    if libsqlite_name is None:
        libsqlite_name = gdaltest.find_lib('spatialite')
    if libsqlite_name is None:
        return 'skip'
    print('Found ' + libsqlite_name)

    python_exe = sys.executable
    if sys.platform == 'win32':
        python_exe = python_exe.replace('\\', '/')
        libgdal_name = libgdal_name.replace('\\', '/')
        libsqlite_name = libsqlite_name.replace('\\', '/')

    ret = gdaltest.runexternal(python_exe +
                               ' ogr_as_sqlite_extension.py "%s" "%s"' %
                               (libsqlite_name, libgdal_name),
                               check_memleak=False)

    if ret.find('skip') == 0:
        return 'skip'
    if ret.find(gdal.VersionInfo('RELEASE_NAME')) < 0:
        gdaltest.post_reason('fail : %s' % ret)
        return 'fail'

    return 'success'
예제 #51
0
def test_gdalinfo_22():
    if test_cli_utilities.get_gdalinfo_path() is None:
        return 'skip'

    ret = gdaltest.runexternal(test_cli_utilities.get_gdalinfo_path() + ' --format GTiff', check_memleak=False)

    expected_strings = [
        'Short Name:',
        'Long Name:',
        'Extensions:',
        'Mime Type:',
        'Help Topic:',
        'Supports: Create()',
        'Supports: CreateCopy()',
        'Supports: Virtual IO',
        'Creation Datatypes',
        '<CreationOptionList>']
    for expected_string in expected_strings:
        if ret.find(expected_string) < 0:
            gdaltest.post_reason('did not find %s' % expected_string)
            print(ret)
            return 'fail'

    return 'success'
예제 #52
0
def test_ogr2ogr_17():

    if test_cli_utilities.get_ogr2ogr_path() is None:
        return 'skip'

    try:
        os.stat('tmp/poly.shp')
        ogr.GetDriverByName('ESRI Shapefile').DeleteDataSource('tmp/poly.shp')
    except:
        pass

    ret = gdaltest.runexternal(test_cli_utilities.get_ogr2ogr_path() +
                               ' -progress tmp/poly.shp ../ogr/data/poly.shp')
    if ret.find('0...10...20...30...40...50...60...70...80...90...100 - done.'
                ) == -1:
        return 'fail'

    ds = ogr.Open('tmp/poly.shp')
    if ds is None or ds.GetLayer(0).GetFeatureCount() != 10:
        return 'fail'
    ds.Destroy()

    ogr.GetDriverByName('ESRI Shapefile').DeleteDataSource('tmp/poly.shp')
    return 'success'
예제 #53
0
def test_gdalwarp_34():
    if test_cli_utilities.get_gdalwarp_path() is None:
        pytest.skip()
    if test_cli_utilities.get_gdal_translate_path() is None:
        pytest.skip()

    try:
        os.remove('tmp/testgdalwarp34.tif')
    except OSError:
        pass

    gdaltest.runexternal(
        test_cli_utilities.get_gdal_translate_path() +
        ' ../gcore/data/byte.tif tmp/testgdalwarp34src_1.tif -srcwin 0 0 10 20'
    )
    gdaltest.runexternal(
        test_cli_utilities.get_gdal_translate_path() +
        ' ../gcore/data/byte.tif tmp/testgdalwarp34src_2.tif -srcwin 10 0 10 20'
    )
    gdaltest.runexternal(
        test_cli_utilities.get_gdalwarp_path() +
        ' tmp/testgdalwarp34src_1.tif tmp/testgdalwarp34src_2.tif tmp/testgdalwarp34.tif'
    )
    os.remove('tmp/testgdalwarp34src_1.tif')
    os.remove('tmp/testgdalwarp34src_2.tif')

    ds = gdal.Open('tmp/testgdalwarp34.tif')
    cs = ds.GetRasterBand(1).Checksum()
    gt = ds.GetGeoTransform()
    xsize = ds.RasterXSize
    ysize = ds.RasterYSize
    ds = None

    os.remove('tmp/testgdalwarp34.tif')

    assert xsize == 20 and ysize == 20, 'bad dimensions'

    assert cs == 4672, 'bad checksum'

    expected_gt = (440720.0, 60.0, 0.0, 3751320.0, 0.0, -60.0)
    for i in range(6):
        assert abs(gt[i] - expected_gt[i]) <= 1e-5, 'bad gt'
예제 #54
0
def test_gdaladdo_5():
    if test_cli_utilities.get_gdaladdo_path() is None:
        pytest.skip()

    shutil.copyfile('../gcore/data/nodata_byte.tif', 'tmp/test_gdaladdo_5.tif')

    # Will not do anything given than the file is smaller than 256x256 already
    gdaltest.runexternal(test_cli_utilities.get_gdaladdo_path() +
                         ' tmp/test_gdaladdo_5.tif')

    ds = gdal.Open('tmp/test_gdaladdo_5.tif')
    cnt = ds.GetRasterBand(1).GetOverviewCount()
    ds = None

    assert cnt == 0

    # Will generate overviews of size 10 5 3 2 1
    gdaltest.runexternal(test_cli_utilities.get_gdaladdo_path() +
                         ' -minsize 1 tmp/test_gdaladdo_5.tif')

    ds = gdal.Open('tmp/test_gdaladdo_5.tif')
    cnt = ds.GetRasterBand(1).GetOverviewCount()
    ds = None

    assert cnt == 5

    gdal.Translate('tmp/test_gdaladdo_5.tif',
                   '../gcore/data/nodata_byte.tif',
                   options='-outsize 257 257')

    # Will generate overviews of size 129x129
    gdaltest.runexternal(test_cli_utilities.get_gdaladdo_path() +
                         ' tmp/test_gdaladdo_5.tif')

    ds = gdal.Open('tmp/test_gdaladdo_5.tif')
    cnt = ds.GetRasterBand(1).GetOverviewCount()
    ds = None

    assert cnt == 1

    os.remove('tmp/test_gdaladdo_5.tif')
예제 #55
0
def test_gdal_rasterize_1():

    if test_cli_utilities.get_gdal_rasterize_path() is None:
        return 'skip'

    # Setup working spatial reference
    #sr_wkt = 'LOCAL_CS["arbitrary"]'
    #sr = osr.SpatialReference( sr_wkt )
    sr = osr.SpatialReference()
    sr.ImportFromEPSG(32631)
    sr_wkt = sr.ExportToWkt()
    
    # Create a raster to rasterize into.

    target_ds = gdal.GetDriverByName('GTiff').Create( 'tmp/rast1.tif', 100, 100, 3,
                                                    gdal.GDT_Byte )
    target_ds.SetGeoTransform( (1000,1,0,1100,0,-1) )
    target_ds.SetProjection( sr_wkt )

    # Close TIF file
    target_ds = None
    
    # Create a layer to rasterize from.

    rast_ogr_ds = \
              ogr.GetDriverByName('MapInfo File').CreateDataSource( 'tmp/rast1.tab' )
    rast_lyr = rast_ogr_ds.CreateLayer( 'rast1', srs=sr )

    layer_defn = rast_lyr.GetLayerDefn()
    field_defn = ogr.FieldDefn('foo')
    rast_lyr.CreateField(field_defn)
    field_defn.Destroy()

    # Add a polygon.
    
    wkt_geom = 'POLYGON((1020 1030,1020 1045,1050 1045,1050 1030,1020 1030))'
    
    feat = ogr.Feature( rast_lyr.GetLayerDefn() )
    feat.SetGeometryDirectly( ogr.Geometry(wkt = wkt_geom) )

    rast_lyr.CreateFeature( feat )

    # Add feature without geometry to test fix for #3310
    feat = ogr.Feature( rast_lyr.GetLayerDefn() )
    rast_lyr.CreateFeature( feat )

    # Add a linestring.
    
    wkt_geom = 'LINESTRING(1000 1000, 1100 1050)'
    
    feat = ogr.Feature( rast_lyr.GetLayerDefn() )
    feat.SetGeometryDirectly( ogr.Geometry(wkt = wkt_geom) )

    rast_lyr.CreateFeature( feat )

    # Close file
    rast_ogr_ds.Destroy()
    

    # Run the algorithm.
    gdaltest.runexternal(test_cli_utilities.get_gdal_rasterize_path() + ' -b 3 -b 2 -b 1 -burn 200 -burn 220 -burn 240 -l rast1 tmp/rast1.tab tmp/rast1.tif')

    # Check results.

    target_ds = gdal.Open('tmp/rast1.tif')
    expected = 6452
    checksum = target_ds.GetRasterBand(2).Checksum()
    if checksum != expected:
        print(checksum)
        gdaltest.post_reason( 'Did not get expected image checksum' )

        return 'fail'
    
    target_ds = None

    return 'success'
예제 #56
0
파일: ogr_gft.py 프로젝트: rbuffat/gdal
def ogr_gft_ogr2ogr_spatial():
    if ogrtest.gft_drv is None:
        return 'skip'

    if not ogrtest.gft_can_write:
        return 'skip'

    import test_cli_utilities
    if test_cli_utilities.get_ogr2ogr_path() is None:
        return 'skip'

    layer_name = 'geometry_table_%d' % ogrtest.gft_rand_val
    copied_layer_name = 'copied_geometry_table_%d' % ogrtest.gft_rand_val

    f = open('tmp/geometry_table.csv', 'wt')
    f.write('foo,bar,WKT\n')
    f.write('"baz",2,"POINT (0 1)"\n')
    f.write('"baz2",4,"POINT (2 3)"\n')
    f.write('"baz\'3",6,"POINT (4 5)"\n')
    f.close()
    f = open('tmp/geometry_table.csvt', 'wt')
    f.write('String,Integer,String\n')
    f.close()

    # Create a first table
    gdaltest.runexternal(test_cli_utilities.get_ogr2ogr_path() +
                         ' -f GFT "GFT:refresh=' + ogrtest.gft_refresh +
                         '" tmp/geometry_table.csv -nln ' + layer_name +
                         ' -select foo,bar -overwrite')

    # Test round-tripping
    gdaltest.runexternal(test_cli_utilities.get_ogr2ogr_path() +
                         ' -f GFT "GFT:refresh=' + ogrtest.gft_refresh +
                         '" "GFT:refresh=' + ogrtest.gft_refresh + '" ' +
                         layer_name + ' -nln ' + copied_layer_name +
                         ' -overwrite')

    os.unlink('tmp/geometry_table.csv')
    os.unlink('tmp/geometry_table.csvt')

    ds = ogr.Open('GFT:refresh=%s' % ogrtest.gft_refresh, update=1)

    for name in [layer_name, copied_layer_name]:
        lyr = ds.GetLayerByName(name)

        if lyr.GetGeometryColumn() != 'geometry':
            gdaltest.post_reason(
                'layer %s: did not get expected geometry column' % name)
            ds.ExecuteSQL('DELLAYER:' + layer_name)
            ds.ExecuteSQL('DELLAYER:' + copied_layer_name)
            return 'fail'

        if lyr.GetLayerDefn().GetFieldCount() != 3:
            gdaltest.post_reason('layer %s: did not get expected field count' %
                                 name)
            ds.ExecuteSQL('DELLAYER:' + layer_name)
            ds.ExecuteSQL('DELLAYER:' + copied_layer_name)
            return 'fail'

        if lyr.GetGeomType() != ogr.wkbUnknown:
            gdaltest.post_reason(
                'layer %s: did not get expected layer geometry type' % name)
            ds.ExecuteSQL('DELLAYER:' + layer_name)
            ds.ExecuteSQL('DELLAYER:' + copied_layer_name)
            return 'fail'

        if lyr.GetFeatureCount() != 3:
            gdaltest.post_reason(
                'layer %s: did not get expected feature count' % name)
            ds.ExecuteSQL('DELLAYER:' + layer_name)
            ds.ExecuteSQL('DELLAYER:' + copied_layer_name)
            return 'fail'

        feat = lyr.GetNextFeature()
        if feat.GetGeometryRef().ExportToWkt() != "POINT (0 1)":
            gdaltest.post_reason('layer %s: did not get expected geometry' %
                                 name)
            ds.ExecuteSQL('DELLAYER:' + layer_name)
            ds.ExecuteSQL('DELLAYER:' + copied_layer_name)
            return 'fail'

        if feat.GetFieldAsInteger('bar') != 2:
            gdaltest.post_reason('layer %s: did not get expected field value' %
                                 name)
            ds.ExecuteSQL('DELLAYER:' + layer_name)
            ds.ExecuteSQL('DELLAYER:' + copied_layer_name)
            return 'fail'

    ds.ExecuteSQL('DELLAYER:' + layer_name)
    ds.ExecuteSQL('DELLAYER:' + copied_layer_name)

    ds = None

    return 'success'
예제 #57
0
def test_ogrinfo_23():
    if test_cli_utilities.get_ogrinfo_path() is None:
        pytest.skip()

    f = open('tmp/test_ogrinfo_23.csv', 'wt')
    f.write('_WKTgeom1_EPSG_4326,_WKTgeom2_EPSG_32631\n')
    f.write('"POINT(1 2)","POINT(3 4)"\n')
    f.write('"POINT(3 4)","POINT(1 2)"\n')
    f.close()

    ret = gdaltest.runexternal(
        test_cli_utilities.get_ogrinfo_path() +
        ' -al tmp/test_ogrinfo_23.csv -spat 1 2 1 2 -geomfield geom__WKTgeom2_EPSG_32631',
        check_memleak=False)
    expected_ret = """INFO: Open of `tmp/test_ogrinfo_23.csv'
      using driver `CSV' successful.

Layer name: test_ogrinfo_23
Geometry (geom__WKTgeom1_EPSG_4326): Unknown (any)
Geometry (geom__WKTgeom2_EPSG_32631): Unknown (any)
Feature Count: 1
Extent (geom__WKTgeom1_EPSG_4326): (3.000000, 4.000000) - (3.000000, 4.000000)
Extent (geom__WKTgeom2_EPSG_32631): (1.000000, 2.000000) - (1.000000, 2.000000)
SRS WKT (geom__WKTgeom1_EPSG_4326):
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"]]
SRS WKT (geom__WKTgeom2_EPSG_32631):
PROJCS["WGS 84 / UTM zone 31N",
    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["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",3],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    AUTHORITY["EPSG","32631"]]
Geometry Column 1 = geom__WKTgeom1_EPSG_4326
Geometry Column 2 = geom__WKTgeom2_EPSG_32631
_WKTgeom1_EPSG_4326: String (0.0)
_WKTgeom2_EPSG_32631: String (0.0)
OGRFeature(test_ogrinfo_23):2
  _WKTgeom1_EPSG_4326 (String) = POINT(3 4)
  _WKTgeom2_EPSG_32631 (String) = POINT(1 2)
  geom__WKTgeom1_EPSG_4326 = POINT (3 4)
  geom__WKTgeom2_EPSG_32631 = POINT (1 2)
"""
    expected_lines = expected_ret.splitlines()
    lines = ret.splitlines()
    for i, exp_line in enumerate(expected_lines):
        assert exp_line == lines[i], ret

    os.unlink('tmp/test_ogrinfo_23.csv')
예제 #58
0
def test_ogrinfo_24():
    if test_cli_utilities.get_ogrinfo_path() is None:
        pytest.skip()

    f = open('tmp/test_ogrinfo_24.vrt', 'wt')
    f.write("""<OGRVRTDataSource>
    <Metadata>
        <MDI key="foo">bar</MDI>
    </Metadata>
    <Metadata domain="other_domain">
        <MDI key="baz">foo</MDI>
    </Metadata>
    <OGRVRTLayer name="poly">
        <Metadata>
            <MDI key="bar">baz</MDI>
        </Metadata>
        <SrcDataSource relativeToVRT="1" shared="1">../../ogr/data/poly.shp</SrcDataSource>
        <SrcLayer>poly</SrcLayer>
  </OGRVRTLayer>
</OGRVRTDataSource>""")
    f.close()

    ret = gdaltest.runexternal(test_cli_utilities.get_ogrinfo_path() +
                               ' -ro -al tmp/test_ogrinfo_24.vrt -so',
                               check_memleak=False)
    expected_ret = """INFO: Open of `tmp/test_ogrinfo_24.vrt'
      using driver `OGR_VRT' successful.
Metadata:
  foo=bar

Layer name: poly
Metadata:
  bar=baz
Geometry: Polygon
Feature Count: 10
Extent: (478315.531250, 4762880.500000) - (481645.312500, 4765610.500000)
Layer SRS WKT:
PROJCS["OSGB 1936 / British National Grid",
    GEOGCS["OSGB 1936",
        DATUM["OSGB_1936",
            SPHEROID["Airy 1830",6377563.396,299.3249646,
                AUTHORITY["EPSG","7001"]],
            TOWGS84[446.448,-125.157,542.06,0.15,0.247,0.842,-20.489],
            AUTHORITY["EPSG","6277"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4277"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",49],
    PARAMETER["central_meridian",-2],
    PARAMETER["scale_factor",0.9996012717],
    PARAMETER["false_easting",400000],
    PARAMETER["false_northing",-100000],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    AUTHORITY["EPSG","27700"]]
"""
    expected_lines = expected_ret.splitlines()
    lines = ret.splitlines()
    for i, exp_line in enumerate(expected_lines):
        if exp_line != lines[i]:
            if gdaltest.is_travis_branch('mingw'):
                return 'expected_fail'
            pytest.fail(ret)
    ret = gdaltest.runexternal(test_cli_utilities.get_ogrinfo_path() +
                               ' -ro -al tmp/test_ogrinfo_24.vrt -so -mdd all',
                               check_memleak=False)
    expected_ret = """INFO: Open of `tmp/test_ogrinfo_24.vrt'
      using driver `OGR_VRT' successful.
Metadata:
  foo=bar
Metadata (other_domain):
  baz=foo

Layer name: poly
Metadata:
  bar=baz
Geometry: Polygon
Feature Count: 10
Extent: (478315.531250, 4762880.500000) - (481645.312500, 4765610.500000)
Layer SRS WKT:
PROJCS["OSGB 1936 / British National Grid",
    GEOGCS["OSGB 1936",
        DATUM["OSGB_1936",
            SPHEROID["Airy 1830",6377563.396,299.3249646,
                AUTHORITY["EPSG","7001"]],
            TOWGS84[446.448,-125.157,542.06,0.15,0.247,0.842,-20.489],
            AUTHORITY["EPSG","6277"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4277"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",49],
    PARAMETER["central_meridian",-2],
    PARAMETER["scale_factor",0.9996012717],
    PARAMETER["false_easting",400000],
    PARAMETER["false_northing",-100000],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    AUTHORITY["EPSG","27700"]]
AREA: Real (12.3)
EAS_ID: Integer64 (11.0)
PRFEDEA: String (16.0)
"""
    expected_lines = expected_ret.splitlines()
    lines = ret.splitlines()
    for i, exp_line in enumerate(expected_lines):
        if exp_line != lines[i]:
            if gdaltest.is_travis_branch('mingw'):
                return 'expected_fail'
            pytest.fail(ret)

    ret = gdaltest.runexternal(test_cli_utilities.get_ogrinfo_path() +
                               ' -ro -al tmp/test_ogrinfo_24.vrt -so -nomd',
                               check_memleak=False)
    expected_ret = """INFO: Open of `tmp/test_ogrinfo_24.vrt'
      using driver `OGR_VRT' successful.

Layer name: poly
Geometry: Polygon
Feature Count: 10
Extent: (478315.531250, 4762880.500000) - (481645.312500, 4765610.500000)
Layer SRS WKT:
PROJCS["OSGB 1936 / British National Grid",
    GEOGCS["OSGB 1936",
        DATUM["OSGB_1936",
            SPHEROID["Airy 1830",6377563.396,299.3249646,
                AUTHORITY["EPSG","7001"]],
            TOWGS84[446.448,-125.157,542.06,0.15,0.247,0.842,-20.489],
            AUTHORITY["EPSG","6277"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4277"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",49],
    PARAMETER["central_meridian",-2],
    PARAMETER["scale_factor",0.9996012717],
    PARAMETER["false_easting",400000],
    PARAMETER["false_northing",-100000],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    AUTHORITY["EPSG","27700"]]
AREA: Real (12.3)
EAS_ID: Integer64 (11.0)
PRFEDEA: String (16.0)
"""
    expected_lines = expected_ret.splitlines()
    lines = ret.splitlines()
    for i, exp_line in enumerate(expected_lines):
        if exp_line != lines[i]:
            if gdaltest.is_travis_branch('mingw'):
                return 'expected_fail'
            pytest.fail(ret)

    os.unlink('tmp/test_ogrinfo_24.vrt')
예제 #59
0
def test_gdal_contour_4():
    if test_cli_utilities.get_gdal_contour_path() is None:
        pytest.skip()

    try:
        os.remove('tmp/contour_orientation.shp')
    except OSError:
        pass
    try:
        os.remove('tmp/contour_orientation.dbf')
    except OSError:
        pass
    try:
        os.remove('tmp/contour_orientation.shx')
    except OSError:
        pass

    drv = gdal.GetDriverByName('GTiff')
    wkt = '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\",\"9108\"]],AUTHORITY[\"EPSG\",\"4326\"]]'

    size = 160
    precision = 1. / size

    ds = drv.Create('tmp/gdal_contour_orientation.tif', size, size, 1)
    ds.SetProjection(wkt)
    ds.SetGeoTransform([1, precision, 0, 50, 0, -precision])

# Make the elevation 15 for the whole image
    raw_data = array.array('h', [15 for i in range(int(size))]).tostring()
    for i in range(int(size)):
        ds.WriteRaster(0, i, int(size), 1, raw_data,
                       buf_type=gdal.GDT_Int16,
                       band_list=[1])

# Create a hill with elevation 25
    raw_data = array.array('h', [25 for i in range(2)]).tostring()
    for i in range(2):
        ds.WriteRaster(int(size / 4) + int(size / 8) - 1, i + int(size / 2) - 1, 2, 1, raw_data,
                       buf_type=gdal.GDT_Int16,
                       band_list=[1])

# Create a depression with elevation 5
    raw_data = array.array('h', [5 for i in range(2)]).tostring()
    for i in range(2):
        ds.WriteRaster(int(size / 2) + int(size / 8) - 1, i + int(size / 2) - 1, 2, 1, raw_data,
                       buf_type=gdal.GDT_Int16,
                       band_list=[1])

    ds = None

    gdaltest.runexternal(test_cli_utilities.get_gdal_contour_path() + ' -a elev -i 10 tmp/gdal_contour_orientation.tif tmp/contour_orientation1.shp')

    ds = ogr.Open('tmp/contour_orientation1.shp')

    expected_contours = ['LINESTRING (' +
                         '1.628125 49.493749999999999,' +
                         '1.63125 49.496875000000003,' +
                         '1.63125 49.503124999999997,' +
                         '1.628125 49.50625,' +
                         '1.621875 49.50625,' +
                         '1.61875 49.503124999999997,' +
                         '1.61875 49.496875000000003,' +
                         '1.621875 49.493749999999999,' +
                         '1.628125 49.493749999999999)',
                         'LINESTRING (' +
                         '1.38125 49.496875000000003,' +
                         '1.378125 49.493749999999999,' +
                         '1.371875 49.493749999999999,' +
                         '1.36875 49.496875000000003,' +
                         '1.36875 49.503124999999997,' +
                         '1.371875 49.50625,' +
                         '1.378125 49.50625,' +
                         '1.38125 49.503124999999997,' +
                         '1.38125 49.496875000000003)']
    expected_elev = [10, 20]

    lyr = ds.ExecuteSQL("select * from contour_orientation1 order by elev asc")

    assert lyr.GetFeatureCount() == len(expected_contours)

    i = 0
    test_failed = False
    feat = lyr.GetNextFeature()
    while feat is not None:
        expected_geom = ogr.CreateGeometryFromWkt(expected_contours[i])
        assert feat.GetField('elev') == expected_elev[i]
        if ogrtest.check_feature_geometry(feat, expected_geom, 0.01) != 0:
            print('Got      %s.\nExpected %s' % (feat.GetGeometryRef().ExportToWkt(), expected_contours[i]))
            test_failed = True
        i = i + 1
        feat = lyr.GetNextFeature()

    ds.ReleaseResultSet(lyr)
    ds.Destroy()

    assert not test_failed
예제 #60
0
def test_gdalbuildvrt_10():
    if test_cli_utilities.get_gdalbuildvrt_path() is None:
        return 'skip'

    out_ds = gdal.GetDriverByName('GTiff').Create(
        'tmp/test_gdalbuildvrt_10_1.tif',
        10,
        10,
        1,
        gdal.GDT_Byte,
        options=['NBITS=1', 'PHOTOMETRIC=MINISWHITE'])
    out_ds.SetGeoTransform([2, 0.1, 0, 49, 0, -0.1])
    srs = osr.SpatialReference()
    srs.SetFromUserInput('EPSG:4326')
    out_ds.SetProjection(srs.ExportToWkt())

    out_ds.GetRasterBand(1).WriteRaster(1,
                                        1,
                                        3,
                                        3,
                                        '\x01',
                                        buf_type=gdal.GDT_Byte,
                                        buf_xsize=1,
                                        buf_ysize=1)
    out_ds = None

    out_ds = gdal.GetDriverByName('GTiff').Create(
        'tmp/test_gdalbuildvrt_10_2.tif',
        10,
        10,
        1,
        gdal.GDT_Byte,
        options=['NBITS=1', 'PHOTOMETRIC=MINISWHITE'])
    out_ds.SetGeoTransform([2, 0.1, 0, 49, 0, -0.1])
    srs = osr.SpatialReference()
    srs.SetFromUserInput('EPSG:4326')
    out_ds.SetProjection(srs.ExportToWkt())

    out_ds.GetRasterBand(1).WriteRaster(6,
                                        6,
                                        3,
                                        3,
                                        '\x01',
                                        buf_type=gdal.GDT_Byte,
                                        buf_xsize=1,
                                        buf_ysize=1)
    out_ds = None

    gdaltest.runexternal(
        test_cli_utilities.get_gdalbuildvrt_path() +
        ' -srcnodata 0 tmp/gdalbuildvrt10.vrt tmp/test_gdalbuildvrt_10_1.tif tmp/test_gdalbuildvrt_10_2.tif'
    )

    ds = gdal.Open('tmp/gdalbuildvrt10.vrt')

    if ds.GetRasterBand(1).Checksum() != 18:
        print(ds.GetRasterBand(1).Checksum())
        gdaltest.post_reason('Wrong checksum')
        return 'fail'

    ds = None

    return 'success'