我希望使用[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)
答案 0 :(得分:1)
不要这样做:
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])