本文整理汇总了Python中test_py_scripts.run_py_script函数的典型用法代码示例。如果您正苦于以下问题:Python run_py_script函数的具体用法?Python run_py_script怎么用?Python run_py_script使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run_py_script函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ogr2ogr_py_21
def test_ogr2ogr_py_21():
script_path = test_py_scripts.get_py_script("ogr2ogr")
if script_path is None:
return "skip"
try:
os.remove("tmp/testogr2ogr21.gtm")
except:
pass
test_py_scripts.run_py_script(
script_path,
"ogr2ogr",
"-f GPSTrackMaker tmp/testogr2ogr21.gtm ../utilities/data/dataforogr2ogr21.csv "
+ '-sql "SELECT comment, name FROM dataforogr2ogr21" -nlt POINT',
)
ds = ogr.Open("tmp/testogr2ogr21.gtm")
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()
os.remove("tmp/testogr2ogr21.gtm")
return "fail"
ds.Destroy()
os.remove("tmp/testogr2ogr21.gtm")
return "success"
示例2: test_ogrmerge_11
def test_ogrmerge_11():
script_path = test_py_scripts.get_py_script('ogrmerge')
if script_path is None:
return 'skip'
test_py_scripts.run_py_script(script_path, 'ogrmerge',
'-f VRT -o /vsimem/out.vrt ../ogr/data/poly.shp '
'-a_srs EPSG:32630')
ds = ogr.Open('/vsimem/out.vrt')
if ds is None:
gdaltest.post_reason('fail')
return 'fail'
ds = None
f = gdal.VSIFOpenL('/vsimem/out.vrt', 'rb')
content = ''
if f is not None:
content = gdal.VSIFReadL(1, 10000, f).decode('UTF-8')
gdal.VSIFCloseL(f)
gdal.Unlink('/vsimem/out.vrt')
if content.find('<LayerSRS>EPSG:32630</LayerSRS>') < 0:
gdaltest.post_reason('fail')
print(content)
return 'fail'
return 'success'
示例3: test_gdalinfo_py_8
def test_gdalinfo_py_8():
script_path = test_py_scripts.get_py_script('gdalinfo')
if script_path is None:
return 'skip'
try:
os.remove('../gcore/data/byte.tif.aux.xml')
except:
pass
ret = test_py_scripts.run_py_script(script_path, 'gdalinfo', '../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 = test_py_scripts.run_py_script(script_path, 'gdalinfo', '-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'
示例4: test_gdal_edit_py_2
def test_gdal_edit_py_2():
script_path = test_py_scripts.get_py_script('gdal_edit')
if script_path is None:
return 'skip'
shutil.copy('../gcore/data/byte.tif', 'tmp/test_gdal_edit_py.tif')
test_py_scripts.run_py_script(script_path, 'gdal_edit', "tmp/test_gdal_edit_py.tif -unsetgt")
ds = gdal.Open('tmp/test_gdal_edit_py.tif')
wkt = ds.GetProjectionRef()
gt = ds.GetGeoTransform(can_return_null = True)
ds = None
if gt is not None:
gdaltest.post_reason('fail')
print(gt)
return 'fail'
if wkt == '':
gdaltest.post_reason('fail')
print(wkt)
return 'fail'
return 'success'
示例5: test_gdal_edit_py_7
def test_gdal_edit_py_7():
script_path = test_py_scripts.get_py_script('gdal_edit')
if script_path is None:
return 'skip'
gdal.Translate('tmp/test_gdal_edit_py.tif',
'../gcore/data/byte.tif',
options = '-b 1 -b 1 -b 1 -b 1 -co PHOTOMETRIC=RGB -co ALPHA=NO')
test_py_scripts.run_py_script(script_path, 'gdal_edit', "tmp/test_gdal_edit_py.tif -colorinterp_4 alpha")
ds = gdal.Open('tmp/test_gdal_edit_py.tif')
if ds.GetRasterBand(4).GetColorInterpretation() != gdal.GCI_AlphaBand:
gdaltest.post_reason('fail')
return 'fail'
test_py_scripts.run_py_script(script_path, 'gdal_edit', "tmp/test_gdal_edit_py.tif -colorinterp_4 undefined")
ds = gdal.Open('tmp/test_gdal_edit_py.tif')
if ds.GetRasterBand(4).GetColorInterpretation() != gdal.GCI_Undefined:
gdaltest.post_reason('fail')
return 'fail'
return 'success'
示例6: test_gdalmove_1
def test_gdalmove_1():
script_path = test_py_scripts.get_py_script('gdalmove')
if script_path is None:
return 'skip'
shutil.copy('../gcore/data/byte.tif', 'tmp/test_gdalmove_1.tif' )
test_py_scripts.run_py_script(script_path, 'gdalmove', '-s_srs "+proj=utm +zone=11 +ellps=clrk66 +towgs84=0,0,0 +no_defs" -t_srs EPSG:32611 tmp/test_gdalmove_1.tif -et 1' )
ds = gdal.Open('tmp/test_gdalmove_1.tif')
got_gt = ds.GetGeoTransform()
expected_gt = (440719.95870935748, 60.000041745067577, 1.9291142234578728e-05, 3751294.2109841029, 1.9099167548120022e-05, -60.000041705276814)
for i in range(6):
if abs(got_gt[i] - expected_gt[i]) / abs(got_gt[i]) > 1e-5:
gdaltest.post_reason('bad gt')
print(got_gt)
print(expected_gt)
return 'fail'
wkt = ds.GetProjection()
if wkt.find('32611') < 0:
gdaltest.post_reason('bad geotransform')
print(wkt)
return 'fail'
ds = None
return 'success'
示例7: test_gdal_sieve_1
def test_gdal_sieve_1():
script_path = test_py_scripts.get_py_script('gdal_sieve')
if script_path is None:
return 'skip'
drv = gdal.GetDriverByName('GTiff')
dst_ds = drv.Create('tmp/sieve_1.tif', 5, 7, 1, gdal.GDT_Byte)
dst_ds = None
test_py_scripts.run_py_script(script_path, 'gdal_sieve', '-nomask -st 2 -4 ../alg/data/sieve_src.grd tmp/sieve_1.tif')
dst_ds = gdal.Open('tmp/sieve_1.tif')
dst_band = dst_ds.GetRasterBand(1)
cs_expected = 364
cs = dst_band.Checksum()
dst_band = None
dst_ds = None
if cs == cs_expected \
or gdal.GetConfigOption('CPL_DEBUG', 'OFF') != 'ON':
# Reload because of side effects of run_py_script()
drv = gdal.GetDriverByName('GTiff')
drv.Delete('tmp/sieve_1.tif')
if cs != cs_expected:
print('Got: ', cs)
gdaltest.post_reason('got wrong checksum')
return 'fail'
return 'success'
示例8: test_gdal_edit_py_4
def test_gdal_edit_py_4():
script_path = test_py_scripts.get_py_script('gdal_edit')
if script_path is None:
return 'skip'
shutil.copy('../gcore/data/byte.tif', 'tmp/test_gdal_edit_py.tif')
ds = gdal.Open( 'tmp/test_gdal_edit_py.tif', gdal.GA_Update )
ds.GetRasterBand(1).ComputeStatistics(False)
ds = None
ds = gdal.Open('tmp/test_gdal_edit_py.tif')
if ds.GetRasterBand(1).GetMetadataItem('STATISTICS_MINIMUM') is None:
gdaltest.post_reason('fail')
return 'fail'
ds = None
test_py_scripts.run_py_script(script_path, 'gdal_edit', "tmp/test_gdal_edit_py.tif -unsetstats")
ds = gdal.Open('tmp/test_gdal_edit_py.tif')
if ds.GetRasterBand(1).GetMetadataItem('STATISTICS_MINIMUM') is not None:
gdaltest.post_reason('fail')
return 'fail'
ds = None
try:
os.stat('tmp/test_gdal_edit_py.tif.aux.xml')
gdaltest.post_reason('fail')
return 'fail'
except:
pass
return 'success'
示例9: test_ogr2ogr_py_26
def test_ogr2ogr_py_26():
script_path = test_py_scripts.get_py_script("ogr2ogr")
if script_path is None:
return "skip"
if not ogrtest.have_geos():
return "skip"
try:
os.stat("tmp/poly.shp")
ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource("tmp/poly.shp")
except:
pass
test_py_scripts.run_py_script(
script_path,
"ogr2ogr",
'tmp/poly.shp ../ogr/data/poly.shp -clipdst "POLYGON((479609 4764629,479609 4764817,479764 4764817,479764 4764629,479609 4764629))"',
)
ds = ogr.Open("tmp/poly.shp")
if ds is None or ds.GetLayer(0).GetFeatureCount() != 4:
return "fail"
if ds.GetLayer(0).GetExtent() != (479609, 479764, 4764629, 4764817):
print(ds.GetLayer(0).GetExtent())
gdaltest.post_reason("unexpected extent")
return "fail"
ds.Destroy()
ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource("tmp/poly.shp")
return "success"
示例10: test_ogr2ogr_py_22
def test_ogr2ogr_py_22():
script_path = test_py_scripts.get_py_script("ogr2ogr")
if script_path is None:
return "skip"
test_py_scripts.run_py_script(
script_path,
"ogr2ogr",
'-f "MapInfo File" tmp/testogr2ogr22.mif ../utilities/data/dataforogr2ogr21.csv '
+ '-sql "SELECT comment, name FROM dataforogr2ogr21" -nlt POINT',
)
ds = ogr.Open("tmp/testogr2ogr22.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/testogr2ogr22.mif")
return "fail"
ds.Destroy()
ogr.GetDriverByName("MapInfo File").DeleteDataSource("tmp/testogr2ogr22.mif")
return "success"
示例11: test_gdal_proximity_1
def test_gdal_proximity_1():
script_path = test_py_scripts.get_py_script('gdal_proximity')
if script_path is None:
return 'skip'
drv = gdal.GetDriverByName( 'GTiff' )
dst_ds = drv.Create('tmp/proximity_1.tif', 25, 25, 1, gdal.GDT_Byte )
dst_ds = None
test_py_scripts.run_py_script(script_path, 'gdal_proximity', '../alg/data/pat.tif tmp/proximity_1.tif' )
dst_ds = gdal.Open('tmp/proximity_1.tif')
dst_band = dst_ds.GetRasterBand(1)
cs_expected = 1941
cs = dst_band.Checksum()
dst_band = None
dst_ds = None
if cs != cs_expected:
print('Got: ', cs)
gdaltest.post_reason( 'got wrong checksum' )
return 'fail'
else:
return 'success'
示例12: test_gdal_retile_2
def test_gdal_retile_2():
script_path = test_py_scripts.get_py_script('gdal_retile')
if script_path is None:
return 'skip'
try:
os.mkdir('tmp/outretile2')
except:
pass
test_py_scripts.run_py_script(script_path, 'gdal_retile', '-v -levels 2 -r bilinear -targetDir tmp/outretile2 ../gcore/data/rgba.tif' )
ds = gdal.Open('tmp/outretile2/2/rgba_1_1.tif')
if ds.GetRasterBand(1).Checksum() != 35:
gdaltest.post_reason('wrong checksum for band 1')
print(ds.GetRasterBand(1).Checksum())
return 'fail'
if ds.GetRasterBand(4).Checksum() != 35:
gdaltest.post_reason('wrong checksum for band 4')
print(ds.GetRasterBand(4).Checksum())
return 'fail'
ds = None
return 'success'
示例13: test_gdal_pansharpen_1
def test_gdal_pansharpen_1():
script_path = test_py_scripts.get_py_script('gdal_pansharpen')
if script_path is None:
return 'skip'
src_ds = gdal.Open('../gdrivers/data/small_world.tif')
src_data = src_ds.GetRasterBand(1).ReadRaster()
gt = src_ds.GetGeoTransform()
wkt = src_ds.GetProjectionRef()
src_ds = None
pan_ds = gdal.GetDriverByName('GTiff').Create('tmp/small_world_pan.tif', 800, 400)
gt = [ gt[i] for i in range(len(gt)) ]
gt[1] *= 0.5
gt[5] *= 0.5
pan_ds.SetGeoTransform(gt)
pan_ds.SetProjection(wkt)
pan_ds.GetRasterBand(1).WriteRaster(0,0,800,400,src_data,400,200)
pan_ds = None
test_py_scripts.run_py_script(script_path, 'gdal_pansharpen', ' tmp/small_world_pan.tif ../gdrivers/data/small_world.tif tmp/out.tif')
ds = gdal.Open('tmp/out.tif')
cs = [ ds.GetRasterBand(i+1).Checksum() for i in range(ds.RasterCount) ]
ds = None
gdal.GetDriverByName('GTiff').Delete('tmp/out.tif')
if cs != [4735, 10000, 9742]:
gdaltest.post_reason('fail')
print(cs)
return 'fail'
return 'success'
示例14: test_pct2rgb_4
def test_pct2rgb_4():
try:
from osgeo import gdalnumeric
gdalnumeric.BandRasterIONumPy
except:
return 'skip'
script_path = test_py_scripts.get_py_script('pct2rgb')
if script_path is None:
return 'skip'
test_py_scripts.run_py_script(script_path, 'pct2rgb', '-rgba ../gcore/data/rat.img tmp/test_pct2rgb_4.tif')
ds = gdal.Open('tmp/test_pct2rgb_4.tif')
ori_ds = gdal.Open('../gcore/data/rat.img')
ori_data = struct.unpack('H', ori_ds.GetRasterBand(1).ReadRaster(1990, 1990, 1, 1, 1, 1))[0]
data = (struct.unpack('B', ds.GetRasterBand(1).ReadRaster(1990, 1990, 1, 1, 1, 1))[0],
struct.unpack('B', ds.GetRasterBand(2).ReadRaster(1990, 1990, 1, 1, 1, 1))[0],
struct.unpack('B', ds.GetRasterBand(3).ReadRaster(1990, 1990, 1, 1, 1, 1))[0],
struct.unpack('B', ds.GetRasterBand(4).ReadRaster(1990, 1990, 1, 1, 1, 1))[0],)
ct = ori_ds.GetRasterBand(1).GetRasterColorTable()
entry = ct.GetColorEntry(ori_data)
if entry != data:
return 'fail'
ds = None
ori_ds = None
return 'success'
示例15: test_pct2rgb_1
def test_pct2rgb_1():
try:
from osgeo import gdalnumeric
gdalnumeric.BandRasterIONumPy
except:
return 'skip'
script_path = test_py_scripts.get_py_script('pct2rgb')
if script_path is None:
return 'skip'
test_py_scripts.run_py_script(script_path, 'pct2rgb', 'tmp/test_rgb2pct_1.tif tmp/test_pct2rgb_1.tif' )
ds = gdal.Open('tmp/test_pct2rgb_1.tif')
if ds.GetRasterBand(1).Checksum() != 20963:
print(ds.GetRasterBand(1).Checksum())
return 'fail'
ori_ds = gdal.Open('../gcore/data/rgbsmall.tif')
max_diff = gdaltest.compare_ds(ori_ds, ds)
if max_diff > 18:
return 'fail'
ds = None
ori_ds = None
return 'success'