Skip to content

Commit

Permalink
[processing] update of lidar algorithms
Browse files Browse the repository at this point in the history
Provided by Martin Isenburg
  • Loading branch information
volaya committed Dec 22, 2014
1 parent 9e879ed commit 6c7d61f
Show file tree
Hide file tree
Showing 73 changed files with 2,359 additions and 196 deletions.
Expand Up @@ -8,7 +8,7 @@
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
---------------------
Date : April 2014
Date : April, October 2014
Copyright : (C) 2014 by Martin Isenburg
Email : martin near rapidlasso point com
---------------------
Expand Down Expand Up @@ -81,6 +81,30 @@
from lastools.lastilePro import lastilePro
from lastools.lasgroundPro import lasgroundPro
from lastools.las2demPro import las2demPro
from lastools.lasheightPro import lasheightPro
from lastools.laszipPro import laszipPro
from lastools.lasgridPro import lasgridPro
from lastools.lasduplicatePro import lasduplicatePro
from lastools.lassortPro import lassortPro
from lastools.lasclassifyPro import lasclassifyPro
from lastools.lasthinPro import lasthinPro
from lastools.lasnoisePro import lasnoisePro
from lastools.lasindexPro import lasindexPro
from lastools.lascanopyPro import lascanopyPro
from lastools.blast2demPro import blast2demPro
from lastools.lasboundaryPro import lasboundaryPro
from lastools.lasinfoPro import lasinfoPro
from lastools.las2lasPro_filter import las2lasPro_filter
from lastools.las2lasPro_project import las2lasPro_project
from lastools.las2lasPro_transform import las2lasPro_transform
from lastools.lasoveragePro import lasoveragePro
from lastools.txt2lasPro import txt2lasPro
from lastools.las2txtPro import las2txtPro
from lastools.blast2isoPro import blast2isoPro
from lastools.lasvalidatePro import lasvalidatePro
from lastools.lasmergePro import lasmergePro
from lastools.lasviewPro import lasviewPro
from lastools.lasoverlapPro import lasoverlapPro

from lastools.flightlinesToDTMandDSM import flightlinesToDTMandDSM
from lastools.flightlinesToCHM import flightlinesToCHM
Expand All @@ -105,7 +129,6 @@
from fusion.FilterData import FilterData
from fusion.FusionUtils import FusionUtils


class LidarToolsAlgorithmProvider(AlgorithmProvider):

def __init__(self):
Expand All @@ -115,7 +138,7 @@ def __init__(self):

# LAStools for processing single files

if isWindows():
if (isWindows() or LAStoolsUtils.hasWine()):
lastools = [
lasground(), lasheight(), lasclassify(), lasclip(), lastile(),
lascolor(), lasgrid(), las2dem(), blast2dem(), las2iso(), blast2iso(),
Expand All @@ -138,20 +161,27 @@ def __init__(self):

# LAStools Production for processing folders of files

if isWindows():
if (isWindows() or LAStoolsUtils.hasWine()):
lastoolsPro = [
lastilePro(), lasgroundPro(), las2demPro()
lastilePro(), lasgroundPro(), las2demPro(), lasheightPro(), laszipPro(),
lasduplicatePro(), lasgridPro(), lassortPro(), lasclassifyPro(), lasthinPro(),
lasnoisePro(), lasindexPro(), lascanopyPro(), blast2demPro(), lasboundaryPro(),
lasinfoPro(), las2lasPro_filter(), las2lasPro_project(), las2lasPro_transform(),
lasoveragePro(), txt2lasPro(), las2txtPro(), blast2isoPro(), lasvalidatePro(),
lasmergePro(), lasviewPro(), lasoverlapPro()
]
else:
lastoolsPro = [
laszipPro(), lasindexPro(), lasinfoPro(), las2lasPro_filter(), las2lasPro_project(),
las2lasPro_transform(), txt2lasPro(), las2txtPro(), lasvalidatePro(), lasmergePro()
]
for alg in lastoolsPro:
alg.group = 'LAStools Production'
self.algsList.extend(lastoolsPro)

# some examples for LAStools Pipelines

if isWindows():
if (isWindows() or LAStoolsUtils.hasWine()):
lastoolsPipe = [
flightlinesToDTMandDSM(), flightlinesToCHM(), flightlinesToSingleCHMpitFree(), hugeFileClassify(),
hugeFileGroundClassify(), hugeFileNormalize()
Expand Down
48 changes: 41 additions & 7 deletions python/plugins/processing/algs/lidar/lastools/LAStoolsAlgorithm.py
Expand Up @@ -45,10 +45,12 @@
class LAStoolsAlgorithm(GeoAlgorithm):

VERBOSE = "VERBOSE"
GUI = "GUI"
CORES = "CORES"
INPUT_LASLAZ = "INPUT_LASLAZ"
INPUT_DIRECTORY = "INPUT_DIRECTORY"
INPUT_WILDCARDS = "INPUT_WILDCARDS"
MERGED = "MERGED"
OUTPUT_LASLAZ = "OUTPUT_LASLAZ"
OUTPUT_DIRECTORY = "OUTPUT_DIRECTORY"
OUTPUT_APPENDIX = "OUTPUT_APPENDIX"
Expand All @@ -65,21 +67,22 @@ class LAStoolsAlgorithm(GeoAlgorithm):
HORIZONTAL_FEET = "HORIZONTAL_FEET"
VERTICAL_FEET = "VERTICAL_FEET"
FILES_ARE_FLIGHTLINES = "FILES_ARE_FLIGHTLINES"
APPLY_FILE_SOURCE_ID = "APPLY_FILE_SOURCE_ID"
STEP = "STEP"
FILTER_RETURN_CLASS_FLAGS1 = "FILTER_RETURN_CLASS_FLAGS1"
FILTER_RETURN_CLASS_FLAGS2 = "FILTER_RETURN_CLASS_FLAGS2"
FILTER_RETURN_CLASS_FLAGS3 = "FILTER_RETURN_CLASS_FLAGS3"
FILTERS_RETURN_CLASS_FLAGS = ["---", "keep_last", "keep_first", "keep_middle", "keep_single", "drop_single",
"keep_double", "keep_class 2", "keep_class 2 8", "keep_class 8", "keep_class 6",
"keep_class 9", "keep_class 3 4 5", "keep_class 2 6", "drop_class 7", "drop_withheld"]
"keep_class 9", "keep_class 3 4 5", "keep_class 2 6", "drop_class 7", "drop_withheld", "drop_synthetic"]
FILTER_COORDS_INTENSITY1 = "FILTER_COORDS_INTENSITY1"
FILTER_COORDS_INTENSITY2 = "FILTER_COORDS_INTENSITY2"
FILTER_COORDS_INTENSITY3 = "FILTER_COORDS_INTENSITY3"
FILTER_COORDS_INTENSITY1_ARG = "FILTER_COORDS_INTENSITY1_ARG"
FILTER_COORDS_INTENSITY2_ARG = "FILTER_COORDS_INTENSITY2_ARG"
FILTER_COORDS_INTENSITY3_ARG = "FILTER_COORDS_INTENSITY3_ARG"
FILTERS_COORDS_INTENSITY = ["---", "clip_x_above", "clip_x_below", "clip_y_above", "clip_y_below", "clip_z_above",
"clip_z_below", "drop_intensity_above", "drop_intensity_below", "drop_gps_time_above",
FILTERS_COORDS_INTENSITY = ["---", "drop_x_above", "drop_x_below", "drop_y_above", "drop_y_below", "drop_z_above",
"drop_z_below", "drop_intensity_above", "drop_intensity_below", "drop_gps_time_above",
"drop_gps_time_below", "drop_scan_angle_above", "drop_scan_angle_below", "keep_point_source",
"drop_point_source", "drop_point_source_above", "drop_point_source_below", "keep_user_data",
"drop_user_data", "drop_user_data_above", "drop_user_data_below", "keep_every_nth",
Expand Down Expand Up @@ -110,10 +113,13 @@ def checkBeforeOpeningParametersDialog(self):

def addParametersVerboseGUI(self):
self.addParameter(ParameterBoolean(LAStoolsAlgorithm.VERBOSE, "verbose", False))
self.addParameter(ParameterBoolean(LAStoolsAlgorithm.GUI, "open LAStools GUI", False))

def addParametersVerboseCommands(self, commands):
if self.getParameterValue(LAStoolsAlgorithm.VERBOSE):
commands.append("-v")
if self.getParameterValue(LAStoolsAlgorithm.GUI):
commands.append("-gui")

def addParametersCoresGUI(self):
self.addParameter(ParameterNumber(LAStoolsAlgorithm.CORES, "number of cores", 1, 32, 4))
Expand All @@ -125,7 +131,7 @@ def addParametersCoresCommands(self, commands):
commands.append(str(cores))

def addParametersPointInputGUI(self):
self.addParameter(ParameterFile(LAStoolsAlgorithm.INPUT_LASLAZ, "input LAS/LAZ file"))
self.addParameter(ParameterFile(LAStoolsAlgorithm.INPUT_LASLAZ, "input LAS/LAZ file", False, False))

def addParametersPointInputCommands(self, commands):
input = self.getParameterValue(LAStoolsAlgorithm.INPUT_LASLAZ)
Expand All @@ -134,7 +140,7 @@ def addParametersPointInputCommands(self, commands):
commands.append(input)

def addParametersPointInputFolderGUI(self):
self.addParameter(ParameterFile(LAStoolsAlgorithm.INPUT_DIRECTORY, "input directory", True))
self.addParameter(ParameterFile(LAStoolsAlgorithm.INPUT_DIRECTORY, "input directory", True, False))
self.addParameter(ParameterString(LAStoolsAlgorithm.INPUT_WILDCARDS, "input wildcard(s)", "*.laz"))

def addParametersPointInputFolderCommands(self, commands):
Expand All @@ -147,6 +153,27 @@ def addParametersPointInputFolderCommands(self, commands):
else:
commands.append('"' + wildcard + '"')

def addParametersPointInputMergedGUI(self):
self.addParameter(ParameterBoolean(LAStoolsAlgorithm.MERGED, "merge all input files on-the-fly into one", False))

def addParametersPointInputMergedCommands(self, commands):
if self.getParameterValue(LAStoolsAlgorithm.MERGED):
commands.append("-merged")

def addParametersGenericInputFolderGUI(self, wildcard):
self.addParameter(ParameterFile(LAStoolsAlgorithm.INPUT_DIRECTORY, "input directory", True, False))
self.addParameter(ParameterString(LAStoolsAlgorithm.INPUT_WILDCARDS, "input wildcard(s)", wildcard))

def addParametersGenericInputFolderCommands(self, commands):
input = self.getParameterValue(LAStoolsAlgorithm.INPUT_DIRECTORY)
wildcards = self.getParameterValue(LAStoolsAlgorithm.INPUT_WILDCARDS).split()
for wildcard in wildcards:
commands.append("-i")
if input != None:
commands.append('"' + input + "\\" + wildcard + '"')
else:
commands.append('"' + wildcard + '"')

def addParametersHorizontalFeetGUI(self):
self.addParameter(ParameterBoolean(LAStoolsAlgorithm.HORIZONTAL_FEET, "horizontal feet", False))

Expand All @@ -170,12 +197,19 @@ def addParametersHorizontalAndVerticalFeetCommands(self, commands):
self.addParametersVerticalFeetCommands(commands)

def addParametersFilesAreFlightlinesGUI(self):
self.addParameter(ParameterBoolean(LAStoolsAlgorithm.FILES_ARE_FLIGHTLINES, "files are flightlines", True))
self.addParameter(ParameterBoolean(LAStoolsAlgorithm.FILES_ARE_FLIGHTLINES, "files are flightlines", False))

def addParametersFilesAreFlightlinesCommands(self, commands):
if self.getParameterValue(LAStoolsAlgorithm.FILES_ARE_FLIGHTLINES):
commands.append("-files_are_flightlines")

def addParametersApplyFileSourceIdGUI(self):
self.addParameter(ParameterBoolean(LAStoolsAlgorithm.APPLY_FILE_SOURCE_ID, "apply file source ID", False))

def addParametersApplyFileSourceIdCommands(self, commands):
if self.getParameterValue(LAStoolsAlgorithm.APPLY_FILE_SOURCE_ID):
commands.append("-apply_file_source_ID")

def addParametersStepGUI(self):
self.addParameter(ParameterNumber(LAStoolsAlgorithm.STEP, "step size / pixel size", 0, None, 1.0))

Expand Down Expand Up @@ -252,7 +286,7 @@ def addParametersOutputAppendixCommands(self, commands):
commands.append(odix)

def addParametersTemporaryDirectoryGUI(self):
self.addParameter(ParameterFile(LAStoolsAlgorithm.TEMPORARY_DIRECTORY, "empty temporary directory", True))
self.addParameter(ParameterFile(LAStoolsAlgorithm.TEMPORARY_DIRECTORY, "empty temporary directory", True, False))

def addParametersTemporaryDirectoryAsOutputDirectoryCommands(self, commands):
odir = self.getParameterValue(LAStoolsAlgorithm.TEMPORARY_DIRECTORY)
Expand Down
26 changes: 20 additions & 6 deletions python/plugins/processing/algs/lidar/lastools/LAStoolsUtils.py
Expand Up @@ -7,6 +7,10 @@
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
---------------------
Date : October 2014
Copyright : (C) 2014 by Martin Isenburg
Email : martin near rapidlasso point com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
Expand All @@ -33,19 +37,29 @@ class LAStoolsUtils:
WINE_FOLDER = "WINE_FOLDER"

@staticmethod
def LAStoolsPath():
folder = ProcessingConfig.getSetting(LAStoolsUtils.LASTOOLS_FOLDER)
if folder == None:
folder =""
def hasWine():
wine_folder = ProcessingConfig.getSetting(LAStoolsUtils.WINE_FOLDER)
return ((wine_folder != None) and (wine_folder != ""))

@staticmethod
def LAStoolsPath():
lastools_folder = ProcessingConfig.getSetting(LAStoolsUtils.LASTOOLS_FOLDER)
if lastools_folder == None:
lastools_folder = ""
wine_folder = ProcessingConfig.getSetting(LAStoolsUtils.WINE_FOLDER)
if (wine_folder == None) or (wine_folder == ""):
folder = lastools_folder
else:
folder = wine_folder + "/wine " + lastools_folder
return folder


@staticmethod
def runLAStools(commands, progress):
loglines = []
loglines.append("LAStools console output")
commandline = " ".join(commands)
loglines.append("LAStools command line")
loglines.append(commandline)
loglines.append("LAStools console output")
proc = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stdin=open(os.devnull),
stderr=subprocess.STDOUT, universal_newlines=False).stdout
for line in iter(proc.readline, ""):
Expand Down
10 changes: 8 additions & 2 deletions python/plugins/processing/algs/lidar/lastools/blast2dem.py
Expand Up @@ -28,14 +28,15 @@
from LAStoolsAlgorithm import LAStoolsAlgorithm

from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterBoolean

class blast2dem(LAStoolsAlgorithm):

ATTRIBUTE = "ATTRIBUTE"
PRODUCT = "PRODUCT"
ATTRIBUTES = ["elevation", "slope", "intensity", "rgb"]
PRODUCTS = ["actual values", "hillshade", "gray", "false"]

USE_TILE_BB = "USE_TILE_BB"

def defineCharacteristics(self):
self.name = "blast2dem"
Expand All @@ -46,10 +47,12 @@ def defineCharacteristics(self):
self.addParametersStepGUI()
self.addParameter(ParameterSelection(blast2dem.ATTRIBUTE, "Attribute", blast2dem.ATTRIBUTES, 0))
self.addParameter(ParameterSelection(blast2dem.PRODUCT, "Product", blast2dem.PRODUCTS, 0))
self.addParameter(ParameterBoolean(blast2dem.USE_TILE_BB, "use tile bounding box (after tiling with buffer)", False))
self.addParametersRasterOutputGUI()
self.addParametersAdditionalGUI()

def processAlgorithm(self, progress):
commands = [os.path.join(LAStoolsUtils.LAStoolsPath(), "bin", "blast2dem.exe")]
commands = [os.path.join(LAStoolsUtils.LAStoolsPath(), "bin", "blast2dem")]
self.addParametersVerboseCommands(commands)
self.addParametersPointInputCommands(commands)
self.addParametersFilter1ReturnClassFlagsCommands(commands)
Expand All @@ -60,6 +63,9 @@ def processAlgorithm(self, progress):
product = self.getParameterValue(blast2dem.PRODUCT)
if product != 0:
commands.append("-" + blast2dem.PRODUCTS[product])
if (self.getParameterValue(blast2dem.USE_TILE_BB)):
commands.append("-use_tile_bb")
self.addParametersRasterOutputCommands(commands)
self.addParametersAdditionalCommands(commands)

LAStoolsUtils.runLAStools(commands, progress)
81 changes: 81 additions & 0 deletions python/plugins/processing/algs/lidar/lastools/blast2demPro.py
@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
blast2demPro.py
---------------------
Date : October 2014
Copyright : (C) 2014 by Martin Isenburg
Email : martin near rapidlasso point com
***************************************************************************
* *
* 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__ = 'Martin Isenburg'
__date__ = 'October 2014'
__copyright__ = '(C) 2014, Martin Isenburg'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
from LAStoolsUtils import LAStoolsUtils
from LAStoolsAlgorithm import LAStoolsAlgorithm

from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterBoolean

class blast2demPro(LAStoolsAlgorithm):

ATTRIBUTE = "ATTRIBUTE"
PRODUCT = "PRODUCT"
ATTRIBUTES = ["elevation", "slope", "intensity", "rgb"]
PRODUCTS = ["actual values", "hillshade", "gray", "false"]
USE_TILE_BB = "USE_TILE_BB"

def defineCharacteristics(self):
self.name = "blast2demPro"
self.group = "LAStools Production"
self.addParametersPointInputFolderGUI()
self.addParametersPointInputMergedGUI()
self.addParametersFilter1ReturnClassFlagsGUI()
self.addParametersStepGUI()
self.addParameter(ParameterSelection(blast2demPro.ATTRIBUTE, "Attribute", blast2demPro.ATTRIBUTES, 0))
self.addParameter(ParameterSelection(blast2demPro.PRODUCT, "Product", blast2demPro.PRODUCTS, 0))
self.addParameter(ParameterBoolean(blast2demPro.USE_TILE_BB, "use tile bounding box (after tiling with buffer)", False))
self.addParametersOutputDirectoryGUI()
self.addParametersOutputAppendixGUI()
self.addParametersRasterOutputFormatGUI()
self.addParametersRasterOutputGUI()
self.addParametersAdditionalGUI()
self.addParametersCoresGUI()
self.addParametersVerboseGUI()

def processAlgorithm(self, progress):
commands = [os.path.join(LAStoolsUtils.LAStoolsPath(), "bin", "blast2dem")]
self.addParametersVerboseCommands(commands)
self.addParametersPointInputFolderCommands(commands)
self.addParametersPointInputMergedCommands(commands)
self.addParametersFilter1ReturnClassFlagsCommands(commands)
self.addParametersStepCommands(commands)
attribute = self.getParameterValue(blast2demPro.ATTRIBUTE)
if attribute != 0:
commands.append("-" + blast2demPro.ATTRIBUTES[attribute])
product = self.getParameterValue(blast2demPro.PRODUCT)
if product != 0:
commands.append("-" + blast2demPro.PRODUCTS[product])
if (self.getParameterValue(blast2demPro.USE_TILE_BB)):
commands.append("-use_tile_bb")
self.addParametersOutputDirectoryCommands(commands)
self.addParametersOutputAppendixCommands(commands)
self.addParametersRasterOutputFormatCommands(commands)
self.addParametersRasterOutputCommands(commands)
self.addParametersAdditionalCommands(commands)
self.addParametersCoresCommands(commands)

LAStoolsUtils.runLAStools(commands, progress)

0 comments on commit 6c7d61f

Please sign in to comment.