我尝试使用Python在Erdas中叠加Band1,Band2和Band 3的图像。任何人都建议如何在python中进行。
from imagine import modeler
imagePath = "'C:\\Desktop\\Erdas_Script\\New folder'"
outputPathStack = "'C:\\Desktop\\Erdas_Script\\New folder'"
m = modeler.Model()
ri1 = m.RasterInput("BAND2.tif")
ri2 = m.RasterInput("BAND3.tif")
ri3 = m.RasterInput("BAND4.tif")
ri4 = m.RasterInput("BAND5.tif")
StackBands = m.StackLayers(ri1, ri2, ri3, ri4)
ro = m.RasterOutput(StackBands, outputPathStack + "_stack.img")
m.Execute()
抛出错误
RuntimeError: Intergraph::SpatialModeler::Operator::Execute failed
Intergraph::SpatialModeler::Operator::Execute failed
Intergraph::SpatialModeler::Operator::Execute failed
Intergraph::SpatialModeler::Operator::SetErrorMessage failed
Spatial Model failed in Raster Input. Error: Could not open raster image: BAND2.tif.
答案 0 :(得分:0)
您已将名为imagePath的变量设置为包含图像的文件夹。
您需要在光栅输入中使用它
ri1 = m.RasterInput(imagePath + "\\BAND2.tif")
ri2 = m.RasterInput(imagePath + "\\BAND3.tif")
等
现在脚本可以访问图像。
同时将光栅输出更改为
ro = m.RasterOutput(StackBands, outputPathStack + "\\_stack.img")
这将允许输出放在New Folder目录中。您可能希望在_stack.img前面放置一个描述性名称。目前文件名为_stack.img
您可以找到类似的工作流程here,但代码并未显示出最佳效果,但应该有助于您实现的目标。