예제 #1
0
파일: mem.py 프로젝트: AsgerPetersen/gdal
def test_mem_1():

    #######################################################
    # Setup dataset
    drv = gdal.GetDriverByName('MEM')
    gdaltest.mem_ds = drv.Create('mem_1.mem', 50, 3)
    ds = gdaltest.mem_ds

    assert ds.GetProjection() == '', 'projection wrong'

    assert ds.GetGeoTransform(can_return_null=True) is None, 'geotransform wrong'

    raw_data = array.array('f', list(range(150))).tostring()
    ds.WriteRaster(0, 0, 50, 3, raw_data,
                   buf_type=gdal.GDT_Float32,
                   band_list=[1])

    wkt = gdaltest.user_srs_to_wkt('EPSG:26711')
    ds.SetProjection(wkt)

    gt = (440720, 5, 0, 3751320, 0, -5)
    ds.SetGeoTransform(gt)

    band = ds.GetRasterBand(1)
    band.SetNoDataValue(-1.0)

    # Set GCPs()
    wkt_gcp = gdaltest.user_srs_to_wkt('EPSG:4326')
    gcps = [gdal.GCP(0, 1, 2, 3, 4)]
    ds.SetGCPs([], "")
    ds.SetGCPs(gcps, wkt_gcp)
    ds.SetGCPs([], "")
    ds.SetGCPs(gcps, wkt_gcp)
    ds.SetGCPs(gcps, wkt_gcp)

    #######################################################
    # Verify dataset.

    assert band.GetNoDataValue() == -1.0, 'no data is wrong'

    assert ds.GetProjection() == wkt, 'projection wrong'

    assert ds.GetGeoTransform() == gt, 'geotransform wrong'

    assert band.Checksum() == 1531, 'checksum wrong'

    assert ds.GetGCPCount() == 1, 'GetGCPCount wrong'

    assert len(ds.GetGCPs()) == 1, 'GetGCPs wrong'

    assert ds.GetGCPProjection() == wkt_gcp, 'GetGCPProjection wrong'

    assert band.DeleteNoDataValue() == 0, 'wrong return code'
    assert band.GetNoDataValue() is None, 'got nodata value whereas none was expected'

    gdaltest.mem_ds = None
예제 #2
0
파일: mem.py 프로젝트: kongdd/gdal
def test_mem_1():

    #######################################################
    # Setup dataset
    drv = gdal.GetDriverByName('MEM')
    gdaltest.mem_ds = drv.Create('mem_1.mem', 50, 3)
    ds = gdaltest.mem_ds

    assert ds.GetProjection() == '', 'projection wrong'

    assert ds.GetGeoTransform(can_return_null=True) is None, 'geotransform wrong'

    raw_data = b''.join(struct.pack('f', v) for v in range(150))
    ds.WriteRaster(0, 0, 50, 3, raw_data,
                   buf_type=gdal.GDT_Float32,
                   band_list=[1])

    wkt = gdaltest.user_srs_to_wkt('EPSG:26711')
    ds.SetProjection(wkt)

    gt = (440720, 5, 0, 3751320, 0, -5)
    ds.SetGeoTransform(gt)

    band = ds.GetRasterBand(1)
    band.SetNoDataValue(-1.0)

    # Set GCPs()
    wkt_gcp = gdaltest.user_srs_to_wkt('EPSG:4326')
    gcps = [gdal.GCP(0, 1, 2, 3, 4)]
    ds.SetGCPs([], "")
    ds.SetGCPs(gcps, wkt_gcp)
    ds.SetGCPs([], "")
    ds.SetGCPs(gcps, wkt_gcp)
    ds.SetGCPs(gcps, wkt_gcp)

    #######################################################
    # Verify dataset.

    assert band.GetNoDataValue() == -1.0, 'no data is wrong'

    assert ds.GetProjection() == wkt, 'projection wrong'

    assert ds.GetGeoTransform() == gt, 'geotransform wrong'

    assert band.Checksum() == 1531, 'checksum wrong'

    assert ds.GetGCPCount() == 1, 'GetGCPCount wrong'

    assert len(ds.GetGCPs()) == 1, 'GetGCPs wrong'

    assert ds.GetGCPProjection() == wkt_gcp, 'GetGCPProjection wrong'

    assert band.DeleteNoDataValue() == 0, 'wrong return code'
    assert band.GetNoDataValue() is None, 'got nodata value whereas none was expected'

    gdaltest.mem_ds = None
예제 #3
0
파일: warp.py 프로젝트: AsgerPetersen/gdal
def test_warp_39():

    # Create an output file with GCPs.
    out_file = 'tmp/warp_39.tif'
    ds = gdal.GetDriverByName('GTiff').Create(out_file, 50, 50, 3)

    gcp_list = [
        gdal.GCP(397000, 5642000, 0, 0, 0),
        gdal.GCP(397000, 5641990, 0, 0, 50),
        gdal.GCP(397010, 5642000, 0, 50, 0),
        gdal.GCP(397010, 5641990, 0, 50, 50),
        gdal.GCP(397005, 5641995, 0, 25, 25),
    ]
    ds.SetGCPs(gcp_list, gdaltest.user_srs_to_wkt('EPSG:32632'))
    ds = None

    gdal.Warp(out_file, 'data/test3658.tif', options='-to DST_METHOD=GCP_TPS')

    ds = gdal.Open(out_file)
    cs = ds.GetRasterBand(1).Checksum()
    ds = None

    # Should exactly match the source file.
    exp_cs = 30546
    assert cs == exp_cs

    os.unlink(out_file)
예제 #4
0
파일: warp.py 프로젝트: snorfalorpagus/gdal
def warp_39():

    # Create an output file with GCPs.
    out_file = 'tmp/warp_39.tif'
    ds = gdal.GetDriverByName('GTiff').Create(out_file, 50, 50, 3)

    gcp_list = [
        gdal.GCP(397000, 5642000, 0, 0, 0),
        gdal.GCP(397000, 5641990, 0, 0, 50),
        gdal.GCP(397010, 5642000, 0, 50, 0),
        gdal.GCP(397010, 5641990, 0, 50, 50),
        gdal.GCP(397005, 5641995, 0, 25, 25),
    ]
    ds.SetGCPs(gcp_list, gdaltest.user_srs_to_wkt('EPSG:32632'))
    ds = None

    gdal.Warp(out_file, 'data/test3658.tif', options='-to DST_METHOD=GCP_TPS')

    ds = gdal.Open(out_file)
    cs = ds.GetRasterBand(1).Checksum()
    ds = None

    # Should exactly match the source file.
    exp_cs = 30546
    if cs != exp_cs:
        gdaltest.post_reason('Got %d instead of expected checksum %d.' %
                             (cs, exp_cs))
        return 'fail'

    os.unlink(out_file)
    return 'success'
예제 #5
0
파일: mem.py 프로젝트: rkawsar/gdal-netcdf
def mem_1():

    #######################################################
    # Setup dataset
    drv = gdal.GetDriverByName('MEM')
    gdaltest.mem_ds = drv.Create( 'mem_1.mem', 50, 3 )
    ds = gdaltest.mem_ds

    raw_data = array.array('f',list(range(150))).tostring()
    ds.WriteRaster( 0, 0, 50, 3, raw_data,
                    buf_type = gdal.GDT_Float32,
                    band_list = [1] )

    wkt = gdaltest.user_srs_to_wkt( 'EPSG:26711' )
    ds.SetProjection( wkt )

    gt = ( 440720, 5, 0, 3751320, 0, -5 )
    ds.SetGeoTransform( gt )

    band = ds.GetRasterBand(1)
    band.SetNoDataValue( -1.0 )

    #######################################################
    # Verify dataset.

    if band.GetNoDataValue() != -1.0:
        gdaltest.post_reason( 'no data is wrong' )
        return 'fail'

    if ds.GetProjection() != wkt:
        gdaltest.post_reason( 'projection wrong' )
        return 'fail'

    if ds.GetGeoTransform() != gt:
        gdaltest.post_reason( 'geotransform wrong' )
        return 'fail'

    if band.Checksum() != 1531:
        gdaltest.post_reason( 'checksum wrong' )
        print(band.Checksum())
        return 'fail'

    gdaltest.mem_ds = None

    return 'success'
예제 #6
0
def warp_39():

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

    # Create an output file with GCPs.
    out_file = 'tmp/warp_39.tif'
    ds = gdal.GetDriverByName('GTiff').Create(out_file, 50, 50, 3)

    gcp_list = [
        gdal.GCP(397000, 5642000, 0, 0, 0),
        gdal.GCP(397000, 5641990, 0, 0, 50),
        gdal.GCP(397010, 5642000, 0, 50, 0),
        gdal.GCP(397010, 5641990, 0, 50, 50),
        gdal.GCP(397005, 5641995, 0, 25, 25),
    ]
    ds.SetGCPs(gcp_list, gdaltest.user_srs_to_wkt('EPSG:32632'))
    ds = None

    cmd = test_cli_utilities.get_gdalwarp_path()  \
        + ' -to DST_METHOD=GCP_TPS' \
        + ' data/test3658.tif ' \
        + out_file
    gdaltest.runexternal(cmd, display_live_on_parent_stdout=False)

    ds = gdal.Open(out_file)
    cs = ds.GetRasterBand(1).Checksum()
    ds = None

    # Should exactly match the source file.
    exp_cs = 30546
    if cs != exp_cs:
        gdaltest.post_reason('Got %d instead of expected checksum %d.' %
                             (cs, exp_cs))
        return 'fail'

    os.unlink(out_file)
    return 'success'
예제 #7
0
파일: warp.py 프로젝트: rashadkm/lib_gdal
def warp_39():

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

    # Create an output file with GCPs.
    out_file = 'tmp/warp_39.tif'
    ds = gdal.GetDriverByName('GTiff').Create(out_file, 50, 50, 3)

    gcp_list = [
        gdal.GCP(397000, 5642000, 0,  0,  0),
        gdal.GCP(397000, 5641990, 0,  0, 50),
        gdal.GCP(397010, 5642000, 0, 50,  0),
        gdal.GCP(397010, 5641990, 0, 50, 50),
        gdal.GCP(397005, 5641995, 0, 25, 25),
        ]
    ds.SetGCPs(gcp_list, gdaltest.user_srs_to_wkt('EPSG:32632'))
    ds = None

    cmd = test_cli_utilities.get_gdalwarp_path()  \
        + ' -to DST_METHOD=GCP_TPS' \
        + ' data/test3658.tif ' \
        + out_file
    gdaltest.runexternal(cmd, display_live_on_parent_stdout = False)

    ds = gdal.Open(out_file)
    cs = ds.GetRasterBand(1).Checksum()
    ds = None

    # Should exactly match the source file.
    exp_cs = 30546
    if cs != exp_cs:
        gdaltest.post_reason('Got %d instead of expected checksum %d.' % (
                cs, exp_cs))
        return 'fail'

    os.unlink(out_file)
    return 'success'
예제 #8
0
파일: mem.py 프로젝트: plkms/gdal
def mem_1():

    #######################################################
    # Setup dataset
    drv = gdal.GetDriverByName('MEM')
    gdaltest.mem_ds = drv.Create('mem_1.mem', 50, 3)
    ds = gdaltest.mem_ds

    if ds.GetProjection() != '':
        gdaltest.post_reason('projection wrong')
        return 'fail'

    if ds.GetGeoTransform(can_return_null=True) is not None:
        gdaltest.post_reason('geotransform wrong')
        return 'fail'

    raw_data = array.array('f', list(range(150))).tostring()
    ds.WriteRaster(0,
                   0,
                   50,
                   3,
                   raw_data,
                   buf_type=gdal.GDT_Float32,
                   band_list=[1])

    wkt = gdaltest.user_srs_to_wkt('EPSG:26711')
    ds.SetProjection(wkt)

    gt = (440720, 5, 0, 3751320, 0, -5)
    ds.SetGeoTransform(gt)

    band = ds.GetRasterBand(1)
    band.SetNoDataValue(-1.0)

    # Set GCPs()
    wkt_gcp = gdaltest.user_srs_to_wkt('EPSG:4326')
    gcps = [gdal.GCP(0, 1, 2, 3, 4)]
    ds.SetGCPs([], "")
    ds.SetGCPs(gcps, wkt_gcp)
    ds.SetGCPs([], "")
    ds.SetGCPs(gcps, wkt_gcp)
    ds.SetGCPs(gcps, wkt_gcp)

    #######################################################
    # Verify dataset.

    if band.GetNoDataValue() != -1.0:
        gdaltest.post_reason('no data is wrong')
        return 'fail'

    if ds.GetProjection() != wkt:
        gdaltest.post_reason('projection wrong')
        return 'fail'

    if ds.GetGeoTransform() != gt:
        gdaltest.post_reason('geotransform wrong')
        return 'fail'

    if band.Checksum() != 1531:
        gdaltest.post_reason('checksum wrong')
        print(band.Checksum())
        return 'fail'

    if ds.GetGCPCount() != 1:
        gdaltest.post_reason('GetGCPCount wrong')
        return 'fail'

    if len(ds.GetGCPs()) != 1:
        gdaltest.post_reason('GetGCPs wrong')
        return 'fail'

    if ds.GetGCPProjection() != wkt_gcp:
        gdaltest.post_reason('GetGCPProjection wrong')
        return 'fail'

    if band.DeleteNoDataValue() != 0:
        gdaltest.post_reason('wrong return code')
        return 'fail'
    if band.GetNoDataValue() is not None:
        gdaltest.post_reason('got nodata value whereas none was expected')
        return 'fail'

    gdaltest.mem_ds = None

    return 'success'
예제 #9
0
파일: mem.py 프로젝트: nextgis-borsch/tests
def mem_1():

    #######################################################
    # Setup dataset
    drv = gdal.GetDriverByName('MEM')
    gdaltest.mem_ds = drv.Create( 'mem_1.mem', 50, 3 )
    ds = gdaltest.mem_ds

    if ds.GetProjection() != '':
        gdaltest.post_reason( 'projection wrong' )
        return 'fail'

    if ds.GetGeoTransform(can_return_null = True) is not None:
        gdaltest.post_reason( 'geotransform wrong' )
        return 'fail'

    raw_data = array.array('f',list(range(150))).tostring()
    ds.WriteRaster( 0, 0, 50, 3, raw_data,
                    buf_type = gdal.GDT_Float32,
                    band_list = [1] )

    wkt = gdaltest.user_srs_to_wkt( 'EPSG:26711' )
    ds.SetProjection( wkt )

    gt = ( 440720, 5, 0, 3751320, 0, -5 )
    ds.SetGeoTransform( gt )

    band = ds.GetRasterBand(1)
    band.SetNoDataValue( -1.0 )

    # Set GCPs()
    wkt_gcp = gdaltest.user_srs_to_wkt( 'EPSG:4326' )
    gcps = [ gdal.GCP(0,1,2,3,4) ]
    ds.SetGCPs([], "")
    ds.SetGCPs(gcps, wkt_gcp)
    ds.SetGCPs([], "")
    ds.SetGCPs(gcps, wkt_gcp)
    ds.SetGCPs(gcps, wkt_gcp)

    #######################################################
    # Verify dataset.

    if band.GetNoDataValue() != -1.0:
        gdaltest.post_reason( 'no data is wrong' )
        return 'fail'

    if ds.GetProjection() != wkt:
        gdaltest.post_reason( 'projection wrong' )
        return 'fail'

    if ds.GetGeoTransform() != gt:
        gdaltest.post_reason( 'geotransform wrong' )
        return 'fail'

    if band.Checksum() != 1531:
        gdaltest.post_reason( 'checksum wrong' )
        print(band.Checksum())
        return 'fail'

    if ds.GetGCPCount() != 1:
        gdaltest.post_reason( 'GetGCPCount wrong' )
        return 'fail'

    if len(ds.GetGCPs()) != 1:
        gdaltest.post_reason( 'GetGCPs wrong' )
        return 'fail'

    if ds.GetGCPProjection() != wkt_gcp:
        gdaltest.post_reason( 'GetGCPProjection wrong' )
        return 'fail'

    if band.DeleteNoDataValue() != 0:
        gdaltest.post_reason('wrong return code')
        return 'fail'
    if band.GetNoDataValue() is not None:
        gdaltest.post_reason('got nodata value whereas none was expected')
        return 'fail'

    gdaltest.mem_ds = None

    return 'success'