我希望使用[ os.path.expanduser
]在我自己的计算机以外的计算机上运行各种GDAL进程。但是,当在单独的PC上运行测试时,我遇到了一个用户名的问题,该用户名带有空格而不是C:\ Users \ Kosher_Moses,用户名是C:\ Users \ Kosher Moses。关于如何强制脚本解决此问题的任何想法吗?
# Set varible for gdal_calc
gdal_calc = "C:\\Program Files (x86)\\GDAL\\gdal_calc.py"
# make dictionary of environmental variables
gdal_env = os.environ.copy()
# modify and add variables
gdal_env["GDAL_DATA"] = "C:\\Program Files (x86)\\GDAL\gdal-data"
gdal_env["GDAL_DRIVER_PATH"] = "C:\\Program Files (x86)\\GDAL\\gdalplugins"
gdal_env["PATH"] = gdal_env["PATH"] + ";C:\\Program Files (x86)\\GDAL"
# Set constants
# The pathway to the images files are nested within the '--outfile=' command
inHVZero = os.path.expanduser('~\\Desktop\\Components\\Zeros\\newHVZeros_.img')
outPlace = os.path.expanduser('~\\\Desktop\\Components\\db_Files\\newHVdB.img')
outVFile = '--outfile='+ outPlace
cmd_HV = ['-A', inHVZero, outVFile, '--calc=10*log10(power(A,2))-83']
#calc_cmd_HV = ['C:\\Program Files (x86)\\GDAL\\gdal_calc.py', '-A', inHVZero, '--outfile='+outPlace, '--calc=10*log10(power(A,2))-83']
inVHZero = os.path.expanduser('~\\Desktop\\Components\\Zeros\\newVHZeros_.img')
outPlace_1 = os.path.expanduser('~\\Desktop\\Components\\db_Files\\newVHdB.img')
outVFile_1 = '--outfile='+ outPlace_1
cmd_VH = ['-A', inVHZero, outVFile_1, '--calc=10*log10(power(A,2))-83']
#calc_cmd_VH = ['C:\\Program Files (x86)\\GDAL\\gdal_calc.py', '-A', inVHZero, '--outfile='+outPlace_1, '--calc=10*log10(power(A,2))-83']
subprocess.call([sys.executable,gdal_calc] + cmd_HV, env=gdal_env)
subprocess.call([sys.executable,gdal_calc] + cmd_VH, env=gdal_env)
不要做:
cmd = "-ot float32 -of HFA"
hvfullCmd = ' '.join([gdalTranslate, cmd, src_dataset.fileName, dst_dataset])
subprocess.call(hvfullCmd)
做:
cmd = ['-ot', 'float32', '-of', 'HFA']
subprocess.call([gdalTranslate] + cmd + [src_dataset.fileName, dst_dataset])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句