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'
def vrtmisc_9(): import test_cli_utilities if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' # -scale and -exponent repeated as many times as output band number gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -of VRT data/byte.tif tmp/vrtmisc_9.vrt -scale 0 255 0 255 -scale 74 255 0 255 -exponent 1 -exponent 2.2 -b 1 -b 1') ds = gdal.Open('tmp/vrtmisc_9.vrt') cs1 = ds.GetRasterBand(1).Checksum() cs2 = ds.GetRasterBand(2).Checksum() ds = None os.remove('tmp/vrtmisc_9.vrt') if cs1 != 4672: gdaltest.post_reason('did not get expected checksum') print(cs1) return 'fail' if cs2 != 4159: gdaltest.post_reason('did not get expected checksum') print(cs2) return 'fail' return 'success'
def test_gdal_translate_31(): if test_cli_utilities.get_gdal_translate_path() is None: return "skip" gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + " -projwin_srs EPSG:4267 -projwin -117.641168620797 33.9023526904262 -117.628110837847 33.8915970129613 ../gcore/data/byte.tif tmp/test_gdal_translate_31.tif" ) ds = gdal.Open("tmp/test_gdal_translate_31.tif") if ds is None: return "fail" if ds.GetRasterBand(1).Checksum() != 4672: gdaltest.post_reason("Bad checksum") return "fail" if not gdaltest.geotransform_equals( gdal.Open("../gcore/data/byte.tif").GetGeoTransform(), ds.GetGeoTransform(), 1e-7 ): gdaltest.post_reason("Bad geotransform") return "fail" ds = None return "success"
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: pass return "success"
def vrtmisc_4(): import test_cli_utilities if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' # -scale specified once applies to all bands gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -of VRT data/byte.tif tmp/vrtmisc_4.vrt -scale 74 255 0 255 -b 1 -b 1') ds = gdal.Open('tmp/vrtmisc_4.vrt') cs1 = ds.GetRasterBand(1).Checksum() cs2 = ds.GetRasterBand(2).Checksum() ds = None os.remove('tmp/vrtmisc_4.vrt') if cs1 != 4323: gdaltest.post_reason('did not get expected checksum') print(cs1) return 'fail' if cs2 != 4323: gdaltest.post_reason('did not get expected checksum') print(cs2) return 'fail' return 'success'
def test_gdal_translate_35(): if test_cli_utilities.get_gdal_translate_path() is None: return "skip" (out, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path()) if err.find("No source dataset specified") < 0: gdaltest.post_reason("fail") print(err) return "fail" (out, err) = gdaltest.runexternal_out_and_err( test_cli_utilities.get_gdal_translate_path() + " ../gcore/data/byte.tif" ) if err.find("No target dataset specified") < 0: gdaltest.post_reason("fail") print(err) return "fail" (out, err) = gdaltest.runexternal_out_and_err( test_cli_utilities.get_gdal_translate_path() + " /non_existing_path/non_existing.tif /vsimem/out.tif" ) if err.find("does not exist in the file system") < 0: gdaltest.post_reason("fail") print(err) return "fail" (out, err) = gdaltest.runexternal_out_and_err( test_cli_utilities.get_gdal_translate_path() + " ../gcore/data/byte.tif /non_existing_path/non_existing.tif" ) if err.find("Attempt to create new tiff file") < 0: gdaltest.post_reason("fail") print(err) return "fail" return "success"
def vsistdin_2(): if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' ds = gdal.GetDriverByName('GTiff').Create('tmp/vsistdin_2_src.tif', 2048, 2048) ds = None # Should work on both Unix and Windows os.system(test_cli_utilities.get_gdal_translate_path() + " /vsistdin/ tmp/vsistdin_2_out.tif -q < tmp/vsistdin_2_src.tif") try: os.unlink("tmp/vsistdin_2_src.tif") except: pass ds = gdal.Open("tmp/vsistdin_2_out.tif") if ds is None: return 'fail' ds = None try: os.unlink("tmp/vsistdin_2_out.tif") except: pass return 'success'
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'
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"
def vrtmask_9(): import test_cli_utilities if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' src_ds = gdal.GetDriverByName('GTiff').Create('tmp/vrtmask_9_src.tif', 10, 10, 4) del src_ds (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' tmp/vrtmask_9_src.tif tmp/vrtmask_9_dst.tif -b 1 -b 2 -b 3') ds = gdal.Open('tmp/vrtmask_9_dst.tif') flags = ds.GetRasterBand(1).GetMaskFlags() ds = None os.remove('tmp/vrtmask_9_src.tif') os.remove('tmp/vrtmask_9_dst.tif') if err != '': gdaltest.post_reason('unexpected output on standard err') print(err) return 'fail' if flags != gdal.GMF_ALL_VALID: print(flags) return 'fail' return 'success'
def test_gdal_translate_20(): if test_cli_utilities.get_gdal_translate_path() is None: return "skip" gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + " -a_nodata 255 ../gcore/data/byte.tif tmp/test_gdal_translate_20_src.tif" ) gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + " -a_nodata None tmp/test_gdal_translate_20_src.tif tmp/test_gdal_translate_20_dst.tif" ) ds = gdal.Open("tmp/test_gdal_translate_20_dst.tif") if ds is None: return "fail" nodata = ds.GetRasterBand(1).GetNoDataValue() if nodata != None: print(nodata) return "fail" ds = None return "success"
def test_gdal_translate_35(): if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path()) if err.find('No source dataset specified') < 0: gdaltest.post_reason('fail') print(err) return 'fail' (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' ../gcore/data/byte.tif') if err.find('No target dataset specified') < 0: gdaltest.post_reason('fail') print(err) return 'fail' (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' /non_existing_path/non_existing.tif /vsimem/out.tif') if err.find('does not exist in the file system') < 0 and err.find('No such file or directory') < 0: gdaltest.post_reason('fail') print(err) return 'fail' (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' ../gcore/data/byte.tif /non_existing_path/non_existing.tif') if err.find('Attempt to create new tiff file') < 0: gdaltest.post_reason('fail') print(err) return 'fail' return 'success'
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'
def test_gdal_translate_12(): if test_cli_utilities.get_gdal_translate_path() is None: return "skip" gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + " -a_ullr 440720.000 3751320.000 441920.000 3750120.000 ../gcore/data/byte.tif tmp/test12.tif" ) ds = gdal.Open("tmp/test12.tif") if ds is None: return "fail" if ds.GetRasterBand(1).Checksum() != 4672: gdaltest.post_reason("Bad checksum") return "fail" if not gdaltest.geotransform_equals( gdal.Open("../gcore/data/byte.tif").GetGeoTransform(), ds.GetGeoTransform(), 1e-9 ): gdaltest.post_reason("Bad geotransform") return "fail" ds = None return "success"
def test_gdaldem_color_relief_from_float32(): if test_cli_utilities.get_gdaldem_path() is None: return 'skip' if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -ot Float32 ../gdrivers/data/n43.dt0 tmp/n43_float32.tif') gdaltest.runexternal(test_cli_utilities.get_gdaldem_path() + ' color-relief tmp/n43_float32.tif data/color_file.txt tmp/n43_colorrelief_from_float32.tif') ds = gdal.Open('tmp/n43_colorrelief_from_float32.tif') if ds is None: return 'fail' if ds.GetRasterBand(1).Checksum() != 55009: print(ds.GetRasterBand(1).Checksum()) gdaltest.post_reason('Bad checksum') return 'fail' if ds.GetRasterBand(2).Checksum() != 37543: print(ds.GetRasterBand(2).Checksum()) gdaltest.post_reason('Bad checksum') return 'fail' if ds.GetRasterBand(3).Checksum() != 47711: print(ds.GetRasterBand(3).Checksum()) gdaltest.post_reason('Bad checksum') return 'fail' ds = None return 'success'
def test_gdalwarp_5(): if test_cli_utilities.get_gdalwarp_path() is None: return 'skip' 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/testgdalwarp_gcp.tif') gdaltest.runexternal(test_cli_utilities.get_gdalwarp_path() + ' tmp/testgdalwarp_gcp.tif tmp/testgdalwarp5.tif') ds = gdal.Open('tmp/testgdalwarp5.tif') if ds is None: return 'fail' if ds.GetRasterBand(1).Checksum() != 4672: gdaltest.post_reason('Bad checksum') return 'fail' if not gdaltest.geotransform_equals(gdal.Open('../gcore/data/byte.tif').GetGeoTransform(), ds.GetGeoTransform(), 1e-9) : gdaltest.post_reason('Bad geotransform') return 'fail' ds = None return 'success'
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'
def test_gdalwarp_33(): if test_cli_utilities.get_gdalwarp_path() is None: pytest.skip() if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal(test_cli_utilities.get_gdalwarp_path() + ' -dstalpha ../gcore/data/ycbcr_with_mask.tif tmp/testgdalwarp33.tif') src_ds = gdal.Open('../gcore/data/ycbcr_with_mask.tif') ds = gdal.Open('tmp/testgdalwarp33.tif') assert ds is not None # There are expected diffs because of the artifacts due to JPEG compression in 8x8 blocks # that are partially masked. gdalwarp will remove those artifacts max_diff = gdaltest.compare_ds(src_ds, ds) assert max_diff <= 40 src_ds = None gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -expand gray GTIFF_DIR:2:../gcore/data/ycbcr_with_mask.tif tmp/testgdalwarp33_mask.tif') mask_ds = gdal.Open('tmp/testgdalwarp33_mask.tif') expected_cs = mask_ds.GetRasterBand(1).Checksum() mask_ds = None cs = ds.GetRasterBand(4).Checksum() ds = None assert cs == expected_cs, 'did not get expected checksum on alpha band'
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'
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"
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'
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"
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'
def test_gdal_translate_18(): if test_cli_utilities.get_gdal_translate_path() is None: return "skip" gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + " ../gcore/data/8bit_pal.bmp -of VRT tmp/test18_1.vrt" ) gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + " tmp/test18_1.vrt -expand rgb -of VRT tmp/test18_2.vrt" ) (ret_stdout, ret_stderr) = gdaltest.runexternal_out_and_err( test_cli_utilities.get_gdal_translate_path() + " tmp/test18_2.vrt tmp/test18_2.tif" ) # Check that all datasets are closed if ret_stderr.find("Open GDAL Datasets") != -1: return "fail" ds = gdal.Open("tmp/test18_2.tif") if ds is None: return "fail" if ds.GetRasterBand(1).Checksum() != 4672: gdaltest.post_reason("Bad checksum") return "fail" ds = None return "success"
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'
def test_gdal_translate_21(): if test_cli_utilities.get_gdal_translate_path() is None: return "skip" gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + " -of HFA ../gcore/data/utmsmall.img tmp/test_gdal_translate_21.img" ) ds = gdal.Open("tmp/test_gdal_translate_21.img") md = ds.GetRasterBand(1).GetMetadata() ds = None if md["STATISTICS_MINIMUM"] != "8": gdaltest.post_reason("STATISTICS_MINIMUM is wrong.") print(md["STATISTICS_MINIMUM"]) return "fail" if ( md["STATISTICS_HISTOBINVALUES"] != "0|0|0|0|0|0|0|0|8|0|0|0|0|0|0|0|23|0|0|0|0|0|0|0|0|29|0|0|0|0|0|0|0|46|0|0|0|0|0|0|0|69|0|0|0|0|0|0|0|99|0|0|0|0|0|0|0|0|120|0|0|0|0|0|0|0|178|0|0|0|0|0|0|0|193|0|0|0|0|0|0|0|212|0|0|0|0|0|0|0|281|0|0|0|0|0|0|0|0|365|0|0|0|0|0|0|0|460|0|0|0|0|0|0|0|533|0|0|0|0|0|0|0|544|0|0|0|0|0|0|0|0|626|0|0|0|0|0|0|0|653|0|0|0|0|0|0|0|673|0|0|0|0|0|0|0|629|0|0|0|0|0|0|0|0|586|0|0|0|0|0|0|0|541|0|0|0|0|0|0|0|435|0|0|0|0|0|0|0|348|0|0|0|0|0|0|0|341|0|0|0|0|0|0|0|0|284|0|0|0|0|0|0|0|225|0|0|0|0|0|0|0|237|0|0|0|0|0|0|0|172|0|0|0|0|0|0|0|0|159|0|0|0|0|0|0|0|105|0|0|0|0|0|0|0|824|" ): gdaltest.post_reason("STATISTICS_HISTOBINVALUES is wrong.") return "fail" return "success"
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'
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"
def vrtmisc_8(): import test_cli_utilities if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' # -scale_2 and -exponent_2 apply to band 2 only gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -of VRT data/byte.tif tmp/vrtmisc_8.vrt -scale_2 74 255 0 255 -exponent_2 2.2 -b 1 -b 1') ds = gdal.Open('tmp/vrtmisc_8.vrt') cs1 = ds.GetRasterBand(1).Checksum() cs2 = ds.GetRasterBand(2).Checksum() ds = None os.remove('tmp/vrtmisc_8.vrt') if cs1 != 4672: gdaltest.post_reason('did not get expected checksum') print(cs1) return 'fail' if cs2 != 4159: gdaltest.post_reason('did not get expected checksum') print(cs2) return 'fail' return 'success'
def vsistdin_1(): if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' src_ds = gdal.Open('data/byte.tif') ds = gdal.GetDriverByName('GTiff').CreateCopy('tmp/vsistdin_1_src.tif', src_ds) ds = None cs = src_ds.GetRasterBand(1).Checksum() src_ds = None # Should work on both Unix and Windows os.system(test_cli_utilities.get_gdal_translate_path() + " /vsistdin/ tmp/vsistdin_1_out.tif -q < tmp/vsistdin_1_src.tif") try: os.unlink("tmp/vsistdin_1_src.tif") except: pass ds = gdal.Open("tmp/vsistdin_1_out.tif") if ds is None: gdaltest.post_reason('fail') return 'fail' if ds.GetRasterBand(1).Checksum() != cs: gdaltest.post_reason('fail') return 'fail' try: os.unlink("tmp/vsistdin_1_out.tif") except: pass return 'success'
def test_gdal_translate_7(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + ' -outsize 200% 200% ../gcore/data/byte.tif tmp/test7.tif') ds = gdal.Open('tmp/test7.tif') assert ds is not None assert ds.GetRasterBand(1).Checksum() == 18784, 'Bad checksum' ds = None
def test_gdal_translate_21(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -of HFA ../gcore/data/utmsmall.img tmp/test_gdal_translate_21.img') ds = gdal.Open('tmp/test_gdal_translate_21.img') md = ds.GetRasterBand(1).GetMetadata() ds = None assert md['STATISTICS_MINIMUM'] == '8', 'STATISTICS_MINIMUM is wrong.' assert md['STATISTICS_HISTOBINVALUES'] == '0|0|0|0|0|0|0|0|8|0|0|0|0|0|0|0|23|0|0|0|0|0|0|0|0|29|0|0|0|0|0|0|0|46|0|0|0|0|0|0|0|69|0|0|0|0|0|0|0|99|0|0|0|0|0|0|0|0|120|0|0|0|0|0|0|0|178|0|0|0|0|0|0|0|193|0|0|0|0|0|0|0|212|0|0|0|0|0|0|0|281|0|0|0|0|0|0|0|0|365|0|0|0|0|0|0|0|460|0|0|0|0|0|0|0|533|0|0|0|0|0|0|0|544|0|0|0|0|0|0|0|0|626|0|0|0|0|0|0|0|653|0|0|0|0|0|0|0|673|0|0|0|0|0|0|0|629|0|0|0|0|0|0|0|0|586|0|0|0|0|0|0|0|541|0|0|0|0|0|0|0|435|0|0|0|0|0|0|0|348|0|0|0|0|0|0|0|341|0|0|0|0|0|0|0|0|284|0|0|0|0|0|0|0|225|0|0|0|0|0|0|0|237|0|0|0|0|0|0|0|172|0|0|0|0|0|0|0|0|159|0|0|0|0|0|0|0|105|0|0|0|0|0|0|0|824|', \ 'STATISTICS_HISTOBINVALUES is wrong.'
def test_gdal_translate_15(): if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -sds ../gdrivers/data/A.TOC tmp/test15.tif') ds = gdal.Open('tmp/test15_1.tif') if ds is None: return 'fail' ds = None return 'success'
def test_gdal_translate_10(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + ' -srcwin 0 0 1 1 ../gcore/data/byte.tif tmp/test10.tif') ds = gdal.Open('tmp/test10.tif') assert ds is not None assert ds.GetRasterBand(1).Checksum() == 2, 'Bad checksum' ds = None
def test_gdal_translate_3(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -ot Int16 ../gcore/data/byte.tif tmp/test3.tif') ds = gdal.Open('tmp/test3.tif') assert ds is not None assert ds.GetRasterBand(1).DataType == gdal.GDT_Int16, 'Bad data type' assert ds.GetRasterBand(1).Checksum() == 4672, 'Bad checksum' ds = None
def test_gdal_translate_17(): if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + ' -of VRT -expand rgba ../gdrivers/data/bug407.gif tmp/test17.vrt') ds = gdal.Open('tmp/test17.vrt') if ds is None: return 'fail' if ds.GetRasterBand(1).GetRasterColorInterpretation() != gdal.GCI_RedBand: gdaltest.post_reason('Bad color interpretation') return 'fail' if ds.GetRasterBand( 2).GetRasterColorInterpretation() != gdal.GCI_GreenBand: gdaltest.post_reason('Bad color interpretation') return 'fail' if ds.GetRasterBand(3).GetRasterColorInterpretation() != gdal.GCI_BlueBand: gdaltest.post_reason('Bad color interpretation') return 'fail' if ds.GetRasterBand( 4).GetRasterColorInterpretation() != gdal.GCI_AlphaBand: gdaltest.post_reason('Bad color interpretation') return 'fail' if ds.GetRasterBand(1).Checksum() != 20615: gdaltest.post_reason('Bad checksum') return 'fail' if ds.GetRasterBand(2).Checksum() != 59147: gdaltest.post_reason('Bad checksum') return 'fail' if ds.GetRasterBand(3).Checksum() != 63052: gdaltest.post_reason('Bad checksum') return 'fail' if ds.GetRasterBand(4).Checksum() != 63052: print(ds.GetRasterBand(3).Checksum()) gdaltest.post_reason('Bad checksum') return 'fail' ds = None return 'success'
def test_gdal_translate_20(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -a_nodata 255 ../gcore/data/byte.tif tmp/test_gdal_translate_20_src.tif') gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -a_nodata None tmp/test_gdal_translate_20_src.tif tmp/test_gdal_translate_20_dst.tif') ds = gdal.Open('tmp/test_gdal_translate_20_dst.tif') assert ds is not None nodata = ds.GetRasterBand(1).GetNoDataValue() assert nodata is None ds = None
def test_gdal_translate_23(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.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 assert md['STATISTICS_MINIMUM'] == '74', 'STATISTICS_MINIMUM is wrong.' assert not os.path.exists('tmp/test_gdal_translate_23.tif.aux.xml') gdal.Unlink('../gcore/data/byte.tif.aux.xml')
def test_gdal_translate_22(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -of HFA -scale 0 255 0 128 ../gcore/data/utmsmall.img tmp/test_gdal_translate_22.img') ds = gdal.Open('tmp/test_gdal_translate_22.img') md = ds.GetRasterBand(1).GetMetadata() ds = None assert 'STATISTICS_MINIMUM' not in md, \ 'did not expected a STATISTICS_MINIMUM value.' assert 'STATISTICS_HISTOBINVALUES' not in md, \ 'did not expected a STATISTICS_HISTOBINVALUES value.'
def test_gdal_translate_12(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -a_ullr 440720.000 3751320.000 441920.000 3750120.000 ../gcore/data/byte.tif tmp/test12.tif') ds = gdal.Open('tmp/test12.tif') assert ds is not None assert ds.GetRasterBand(1).Checksum() == 4672, 'Bad checksum' assert gdaltest.geotransform_equals(gdal.Open('../gcore/data/byte.tif').GetGeoTransform(), ds.GetGeoTransform(), 1e-9), \ 'Bad geotransform' ds = None
def test_gdal_translate_34(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + ' ../gcore/data/oddsize1bit.tif tmp/test_gdal_translate_34.vrt -of VRT -mo FOO=BAR' ) ds = gdal.Open('tmp/test_gdal_translate_34.vrt') assert ds.GetRasterBand(1).GetMetadataItem('NBITS', 'IMAGE_STRUCTURE') == '1' ds = None os.unlink('tmp/test_gdal_translate_34.vrt')
def test_gdal_translate_31(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -projwin_srs EPSG:4267 -projwin -117.641168620797 33.9023526904262 -117.628110837847 33.8915970129613 ../gcore/data/byte.tif tmp/test_gdal_translate_31.tif') ds = gdal.Open('tmp/test_gdal_translate_31.tif') assert ds is not None assert ds.GetRasterBand(1).Checksum() == 4672, 'Bad checksum' assert gdaltest.geotransform_equals(gdal.Open('../gcore/data/byte.tif').GetGeoTransform(), ds.GetGeoTransform(), 1e-6), \ 'Bad geotransform' ds = None
def test_gdal_translate_39(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -nogcp ../gcore/data/byte_gcp.tif tmp/test39.tif') ds = gdal.Open('tmp/test39.tif') assert ds is not None assert ds.GetRasterBand(1).Checksum() == 4672, 'Bad checksum' gcps = ds.GetGCPs() assert len(gcps) == 0, 'GCP count wrong.' ds = None
def test_gdal_translate_34(): if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' ../gcore/data/oddsize1bit.tif tmp/test_gdal_translate_34.vrt -of VRT -mo FOO=BAR') ds = gdal.Open('tmp/test_gdal_translate_34.vrt') if ds.GetRasterBand(1).GetMetadataItem('NBITS', 'IMAGE_STRUCTURE') != '1': gdaltest.post_reason('fail') return 'fail' ds = None os.unlink('tmp/test_gdal_translate_34.vrt') return 'success'
def test_gdal_translate_1(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() (_, err) = gdaltest.runexternal_out_and_err( test_cli_utilities.get_gdal_translate_path() + ' ../gcore/data/byte.tif tmp/test1.tif') assert (err is None or err == ''), 'got error/warning' ds = gdal.Open('tmp/test1.tif') assert ds is not None assert ds.GetRasterBand(1).Checksum() == 4672, 'Bad checksum' ds = None
def test_gdal_translate_35(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path()) assert 'No source dataset specified' in err (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' ../gcore/data/byte.tif') assert 'No target dataset specified' in err (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' /non_existing_path/non_existing.tif /vsimem/out.tif') assert 'does not exist in the file system' in err or 'No such file or directory' in err (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' ../gcore/data/byte.tif /non_existing_path/non_existing.tif') assert 'Attempt to create new tiff file' in err
def test_gdal_translate_25(): if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + ' -q ../gdrivers/data/int.img tmp/test_gdal_translate_25.tif -norat') ds = gdal.Open('tmp/test_gdal_translate_25.tif') if ds.GetRasterBand(1).GetDefaultRAT() is not None: gdaltest.post_reason('RAT unexpected') return 'fail' ds = None return 'success'
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' return 'success'
def test_gdal_translate_14(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + ' -co COMPRESS=LZW ../gcore/data/byte.tif tmp/test14.tif') ds = gdal.Open('tmp/test14.tif') assert ds is not None md = ds.GetMetadata('IMAGE_STRUCTURE') assert 'COMPRESSION' in md and md[ 'COMPRESSION'] == 'LZW', 'Did not get COMPRESSION' ds = None
def test_gdal_translate_4(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.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') assert ds is not None assert ds.GetRasterBand(1).Checksum() == 21349, 'Bad checksum' assert ds.GetRasterBand(2).Checksum() == 21053, 'Bad checksum' assert ds.GetRasterBand(3).Checksum() == 21212, 'Bad checksum' ds = None
def test_misc_12(): if int(gdal.VersionInfo('VERSION_NUM')) < 1900: pytest.skip('would crash') import test_cli_utilities gdal_translate_path = test_cli_utilities.get_gdal_translate_path() for i in range(gdal.GetDriverCount()): drv = gdal.GetDriver(i) md = drv.GetMetadata() if ('DCAP_CREATECOPY' in md or 'DCAP_CREATE' in md) and 'DCAP_RASTER' in md: nbands = 1 if drv.ShortName == 'WEBP' or drv.ShortName == 'ADRG': nbands = 3 datatype = gdal.GDT_Byte if drv.ShortName == 'BT' or drv.ShortName == 'BLX': datatype = gdal.GDT_Int16 elif drv.ShortName == 'GTX' or drv.ShortName == 'NTv2' or drv.ShortName == 'Leveller': datatype = gdal.GDT_Float32 size = 1201 if drv.ShortName == 'BLX': size = 128 src_ds = gdal.GetDriverByName('GTiff').Create('/vsimem/misc_12_src.tif', size, size, nbands, datatype) set_gt = (2, 1.0 / size, 0, 49, 0, -1.0 / size) src_ds.SetGeoTransform(set_gt) src_ds.SetProjection('GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.01745329251994328]]') # Test to detect crashes gdal.PushErrorHandler('CPLQuietErrorHandler') ds = drv.CreateCopy('/nonexistingpath' + get_filename(drv, ''), src_ds) gdal.PopErrorHandler() if ds is None and gdal.GetLastErrorMsg() == '': gdal.Unlink('/vsimem/misc_12_src.tif') pytest.fail('CreateCopy() into non existing dir fails without error message for driver %s' % drv.ShortName) ds = None if gdal_translate_path is not None: # Test to detect memleaks ds = gdal.GetDriverByName('VRT').CreateCopy('tmp/misc_12.vrt', src_ds) (out, _) = gdaltest.runexternal_out_and_err(gdal_translate_path + ' -of ' + drv.ShortName + ' tmp/misc_12.vrt /nonexistingpath/' + get_filename(drv, ''), check_memleak=False) del ds gdal.Unlink('tmp/misc_12.vrt') # If DEBUG_VSIMALLOC_STATS is defined, this is an easy way # to catch some memory leaks if out.find('VSIMalloc + VSICalloc - VSIFree') != -1 and \ out.find('VSIMalloc + VSICalloc - VSIFree : 0') == -1: if drv.ShortName == 'Rasterlite' and out.find('VSIMalloc + VSICalloc - VSIFree : 1') != -1: pass else: print('memleak detected for driver %s' % drv.ShortName) src_ds = None gdal.Unlink('/vsimem/misc_12_src.tif')
def test_gdal_translate_24(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + ' -q -srcwin -10 -10 40 40 ../gcore/data/byte.tif tmp/test_gdal_translate_24.tif' ) ds = gdal.Open('tmp/test_gdal_translate_24.tif') assert ds is not None cs = ds.GetRasterBand(1).Checksum() assert cs == 4620, 'Bad checksum' ds = None
def test_gdal_translate_28(): if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + ' ../gdrivers/data/float64.asc tmp/test_gdal_translate_28.tif -oo datatype=float64' ) ds = gdal.Open('tmp/test_gdal_translate_28.tif') if ds.GetRasterBand(1).DataType != gdal.GDT_Float64: gdaltest.post_reason('failure') return 'fail' ds = None return 'success'
def test_gdaldem_color_relief_from_float32_to_png(): if test_cli_utilities.get_gdaldem_path() is None: return 'skip' if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' gdaltest.runexternal( test_cli_utilities.get_gdaldem_path() + ' color-relief -of PNG tmp/n43_float32.tif data/color_file.txt tmp/n43_colorrelief_from_float32.png' ) ds = gdal.Open('tmp/n43_colorrelief_from_float32.png') if ds is None: return 'fail' if ds.GetRasterBand(1).Checksum() != 55009: print(ds.GetRasterBand(1).Checksum()) gdaltest.post_reason('Bad checksum') return 'fail' if ds.GetRasterBand(2).Checksum() != 37543: print(ds.GetRasterBand(2).Checksum()) gdaltest.post_reason('Bad checksum') return 'fail' if ds.GetRasterBand(3).Checksum() != 47711: print(ds.GetRasterBand(3).Checksum()) gdaltest.post_reason('Bad checksum') return 'fail' ds = None return 'success'
def test_gdal_translate_13(): if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal( test_cli_utilities.get_gdal_translate_path() + ' -mo TIFFTAG_DOCUMENTNAME=test13 ../gcore/data/byte.tif tmp/test13.tif' ) ds = gdal.Open('tmp/test13.tif') assert ds is not None md = ds.GetMetadata() assert 'TIFFTAG_DOCUMENTNAME' in md, 'Did not get TIFFTAG_DOCUMENTNAME' ds = None
def vrtmisc_3(): import test_cli_utilities if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' ds = gdal.Open("""<VRTDataset rasterXSize="20" rasterYSize="20"> <VRTRasterBand dataType="Byte" band="1"> <ComplexSource> <SourceFilename relativeToVRT="0">data/byte.tif</SourceFilename> <SourceBand>1</SourceBand> <Exponent>2.2</Exponent> <DstMin>0</DstMin> <DstMax>255</DstMax> </ComplexSource> </VRTRasterBand> </VRTDataset>""") cs = ds.GetRasterBand(1).Checksum() ds = None if cs != 4159: gdaltest.post_reason('did not get expected checksum') print(cs) return 'fail' return 'success'
def test_gdalwarp_43(): if test_cli_utilities.get_gdalwarp_path() is None: pytest.skip() if test_cli_utilities.get_gdal_translate_path() is None: pytest.skip() gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' ../gdrivers/data/small_world.tif tmp/small_world.tif -mo "FOO=BAR" -mo "NODATA_VALUES=62 93 23"') gdaltest.runexternal(test_cli_utilities.get_gdalwarp_path() + ' tmp/small_world.tif tmp/test_gdalwarp_43.tif -overwrite -dstalpha') ds = gdal.Open('tmp/test_gdalwarp_43.tif') assert ds.GetMetadataItem('NODATA_VALUES') is None assert ds.GetMetadataItem('FOO') == 'BAR' got_cs = [ds.GetRasterBand(i + 1).Checksum() for i in range(4)] expected_cs = [30106, 32285, 40022, 64261] assert got_cs == expected_cs
def test_gdal_translate_29(): if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' ../gcore/data/byte.tif tmp/test_gdal_translate_29.tif -outsize 50% 50% -r cubic') if not (err is None or err == ''): gdaltest.post_reason('got error/warning') print(err) return 'fail' ds = gdal.Open('tmp/test_gdal_translate_29.tif') if ds is None: return 'fail' cs = ds.GetRasterBand(1).Checksum() if cs != 1059: gdaltest.post_reason('Bad checksum') print(cs) return 'fail' ds = None (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' ../gcore/data/byte.tif tmp/test_gdal_translate_29.vrt -outsize 50% 50% -r cubic -of VRT') if not (err is None or err == ''): gdaltest.post_reason('got error/warning') print(err) return 'fail' (_, err) = gdaltest.runexternal_out_and_err(test_cli_utilities.get_gdal_translate_path() + ' tmp/test_gdal_translate_29.vrt tmp/test_gdal_translate_29.tif') if not (err is None or err == ''): gdaltest.post_reason('got error/warning') print(err) return 'fail' ds = gdal.Open('tmp/test_gdal_translate_29.tif') if ds is None: return 'fail' cs = ds.GetRasterBand(1).Checksum() if cs != 1059: gdaltest.post_reason('Bad checksum') print(cs) return 'fail' ds = None return 'success'
def test_gdal_translate_2(): if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' gdaltest.runexternal(test_cli_utilities.get_gdal_translate_path() + ' -of GTiff ../gcore/data/byte.tif tmp/test2.tif') ds = gdal.Open('tmp/test2.tif') if ds is None: return 'fail' if ds.GetRasterBand(1).Checksum() != 4672: gdaltest.post_reason('Bad checksum') return 'fail' ds = None return 'success'
def test_gdal_translate_27(): if test_cli_utilities.get_gdal_translate_path() is None: return 'skip' if test_cli_utilities.get_gdalinfo_path() is None: return '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') if ds.GetRasterBand(1).GetMetadataItem('STATISTICS_MINIMUM') is None: gdaltest.post_reason('failure') return 'fail' 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') if ds.GetRasterBand(1).GetMetadataItem('STATISTICS_MINIMUM') is None: gdaltest.post_reason('failure') return 'fail' 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') if ds.GetRasterBand(1).GetMetadataItem('STATISTICS_MINIMUM') is not None: gdaltest.post_reason('failure') return 'fail' ds = None return 'success'