Geographic Information Systems Asked by djz88426 on January 8, 2021
I am using ERDAS Imagine 2013 and am trying to create a Python script that takes lists created in another script containing the path to each scene’s raw data folder and base image ID’s (for example LC80230282013183LGN00). I then use a for-loop to go to each data folder, selecting the layers to stack to produce my stacked images. Also, I’m working with ETM+ and OLI data so I have a conditional statement to determine which bands to stack (1-7 for OLI and 1-5 & 7 for ETM+). What I have so far will stack the layers for the first data folder in the list, but then I get an error when it attempts to stack layers in the next folder in the list. I’m fairly inexperienced with Python and coding in general and I feel like either my logic is wrong or I’m just way off with my code.
What I have:
from imagine import modeler
from getpath import imageName, imagePath, outputPathStack
m = modeler.Model()
numImages = len(imageName)
for i in range (0,numImages):
#check for landsat 8 image
if "LC8" in str(imageName[i]):
ri1 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B1.tif")
ri2 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B2.tif")
ri3 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B3.tif")
ri4 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B4.tif")
ri5 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B5.tif")
ri6 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B6.tif")
ri7 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B7.tif")
StackBands = m.StackLayers(ri1, ri2, ri3, ri4, ri5, ri6, ri7)
ro = m.RasterOutput(StackBands, outputPathStack +
imageName[i] + "_stack.img")
#check for landsat 7 image
elif "LE7" in str(imageName[i]):
ri1 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B1.tif")
ri2 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B2.tif")
ri3 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B3.tif")
ri4 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B4.tif")
ri5 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B5.tif")
ri6 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B7.tif")
StackBands = m.StackLayers(ri1, ri2, ri3, ri4, ri5, ri6)
ro = m.RasterOutput(StackBands, outputPathStack +
imageName[i] + "_stack.img")
m.Execute()
The error I get is:
File “C:Workspacestacklayers.py”, line 35, in
m.Execute()
RuntimeError: erdas::sblib::Operator::SetErrorMessage failed
Spatial Model failed in Raster Output 2. Error: erdas::sbsupportlib::LayerOperator::OnExecute failed
erdas::sbsupportlib::LayerOpOnExecute::WriteBlock failed
Bad response from exchange.
As commented by the asker:
For anyone that's interested, I was able to get this to work by instead using a python script to first generate parameter files, and then a batch file as documented at http://www.hexagongeospatial.com/Libraries/Support_Documents/Howtobatchlayerstack.sflb.ashx. It isn't what I initially intended to do, but it accomplishes the automation I am looking for in processing 100's of landsat images! I have also been using this method to create parameter files/batch files for some of my .gmd models to automate these as well..it's been quite useful.
Answered by PolyGeo on January 8, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP