Skip to content

Commit

Permalink
OTB ROI: apply to vectors
Browse files Browse the repository at this point in the history
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@260 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
cpolymeris@gmail.com committed Jun 22, 2012
1 parent 2dbc903 commit 8373fe5
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/sextante/otb/OTBAlgorithm.py
Expand Up @@ -68,6 +68,7 @@ def defineCharacteristicsFromFile(self):
self.addParameter(param)
elif line.startswith("Extent"):
self.addParameter(ParameterExtent(self.REGION_OF_INTEREST, "Region of interest", "0,1,0,1"))
self.hasROI = True
else:
self.addOutput(OutputFactory.getFromString(line))
line = lines.readline().strip("\n").strip()
Expand All @@ -86,16 +87,22 @@ def processAlgorithm(self, progress):
commands = []
commands.append(path + os.sep + self.cliName)

self.roiVectors = {}
self.roiRasters = {}
for param in self.parameters:
if param.value == None or param.value == "":
continue
if isinstance(param, ParameterVector):
commands.append(param.name)
commands.append(param.value)
if self.hasROI:
roiFile = SextanteUtils.getTempFilename('shp')
commands.append(roiFile)
self.roiVectors[param.value] = roiFile
else:
commands.append(param.value)
if isinstance(param, ParameterRaster):
commands.append(param.name)
if self.roiFile:
if self.hasROI:
roiFile = SextanteUtils.getTempFilename('tif')
commands.append(roiFile)
self.roiRasters[param.value] = roiFile
Expand All @@ -121,22 +128,33 @@ def processAlgorithm(self, progress):
for out in self.outputs:
commands.append(out.name)
commands.append(out.value)

for roiInput, roiFile in self.roiRasters.items():
startX, startY = float(self.roiValues[0]), float(self.roiValues[1])
sizeX = float(self.roiValues[2]) - startX
sizeY = float(self.roiValues[3]) - startY
helperCommands = [
"otbcli_ExtractROI",
"-in", self.roiInput,
"-out", self.roiFile,
"-in", roiInput,
"-out", roiFile,
"-startx", str(startX),
"-starty", str(startY),
"-sizex", str(sizeX),
"-sizey", str(sizeY)]
SextanteLog.addToLog(SextanteLog.LOG_INFO, helperCommands)
OTBUtils.executeOtb(helperCommands, progress)

if self.roiRasters:
supportRaster = self.roiRasters.itervalues().next()
for roiInput, roiFile in self.roiVectors.items():
helperCommands = [
"otbcli_VectorDataExtractROIApplication",
"-vd.in", roiInput,
"-io.in", supportRaster,
"-io.out", roiFile,
"-elev.dem.path", OTBUtils.otbSRTMPath()]
SextanteLog.addToLog(SextanteLog.LOG_INFO, helperCommands)
OTBUtils.executeOtb(helperCommands, progress)

loglines = []
loglines.append("OTB execution command")
for line in commands:
Expand Down

0 comments on commit 8373fe5

Please sign in to comment.