Skip to content
Permalink
Browse files
added some more fusion algorihtms
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@161 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed Apr 27, 2012
1 parent ebf7d1e commit 98c2bb0336485132424f37b250575eeb23045dc2
@@ -0,0 +1,43 @@
import os
from sextante.parameters.ParameterFile import ParameterFile
from sextante.outputs.OutputTable import OutputTable
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.fusion.FusionUtils import FusionUtils
from PyQt4 import QtGui
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.fusion.FusionAlgorithm import FusionAlgorithm

class CanopyMaxima(FusionAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
THRESHOLD = "THRESHOLD"
GROUND = "GROUND"


def defineCharacteristics(self):
self.name = "Canopy Maxima"
self.group = "Points"
self.addParameter(ParameterFile(self.INPUT, "Input las layer"))
self.addParameter(ParameterFile(self.GROUND, "Input ground DTM layer [optional, leave blank if not using it]"))
self.addParameter(ParameterNumber(self.THRESHOLD, "Minimum threshold", 0, None, 10.0))
self.addOutput(OutputTable(self.OUTPUT, "Output file with maxima"))
self.addAdvancedModifiers()

def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), "CanopyMaxima.exe")]
commands.append("/verbose")
self.addAdvancedModifiersToCommand(commands)
ground = self.getParameterValue(self.GROUND)
if str(ground).strip() != "":
commands.append("/ground:" + str(ground))
commands.append("/threshold:" + str(self.getParameterValue(self.THRESHOLD)))
files = self.getParameterValue(self.INPUT).split(";")
if len(files) == 1:
commands.append(self.getParameterValue(self.INPUT))
else:
FusionUtils.createFileList(files)
commands.append(FusionUtils.tempFileListFilepath())
commands.append(self.getOutputValue(self.OUTPUT))

FusionUtils.runFusion(commands, progress)
@@ -0,0 +1,58 @@
import os
from sextante.parameters.ParameterFile import ParameterFile
from sextante.fusion.FusionUtils import FusionUtils
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.outputs.OutputRaster import OutputRaster
from sextante.parameters.ParameterSelection import ParameterSelection
import subprocess
from sextante.fusion.FusionAlgorithm import FusionAlgorithm

class CanopyModel(FusionAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
CELLSIZE = "CELLSIZE"
GROUND = "GROUND"
XYUNITS = "XYUNITS"
ZUNITS = "ZUNITS"
UNITS = ["Meter", "Feet"]

def defineCharacteristics(self):
self.name = "Canopy Model"
self.group = "Points"
self.addParameter(ParameterFile(self.INPUT, "Input las layer"))
self.addParameter(ParameterFile(self.GROUND, "Input ground DTM layer [optional, leave blank if not using it]"))
self.addParameter(ParameterNumber(self.CELLSIZE, "Cellsize", 0, None, 10.0))
self.addParameter(ParameterSelection(self.XYUNITS, "XY Units", self.UNITS))
self.addParameter(ParameterSelection(self.ZUNITS, "Z Units", self.UNITS))
self.addOutput(OutputRaster(self.OUTPUT, "Canopy model"))
self.addAdvancedModifiers()

def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), "CanopyModel.exe")]
commands.append("/verbose")
self.addAdvancedModifiersToCommand(commands)
ground = self.getParameterValue(self.GROUND)
if str(ground).strip() != "":
commands.append("/ground:" + str(ground))
outFile = self.getOutputValue(self.OUTPUT)+".dtm"
commands.append(outFile)
commands.append(str(self.getParameterValue(self.CELLSIZE)))
commands.append(self.UNITS[self.getParameterValue(self.XYUNITS)][0])
commands.append(self.UNITS[self.getParameterValue(self.ZUNITS)][0])
commands.append("0")
commands.append("0")
commands.append("0")
commands.append("0")
files = self.getParameterValue(self.INPUT).split(";")
if len(files) == 1:
commands.append(self.getParameterValue(self.INPUT))
else:
FusionUtils.createFileList(files)
commands.append(FusionUtils.tempFileListFilepath())
FusionUtils.runFusion(commands, progress)
commands = [os.path.join(FusionUtils.FusionPath(), "DTM2TIF.exe")]
commands.append(outFile)
commands.append(self.getOutputValue(self.OUTPUT))
p = subprocess.Popen(commands, shell=True)
p.wait()
@@ -0,0 +1,52 @@
import os
from sextante.parameters.ParameterFile import ParameterFile
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.fusion.FusionUtils import FusionUtils
from PyQt4 import QtGui
import subprocess
from sextante.parameters.ParameterExtent import ParameterExtent
from sextante.outputs.OutputFile import OutputFile
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.fusion.FusionAlgorithm import FusionAlgorithm

class ClipData(FusionAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
EXTENT = "EXTENT"
SHAPE = "SHAPE"


def defineCharacteristics(self):
self.name = "Clip Data"
self.group = "Points"
self.addParameter(ParameterFile(self.INPUT, "Input las layer"))
self.addParameter(ParameterExtent(self.EXTENT, "Extent"))
self.addParameter(ParameterSelection(self.SHAPE, "Shape", ["Rectangle","Circle"]))
self.addOutput(OutputFile(self.OUTPUT, "Output clipped las file"))
self.addAdvancedModifiers()

def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), "ClipData.exe")]
commands.append("/verbose")
self.addAdvancedModifiersToCommand(commands)
commands.append("/shape:" + str(self.getParameterValue(self.SHAPE)))
files = self.getParameterValue(self.INPUT).split(";")
if len(files) == 1:
commands.append(self.getParameterValue(self.INPUT))
else:
FusionUtils.createFileList(files)
commands.append(FusionUtils.tempFileListFilepath())
outFile = self.getOutputValue(self.OUTPUT)
commands.append(outFile)
extent = str(self.getParameterValue(self.EXTENT)).split(",")
commands.append(extent[0])
commands.append(extent[2])
commands.append(extent[1])
commands.append(extent[3])
FusionUtils.runFusion(commands, progress)
commands = [os.path.join(FusionUtils.FusionPath(), "LDA2LAS.exe")]
commands.append(outFile)
commands.append(self.getOutputValue(self.OUTPUT))
p = subprocess.Popen(commands, shell=True)
p.wait()
@@ -1,27 +1,25 @@
import os
from sextante.parameters.ParameterFile import ParameterFile
from sextante.outputs.OutputTable import OutputTable
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.fusion.FusionUtils import FusionUtils
from PyQt4 import QtGui
from sextante.fusion.FusionAlgorithm import FusionAlgorithm

class CloudMetrics(GeoAlgorithm):
class CloudMetrics(FusionAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"

def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/tool.png")

def defineCharacteristics(self):
self.name = "Cloud Metrics"
self.group = "Tools"
self.group = "Points"
self.addParameter(ParameterFile(self.INPUT, "Input las layer"))
self.addOutput(OutputTable(self.OUTPUT, "Output file with tabular metric information"))
#self.addCommonParameters()
self.addAdvancedModifiers()

def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), "CloudMetrics.exe")]
commands.append("/verbose")
self.addAdvancedModifiersToCommand(commands)
files = self.getParameterValue(self.INPUT).split(";")
if len(files) == 1:
commands.append(self.getParameterValue(self.INPUT))
@@ -0,0 +1,62 @@
import os
from sextante.parameters.ParameterFile import ParameterFile
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.fusion.FusionUtils import FusionUtils
from PyQt4 import QtGui
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.outputs.OutputRaster import OutputRaster
from sextante.parameters.ParameterSelection import ParameterSelection
import subprocess
from sextante.fusion.FusionAlgorithm import FusionAlgorithm

class Cover(FusionAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
CELLSIZE = "CELLSIZE"
HEIGHTBREAK = "HEIGHTREAK"
GROUND = "GROUND"
XYUNITS = "XYUNITS"
ZUNITS = "ZUNITS"
UNITS = ["Meter", "Feet"]

def defineCharacteristics(self):
self.name = "Cover"
self.group = "Points"
self.addParameter(ParameterFile(self.INPUT, "Input las layer"))
self.addParameter(ParameterFile(self.GROUND, "Input ground DTM layer"))
self.addParameter(ParameterNumber(self.CELLSIZE, "Cellsize", 0, None, 10.0))
self.addParameter(ParameterNumber(self.HEIGHTBREAK, "Heightbreak", 0, None, 10.0))
self.addParameter(ParameterSelection(self.XYUNITS, "XY Units", self.UNITS))
self.addParameter(ParameterSelection(self.ZUNITS, "Z Units", self.UNITS))
self.addOutput(OutputRaster(self.OUTPUT, "Cover"))
self.addAdvancedModifiers()

def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), "Cover.exe")]
commands.append("/verbose")
self.addAdvancedModifiersToCommand(commands)
ground = self.getParameterValue(self.GROUND)
if str(ground).strip() != "":
commands.append("/ground:" + str(ground))
outFile = self.getOutputValue(self.OUTPUT)+".dtm"
commands.append(outFile)
commands.append(str(self.getParameterValue(self.CELLSIZE)))
commands.append(self.UNITS[self.getParameterValue(self.XYUNITS)][0])
commands.append(self.UNITS[self.getParameterValue(self.ZUNITS)][0])
commands.append("0")
commands.append("0")
commands.append("0")
commands.append("0")
files = self.getParameterValue(self.INPUT).split(";")
if len(files) == 1:
commands.append(self.getParameterValue(self.INPUT))
else:
FusionUtils.createFileList(files)
commands.append(FusionUtils.tempFileListFilepath())
FusionUtils.runFusion(commands, progress)
commands = [os.path.join(FusionUtils.FusionPath(), "DTM2TIF.exe")]
commands.append(outFile)
commands.append(self.getOutputValue(self.OUTPUT))
p = subprocess.Popen(commands, shell=True)
p.wait()
@@ -0,0 +1,28 @@
from sextante.core.GeoAlgorithm import GeoAlgorithm
import os
from PyQt4 import QtGui
from sextante.fusion.FusionUtils import FusionUtils
from sextante.parameters.ParameterString import ParameterString

class FusionAlgorithm(GeoAlgorithm):

ADVANCED_MODIFIERS = "ADVANCED_MODIFIERS"

def getIcon(self):
filepath = os.path.dirname(__file__) + "/../images/tool.png"
return QtGui.QIcon(filepath)

def checkBeforeOpeningParametersDialog(self):
path = FusionUtils.FusionPath()
if path == "":
return "Fusion folder is not configured.\nPlease configure it before running Fusion algorithms."

def addAdvancedModifiers(self):
param = ParameterString(self.ADVANCED_MODIFIERS, "Additional modifiers", "")
param.isAdvanced = True
self.addParameter(param)

def addAdvancedModifiersToCommand(self, commands):
s = str(self.getParameterValue(self.ADVANCED_MODIFIERS)).strip()
if s != "":
commands.append(s)
@@ -6,14 +6,18 @@
from sextante.fusion.FusionUtils import FusionUtils
from sextante.fusion.OpenViewerAction import OpenViewerAction
from sextante.fusion.CloudMetrics import CloudMetrics
from sextante.fusion.CanopyMaxima import CanopyMaxima
from sextante.fusion.CanopyModel import CanopyModel
from sextante.fusion.ClipData import ClipData
from sextante.fusion.Cover import Cover


class FusionAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.actions.append(OpenViewerAction())
self.algsList = [(CloudMetrics())]
self.algsList = [CloudMetrics(), CanopyMaxima(), CanopyModel(), ClipData(), Cover()]

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
@@ -28,7 +28,7 @@ def tempFileListFilepath():
def createFileList(files):
out = open(FusionUtils.tempFileListFilepath(), "w")
for f in files:
out.write(f)
out.write(f + "\n")
out.close()

@staticmethod
@@ -3,8 +3,7 @@
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.outputs.OutputRaster import OutputRaster
import os
from sextante.gdal.GdalUtils import GdalUtils
from sextante.parameters.ParameterString import ParameterString
from qgis.core import *
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.parameters.ParameterCrs import ParameterCrs

@@ -31,11 +30,13 @@ def defineCharacteristics(self):
self.addOutput(OutputRaster(warp.OUTPUT, "Output layer"))

def processAlgorithm(self, progress):
srs = self.getParameterValue(warp.DEST_SRS)
self.crs = QgsCoordinateReferenceSystem(int(srs))
commands = ["gdalwarp"]
commands.append("-s_srs")
commands.append("EPSG:" + str(self.getParameterValue(warp.SOURCE_SRS)))
commands.append("-t_srs")
commands.append("EPSG:" + str(self.getParameterValue(warp.DEST_SRS)))
commands.append("EPSG:" + str(srs))
commands.append("-r")
commands.append(warp.METHOD_OPTIONS[self.getParameterValue(warp.METHOD)])
commands.append("-of")
@@ -8,6 +8,9 @@ def __init__(self, name="", description="", default=True):
self.value = None

def setValue(self, value):
if value is None:
self.value = self.default
return True
self.value = value
return True

@@ -3,11 +3,18 @@
class ParameterCrs(Parameter):

def __init__(self, name="", description="", default = "4326"):
'''The values is the EPSG code of the CRS'''
'''The value is the EPSG code of the CRS'''
Parameter.__init__(self, name, description)
self.value = None
self.default = default

def setValue(self, value):
if value is None:
self.value = self.default
return True
self.value = str(value)
return True

def getValueAsCommandLineParameter(self):
return "\"" + str(self.value) + "\""

@@ -8,6 +8,9 @@ def __init__(self, name="", description="", default="0,1,0,1"):
self.value = None #The value is a string in the form "xmin, xmax, ymin, y max"

def setValue(self, text):
if value is None:
self.value = self.default
return True
tokens = text.split(",")
if len(tokens)!= 4:
return False
@@ -18,6 +18,9 @@ def __init__(self, name="", description="", minValue = None, maxValue = None, de
self.value = None

def setValue(self, n):
if value is None:
self.value = self.default
return True
try:
if (float(n) - int(float(n)) == 0):
value = int(float(n))
@@ -8,6 +8,9 @@ def __init__(self, name="", description="", default="0,1"):
self.value = None

def setValue(self, text):
if text is None:
self.value = self.default
return True
tokens = text.split(",")
if len(tokens)!= 2:
return False
Loading

0 comments on commit 98c2bb0

Please sign in to comment.