Skip to content
Permalink
Browse files

[processing/otb]Add function to customize creation and loading of new…

… applications
  • Loading branch information
amondot authored and volaya committed Nov 4, 2015
1 parent 9c7d206 commit 41c15e770a10db1ca89670514170a252c3763187
@@ -39,19 +39,20 @@

try:
import processing
except ImportError as e:
except ImportError, e:
raise Exception("Processing must be installed and available in PYTHONPATH")

from processing.core.ProcessingConfig import ProcessingConfig

from OTBUtils import OTBUtils



def adaptBinaryMorphologicalOperation(commands_list):
val = commands_list[commands_list.index("-filter") + 1]

def replace_dilate(param, value):
if ".dilate" in unicode(param):
if ".dilate" in str(param):
return param.replace("dilate", value)
else:
return param
@@ -104,7 +105,7 @@ def adaptSplitImage(commands_list):
item = item.replace(".file", ".tif")
if item == "-out":
index = commands_list.index(item)
if "." not in os.path.basename(commands_list[index + 1]):
if "." not in os.path.basename(commands_list[index + 1] ):
commands_list[index + 1] = commands_list[index + 1][:-1] + ".tif" + commands_list[index + 1][-1]
commands_list2.append(item)
return commands_list2
@@ -121,13 +122,12 @@ def adaptLSMSVectorization(commands_list):
item = item.replace(".file", ".shp")
if item == "-out":
index = commands_list.index(item)
if "." not in os.path.basename(commands_list[index + 1]):
if "." not in os.path.basename(commands_list[index + 1] ):
commands_list[index + 1] = commands_list[index + 1][:-1] + ".shp" + commands_list[index + 1][-1]
commands_list2.append(item)

return commands_list2


def adaptComputeImagesStatistics(commands_list):
"""
Ran by default, the extension of output file is .file. Replace it with ".xml"
@@ -140,7 +140,7 @@ def adaptComputeImagesStatistics(commands_list):
commands_list2.append(item)
if item == "-out":
index = commands_list.index(item)
if "." not in os.path.basename(commands_list[index + 1]):
if "." not in os.path.basename(commands_list[index + 1] ):
commands_list[index + 1] = commands_list[index + 1][:-1] + ".xml" + commands_list[index + 1][-1]

return commands_list2
@@ -159,7 +159,7 @@ def adaptKmzExport(commands_list):
item = item.replace(".file", ".kmz")
if item == "-out":
index = commands_list.index(item)
if "." not in os.path.basename(commands_list[index + 1]):
if "." not in os.path.basename(commands_list[index + 1] ):
commands_list[index + 1] = commands_list[index + 1][:-1] + ".kmz" + commands_list[index + 1][-1]

commands_list2.append(item)
@@ -171,10 +171,11 @@ def adaptColorMapping(commands_list):
The output of this algorithm must be in uint8.
"""
indexInput = commands_list.index("-out")
commands_list[indexInput + 1] = commands_list[indexInput + 1] + " uint8"
commands_list[indexInput+1] = commands_list[indexInput+1] + " uint8"
return commands_list



def adaptStereoFramework(commands_list):
"""
Remove parameter and user value instead of giving None.
@@ -185,7 +186,7 @@ def adaptStereoFramework(commands_list):
for item in commands_list:
if "None" in item:
index = commands_list2.index(item)
argumentToRemove = commands_list2[index - 1]
argumentToRemove = commands_list2[index-1]
commands_list2.remove(item)
commands_list2.remove(argumentToRemove)
#commands_list2.append(item)
@@ -203,7 +204,7 @@ def adaptComputeConfusionMatrix(commands_list):
item = item.replace(".file", ".csv")
if item == "-out":
index = commands_list.index(item)
if "." not in os.path.basename(commands_list[index + 1]):
if "." not in os.path.basename(commands_list[index + 1] ):
commands_list[index + 1] = commands_list[index + 1][:-1] + ".csv" + commands_list[index + 1][-1]

commands_list2.append(item)
@@ -221,12 +222,12 @@ def adaptRadiometricIndices(commands_list):
"ri" : "Soil:RI", "ci" : "Soil:CI", "bi" : "Soil:BI", "bi2" : "Soil:BI2"}
"""
# "laindvilog" : , "lairefl" : , "laindviformo" : ,
indices = {"ndvi": "Vegetation:NDVI", "tndvi": "Vegetation:TNDVI", "rvi": "Vegetation:RVI", "savi": "Vegetation:SAVI",
"tsavi": "Vegetation:TSAVI", "msavi": "Vegetation:MSAVI", "msavi2": "Vegetation:MSAVI2", "gemi": "Vegetation:GEMI",
"ipvi": "Vegetation:IPVI",
"ndwi": "Water:NDWI", "ndwi2": "Water:NDWI2", "mndwi": "Water:MNDWI", "ndpi": "Water:NDPI",
"ndti": "Water:NDTI",
"ri": "Soil:RI", "ci": "Soil:CI", "bi": "Soil:BI", "bi2": "Soil:BI2"}
indices = {"ndvi" : "Vegetation:NDVI", "tndvi" : "Vegetation:TNDVI", "rvi" : "Vegetation:RVI", "savi" : "Vegetation:SAVI",
"tsavi" : "Vegetation:TSAVI", "msavi" : "Vegetation:MSAVI", "msavi2" : "Vegetation:MSAVI2", "gemi" : "Vegetation:GEMI",
"ipvi" : "Vegetation:IPVI",
"ndwi" : "Water:NDWI", "ndwi2" : "Water:NDWI2", "mndwi" :"Water:MNDWI" , "ndpi" : "Water:NDPI",
"ndti" : "Water:NDTI",
"ri" : "Soil:RI", "ci" : "Soil:CI", "bi" : "Soil:BI", "bi2" : "Soil:BI2"}
for item in commands_list:
if item in indices:
commands_list[commands_list.index(item)] = indices[item]
@@ -250,7 +251,7 @@ def adaptConnectedComponentSegmentation(commands_list):
for item in commands_list:
if "None" in item:
index = commands_list2.index(item)
argumentToRemove = commands_list2[index - 1]
argumentToRemove = commands_list2[index-1]
commands_list2.remove(item)
commands_list2.remove(argumentToRemove)
#commands_list2.append(item)
@@ -288,36 +289,53 @@ def adaptTrainImagesClassifier(commands_list):
adaptGeoidSrtm(commands_list)
return commands_list


def adaptGeoidSrtm(commands_list):
"""
Check geoid file, srtm folder and given elevation and manage arguments.
"""
srtm, geoid = ckeckGeoidSrtmSettings()

if srtm:
if commands_list[0].endswith("ExtractROI"):

if srtm :
if commands_list[0].endswith("ExtractROI") :
commands_list.append("-mode.fit.elev.dem")
commands_list.append(srtm)
else:
else :
commands_list.append("-elev.dem")
commands_list.append(srtm)
if geoid:
if commands_list[0].endswith("ExtractROI"):
if geoid :
if commands_list[0].endswith("ExtractROI") :
commands_list.append("-mode.fit.elev.geoid")
commands_list.append(geoid)
else:
else :
commands_list.append("-elev.geoid")
commands_list.append(geoid)


def adaptComputePolylineFeatureFromImage(commands_list):
"""
Remove parameter and user value instead of giving None.
Check geoid file, srtm folder and given elevation and manage arguments.
"""
commands_list2 = commands_list
adaptGeoidSrtm(commands_list2)
for item in commands_list:
if "None" in item:
index = commands_list2.index(item)
argumentToRemove = commands_list2[index - 1]
commands_list2.remove(item)
commands_list2.remove(argumentToRemove)
# commands_list2.append(item)
return commands_list2


def ckeckGeoidSrtmSettings():
folder = ProcessingConfig.getSetting(OTBUtils.OTB_SRTM_FOLDER)
if folder is None:
folder = ""
folder =""

filepath = ProcessingConfig.getSetting(OTBUtils.OTB_GEOID_FILE)
if filepath is None:
filepath = ""
filepath =""

return folder, filepath
@@ -648,6 +648,82 @@ def getStereoFramework(available_app, original_dom_document):
return [the_root]


def getRasterization(available_app, original_dom_document):
"""
Let only rasterization with an reference image
Let only mode auto.
Remove all parameters which should be updated once the input file given.
Split by SRS : EPSG, fit to ortho, lambert-wgs84 and UTM.
Each of these SRS have their own parameters modified in this fonction.
Delete GEOID and DEM parameter as they are not updated at the creation of the otb algorithms when you launch QGIS.
The values are picked from the settings.
"""
the_list = []
rasterization_image = original_dom_document

import copy
rasterization_manual = copy.deepcopy(original_dom_document)

old_app_name = rasterization_image.find('key').text

remove_parameter_by_key(rasterization_image, 'szx')
remove_parameter_by_key(rasterization_image, 'szy')
remove_parameter_by_key(rasterization_image, 'epsg')
remove_parameter_by_key(rasterization_image, 'orx')
remove_parameter_by_key(rasterization_image, 'ory')
remove_parameter_by_key(rasterization_image, 'spx')
remove_parameter_by_key(rasterization_image, 'spy')

remove_parameter_by_key(rasterization_manual, 'im')

# set a new name according to the choice
rasterization_image.find('key').text = '%s-%s' % (old_app_name, "image")
rasterization_image.find('longname').text = '%s (%s)' % (old_app_name, "image")
defaultWrite('%s-%s' % (old_app_name, "image"), rasterization_image)
rasterization_manual.find('key').text = '%s-%s' % (old_app_name, "manual")
rasterization_manual.find('longname').text = '%s (%s)' % (old_app_name, "manual")
defaultWrite('%s-%s' % (old_app_name, "manual"), rasterization_manual)
return [rasterization_image, rasterization_manual]


def getVectorDataExtractROI(available_app, original_dom_document):
"""
Delete GEOID and DEM parameter as they are not updated at the creation of the otb algorithms when you launch QGIS.
The values are picked from the settings.
"""
the_root = original_dom_document
deleteGeoidSrtm(the_root)
defaultWrite(available_app, the_root)
return [the_root]


def getVectorDataReprojection(available_app, original_dom_document):
"""
"""
the_root = original_dom_document
deleteGeoidSrtm(the_root)
the_list = defaultSplit(available_app, the_root, 'out.proj')
return the_list


def getComputePolylineFeatureFromImage(available_app, original_dom_document):
"""
Delete GEOID and DEM parameter as they are not updated at the creation of the otb algorithms when you launch QGIS.
The values are picked from the settings.
"""
the_root = original_dom_document
deleteGeoidSrtm(the_root)
defaultWrite(available_app, the_root)
return [the_root]


def getDespeckle(available_app, original_dom_document):
"""
"""
the_root = original_dom_document
the_list = defaultSplit(available_app, the_root, 'filter')
return the_list


def deleteGeoidSrtm(doc) :
"""

0 comments on commit 41c15e7

Please sign in to comment.
You can’t perform that action at this time.