Skip to content
Permalink
Browse files
[processing] more changes to fusion lidar algorithms
  • Loading branch information
volaya committed Jul 1, 2014
1 parent b44a256 commit dd8dbc23daecf437c74fe03339e2777d1ee23e3e
@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
ASCII2DTM.py
---------------------
Date : May 2014
Copyright : (C) 2014 by Niccolo' Marchi
Email : sciurusurbanus at hotmail dot it
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = "Niccolo' Marchi"
__date__ = 'May 2014'
__copyright__ = "(C) 2014 by Niccolo' Marchi"

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

import os
import subprocess
from processing.parameters.ParameterFile import ParameterFile
from processing.parameters.ParameterSelection import ParameterSelection
from processing.parameters.ParameterNumber import ParameterNumber
from processing.outputs.OutputFile import OutputFile
from FusionAlgorithm import FusionAlgorithm
from FusionUtils import FusionUtils


class ASCII2DTM(FusionAlgorithm):

INPUT = 'INPUT'
OUTPUT = 'OUTPUT'
COORDSYS = 'COORDSYS'
XYUNITS = 'XYUNITS'
ZUNITS = 'ZUNITS'
UNITS = ['Meter', 'Feet']
ZONE = 'ZONE'

def defineCharacteristics(self):
self.name = 'ASCII to DTM'
self.group = 'Conversion'
self.addParameter(ParameterFile(self.INPUT, 'Input ESRI ASCII layer'))
self.addParameter(ParameterSelection(self.XYUNITS, 'XY Units',
self.UNITS))
self.addParameter(ParameterSelection(self.ZUNITS, 'Z Units',
self.UNITS))
self.addParameter(ParameterSelection(self.COORDSYS, 'Coordinate system',
['unknown', 'UTM', 'state plane']))
self.addParameter(ParameterNumber(self.ZONE, "Coordinate system zone ('0' for unknown)", 0, None,
0))
self.addOutput(OutputFile(self.OUTPUT, 'Output surface', 'dtm'))
self.addAdvancedModifiers()

def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), 'ASCII2DTM.exe')]
commands.append('/verbose')
self.addAdvancedModifiersToCommand(commands)
outFile = self.getOutputValue(self.OUTPUT)
commands.append(outFile)
commands.append(self.UNITS[self.getParameterValue(self.XYUNITS)][0])
commands.append(self.UNITS[self.getParameterValue(self.ZUNITS)][0])
commands.append(str(self.getParameterValue(self.COORDSYS)))
commands.append(str(self.getParameterValue(self.ZONE)))
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)
@@ -26,11 +26,14 @@
__revision__ = '$Format:%H$'

import os
from PyQt4 import QtGui
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.parameters.ParameterFile import ParameterFile
from processing.parameters.ParameterNumber import ParameterNumber
from processing.parameters.ParameterBoolean import ParameterBoolean
from processing.outputs.OutputTable import OutputTable
from FusionUtils import FusionUtils
from FusionAlgorithm import FusionAlgorithm
from fusion.FusionUtils import FusionUtils
from fusion.FusionAlgorithm import FusionAlgorithm


class CanopyMaxima(FusionAlgorithm):
@@ -39,24 +42,41 @@ class CanopyMaxima(FusionAlgorithm):
OUTPUT = 'OUTPUT'
THRESHOLD = 'THRESHOLD'
GROUND = 'GROUND'
SUMMARY = 'SUMMARY'
PARAM_A = 'PARAM_A'
PARAM_C = 'PARAM_C'

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',
self.addParameter(ParameterFile(self.INPUT, 'Input FUSION canopy height model'))
self.addParameter(ParameterFile(self.GROUND, 'Input ground .dtm layer [optional]'))
self.addParameter(ParameterNumber(self.THRESHOLD, 'Height threshold',
0, None, 10.0))
### begin
self.addParameter(ParameterNumber(self.PARAM_A, 'Variable window size: parameter A',
0, None, 2.51503))
self.addParameter(ParameterNumber(self.PARAM_C, 'Parameter C',
0, None, 0.00901))
self.addParameter(ParameterBoolean(self.SUMMARY, 'Summary (tree height summary statistics)',
False))
### end
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')
### begin
commands.append('/wse:' + str(self.getParameterValue(self.PARAM_A)) + ',0,' + str(self.getParameterValue(self.PARAM_C)) + ',0')
if self.getParameterValue(self.SUMMARY) == True:
commands.append('/summary')
### end
self.addAdvancedModifiersToCommand(commands)
ground = self.getParameterValue(self.GROUND)
if str(ground).strip() != '':
## here it's necessary to have the support for multiple files like for INPUT.
if str(ground).strip():
commands.append('/ground:' + str(ground))
commands.append('/threshold:'
+ str(self.getParameterValue(self.THRESHOLD)))
@@ -43,7 +43,6 @@ class CanopyModel(FusionAlgorithm):

INPUT = 'INPUT'
OUTPUT_DTM = 'OUTPUT_DTM'
OUTPUT_ASCII = 'OUTPUT_ASCII'
CELLSIZE = 'CELLSIZE'
XYUNITS = 'XYUNITS'
ZUNITS = 'ZUNITS'
@@ -53,7 +52,6 @@ class CanopyModel(FusionAlgorithm):
SMOOTH = 'SMOOTH'
SLOPE = 'SLOPE'
CLASS = 'CLASS'
ASCII = 'ASCII'
ADVANCED_MODIFIERS = 'ADVANCED_MODIFIERS'

def defineCharacteristics(self):
@@ -63,22 +61,20 @@ def defineCharacteristics(self):
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.addParameter(ParameterBoolean(self.ASCII, 'ASCII Output?'))
self.addOutput(OutputFile(self.OUTPUT_DTM, 'DTM Output Surface', 'dtm'))
self.addOutput(OutputFile(self.OUTPUT_ASCII, 'ASCII Output Surface', 'asc'))
self.addOutput(OutputFile(self.OUTPUT_DTM, 'DTM Output Surface', 'dtm'))
ground = ParameterFile(self.GROUND, 'Input ground DTM layer', False, True)
ground.isAdvanced = True
self.addParameter(ground)
median = ParameterString(self.MEDIAN, 'Median (set blank if not used)', '', False, True)
median = ParameterString(self.MEDIAN, 'Median', '', False, True)
median.isAdvanced = True
self.addParameter(median)
smooth = ParameterString(self.SMOOTH, 'Smooth (set blank if not used)', '', False, True)
smooth = ParameterString(self.SMOOTH, 'Smooth', '', False, True)
smooth.isAdvanced = True
self.addParameter(smooth)
slope = ParameterString(self.SLOPE, 'Slope (set blank if not used)', '', False, True)
slope = ParameterString(self.SLOPE, 'Slope', '', False, True)
slope.isAdvanced = True
self.addParameter(slope)
class_var = ParameterString(self.CLASS, 'Class (set blank if not used)', '', False, True)
class_var = ParameterString(self.CLASS, 'Class', '', False, True)
class_var.isAdvanced = True
self.addParameter(class_var)
advance_modifiers = ParameterString(self.ADVANCED_MODIFIERS, 'Additional modifiers', '', False, True)
@@ -89,23 +85,23 @@ def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), 'CanopyModel.exe')]
commands.append('/verbose')
ground = self.getParameterValue(self.GROUND)
if str(ground).strip() != '':
if str(ground).strip():
commands.append('/ground:' + str(ground))
median = self.getParameterValue(self.MEDIAN)
if str(median).strip() != '':
if str(median).strip():
commands.append('/median:' + str(median))
smooth = self.getParameterValue(self.SMOOTH)
if str(smooth).strip() != '':
if str(smooth).strip():
commands.append('/smooth:' + str(smooth))
slope = self.getParameterValue(self.SLOPE)
if str(slope).strip() != '':
if str(slope).strip():
commands.append('/slope:' + str(slope))
class_var = self.getParameterValue(self.CLASS)
if str(class_var).strip() != '':
if str(class_var).strip():
commands.append('/class:' + str(class_var))
advance_modifiers = str(self.getParameterValue(self.ADVANCED_MODIFIERS)).strip()
if advance_modifiers != '':
commands.append(s)
if advance_modifiers:
commands.append(advance_modifiers)
commands.append(self.getOutputValue(self.OUTPUT_DTM))
commands.append(str(self.getParameterValue(self.CELLSIZE)))
commands.append(self.UNITS[self.getParameterValue(self.XYUNITS)][0])
@@ -121,10 +117,3 @@ def processAlgorithm(self, progress):
FusionUtils.createFileList(files)
commands.append(FusionUtils.tempFileListFilepath())
FusionUtils.runFusion(commands, progress)
ascii = self.getParameterValue(self.ASCII)
if ascii == 1:
commands = [os.path.join(FusionUtils.FusionPath(), 'DTM2ASCII.exe')]
commands.append(self.getOutputValue(self.OUTPUT_DTM))
commands.append(self.getOutputValue(self.OUTPUT_ASCII))
p = subprocess.Popen(commands, shell=True)
p.wait()
@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
DTM2TIF.py
---------------------
Date : May 2014
Copyright : (C) 2014 by Niccolo' Marchi
Email : sciurusurbanus at hotmail dot it
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = "Niccolo' Marchi"
__date__ = 'May 2014'
__copyright__ = "(C) 2014 by Niccolo' Marchi"

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

import os
from processing.parameters.ParameterFile import ParameterFile
from processing.outputs.OutputRaster import OutputRaster
from FusionAlgorithm import FusionAlgorithm
from FusionUtils import FusionUtils


class DTM2TIF(FusionAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
CSV = 'CSV'


def defineCharacteristics(self):
self.name = "DTM to TIF"
self.group = "Conversion"
self.addParameter(ParameterFile(self.INPUT, "Input .dtm layer"))
self.addOutput(OutputRaster(self.OUTPUT, 'Output file name'))
self.addAdvancedModifiers()

def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), "DTM2TIF.exe")]
commands.append("/verbose")
self.addAdvancedModifiersToCommand(commands)
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)

FusionUtils.runFusion(commands, progress)
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
FirstLastReturn.py
---------------------
Date : May 2014
Copyright : (C) 2014 by Niccolo' Marchi
Email : sciurusurbanus at hotmail dot it
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = "Niccolo' Marchi"
__date__ = 'May 2014'
__copyright__ = "(C) 2014 by Niccolo' Marchi"

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

import os
from processing.parameters.ParameterFile import ParameterFile
from processing.parameters.ParameterBoolean import ParameterBoolean
from processing.outputs.OutputFile import OutputFile
from FusionAlgorithm import FusionAlgorithm
from FusionUtils import FusionUtils


class FirstLastReturn(FusionAlgorithm):

INPUT = 'INPUT'
OUTPUT = 'OUTPUT'
SWITCH = 'SWITCH'


def defineCharacteristics(self):
self.name = 'First&Last Return'
self.group = 'Points'
self.addParameter(ParameterFile(self.INPUT, 'Input .las'))
self.addParameter(ParameterBoolean(self.SWITCH, 'Use LAS info', True))
self.addOutput(OutputFile(self.OUTPUT, 'Output layers'))
self.addAdvancedModifiers()

def processAlgorithm(self, progress):
commands = [os.path.join(FusionUtils.FusionPath(), 'FirstLastReturn.exe')]
commands.append('/verbose')
if self.getParameterValue(self.SWITCH) == True:
commands.append('/uselas')
self.addAdvancedModifiersToCommand(commands)
outFile = self.getOutputValue(self.OUTPUT)
commands.append(outFile)
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)

0 comments on commit dd8dbc2

Please sign in to comment.