| pktools 2.6.7 Processing Kernel for geospatial data

pklas2img.py
1# -*- coding: utf-8 -*-
2
3"""
4***************************************************************************
5 pklas2img.py
6 ---------------------
7 Date : April 2015
8 Copyright : (C) 2015 by Pieter Kempeneers
9 Email : kempenep at gmail dot com
10***************************************************************************
11* *
12* This program is free software; you can redistribute it and/or modify *
13* it under the terms of the GNU General Public License as published by *
14* the Free Software Foundation; either version 2 of the License, or *
15* (at your option) any later version. *
16* *
17***************************************************************************
18"""
19
20__author__ = 'Pieter Kempeneers'
21__date__ = 'April 2015'
22__copyright__ = '(C) 2015, Pieter Kempeneers'
23# This will get replaced with a git SHA1 when you do a git archive
24__revision__ = '$Format:%H$'
25
26 import os
27 from pktoolsUtils import pktoolsUtils
28 from pktoolsAlgorithm import pktoolsAlgorithm
29 from processing.core.parameters import ParameterMultipleInput
30 from processing.core.parameters import ParameterRaster
31 from processing.core.parameters import ParameterFile
32 from processing.core.outputs import OutputRaster
33 from processing.core.parameters import ParameterSelection
34 from processing.core.parameters import ParameterNumber
35 from processing.core.parameters import ParameterString
36 from processing.core.parameters import ParameterBoolean
37 from processing.core.parameters import ParameterExtent
38
39 class pklas2img(pktoolsAlgorithm):
40
41 INPUT = "INPUT"
42 OUTPUT = "OUTPUT"
43 ATTRIBUTE_OPTIONS = ["z","intensity", "return", "nreturn"]
44 COMPOSITE_OPTIONS = ["last", "min", "max", "absmin", "absmax", "median", "mean", "sum", "first", "profile", "percentile", "height", "values", "percentile", "number"]
45 FILTER_OPTIONS = ["all","first","last","single","multiple"]
46
47 ATTRIBUTE = "ATTRIBUTE"
48 COMPOSITE = "COMPOSITE"
49 FILTER = "FILTER"
50
51 PERCENTILE = "PERCENTILE"
52 DX = "DX"
53 DY = "DY"
54# PROJWIN = 'PROJWIN'
55 NODATA = "NODATA"
56 RTYPE = 'RTYPE'
57 TYPE = ['Float32','Byte','Int16','UInt16','UInt32','Int32','Float64','CInt16','CInt32','CFloat32','CFloat64']
58 EXTRA = 'EXTRA'
59
60 def cliName(self):
61 return "pklas2img"
62
63 def defineCharacteristics(self):
64 self.name = "Create raster dataset from LAS(Z) data point cloud(s)"
65 self.group = "[pktools] LiDAR"
66
67 self.addParameter(ParameterFile(self.INPUT, "Input LAS(Z) data set(s)", False, False))
68
69 self.addParameter(ParameterSelection(self.ATTRIBUTE,"name of the point attribute to select",self.ATTRIBUTE_OPTIONS, 0))
70 self.addParameter(ParameterSelection(self.COMPOSITE,"composite for multiple points in cell",self.COMPOSITE_OPTIONS, 0))
71 self.addParameter(ParameterSelection(self.FILTER,"filter las points",self.FILTER_OPTIONS, 0))
72 self.addOutput(OutputRaster(self.OUTPUT, "Output raster data set"))
73 self.addParameter(ParameterSelection(self.RTYPE, 'Output raster type', self.TYPE, 0))
74 self.addParameter(ParameterNumber(self.PERCENTILE, "Percentile value used for rule percentile",0.0,100.0,95))
75 self.addParameter(ParameterNumber(self.DX, "Output resolution in x",0.0,None,1.0))
76 self.addParameter(ParameterNumber(self.DY, "Output resolution in y",0.0,None,1.0))
77 # self.addParameter(ParameterExtent(self.PROJWIN,
78 # 'Georeferenced boundingbox'))
79 self.addParameter(ParameterNumber(self.NODATA, "nodata value to put in image",0,None,0))
80 self.addParameter(ParameterString(self.EXTRA,
81 'Additional parameters', '-of GTiff', optional=True))
82
83 def processAlgorithm(self, progress):
84 cliPath = '"' + os.path.join(pktoolsUtils.pktoolsPath(), self.cliName()) + '"'
85 commands = [cliPath]
86
87 input=self.getParameterValue(self.INPUT)
88 inputFiles = input.split(';')
89 for inputFile in inputFiles:
90 commands.append('-i')
91 commands.append('"' + inputFile + '"')
92
93 if self.TYPE[self.getParameterValue(self.RTYPE)] != "none":
94 commands.append('-ot')
95 commands.append(self.TYPE[self.getParameterValue(self.RTYPE)])
96
97 output=self.getOutputValue(self.OUTPUT)
98 if output != "":
99 commands.append("-o")
100 commands.append('"' + output + '"')
101
102 commands.append("-n")
103 commands.append(self.ATTRIBUTE_OPTIONS[self.getParameterValue(self.ATTRIBUTE)])
104 commands.append("-comp")
105 commands.append(self.COMPOSITE_OPTIONS[self.getParameterValue(self.COMPOSITE)])
106 commands.append("-fir")
107 commands.append(self.FILTER_OPTIONS[self.getParameterValue(self.FILTER)])
108 if self.getParameterValue(self.DX) != 0:
109 commands.append("-dx")
110 commands.append(str(self.getParameterValue(self.DX)))
111 if self.getParameterValue(self.DY) != 0:
112 commands.append("-dy")
113 commands.append(str(self.getParameterValue(self.DY)))
114 #projwin = str(self.getParameterValue(self.PROJWIN))
115 # regionCoords = projwin.split(',')
116 # commands.append('-ulx')
117 # commands.append(regionCoords[0])
118 # commands.append('-uly')
119 # commands.append(regionCoords[3])
120 # commands.append('-lrx')
121 # commands.append(regionCoords[1])
122 # commands.append('-lry')
123 # commands.append(regionCoords[2])
124 commands.append('-nodata')
125 commands.append(str(self.getParameterValue(self.NODATA)))
126
127 extra = str(self.getParameterValue(self.EXTRA))
128 if len(extra) > 0:
129 commands.append(extra)
130
131 pktoolsUtils.runpktools(commands, progress)
qgis.pklas2img.pklas2img.ATTRIBUTE_OPTIONS
list ATTRIBUTE_OPTIONS
Definition: pklas2img.py:43
qgis.pklas2img.pklas2img.ATTRIBUTE
string ATTRIBUTE
Definition: pklas2img.py:47
qgis.pklas2img.pklas2img.DY
string DY
Definition: pklas2img.py:53
qgis.pklas2img.pklas2img.PERCENTILE
string PERCENTILE
Definition: pklas2img.py:51
qgis.pklas2img.pklas2img.group
group
Definition: pklas2img.py:65
qgis.pklas2img.pklas2img.RTYPE
string RTYPE
Definition: pklas2img.py:56
qgis.pklas2img.pklas2img.FILTER
string FILTER
Definition: pklas2img.py:49
qgis.pklas2img.pklas2img.DX
string DX
Definition: pklas2img.py:52
qgis.pklas2img.pklas2img.OUTPUT
string OUTPUT
Definition: pklas2img.py:42
qgis.pklas2img.pklas2img.INPUT
string INPUT
Definition: pklas2img.py:41
qgis.pklas2img.pklas2img.EXTRA
string EXTRA
Definition: pklas2img.py:58
qgis.pklas2img.pklas2img.NODATA
string NODATA
Definition: pklas2img.py:55
qgis.pklas2img.pklas2img.name
name
Definition: pklas2img.py:64
qgis.pklas2img.pklas2img.TYPE
list TYPE
Definition: pklas2img.py:57
qgis.pklas2img.pklas2img.cliName
def cliName(self)
Definition: pklas2img.py:60
qgis.pklas2img.pklas2img.FILTER_OPTIONS
list FILTER_OPTIONS
Definition: pklas2img.py:45
qgis.pklas2img.pklas2img.COMPOSITE_OPTIONS
list COMPOSITE_OPTIONS
Definition: pklas2img.py:44
qgis.pklas2img.pklas2img.COMPOSITE
string COMPOSITE
Definition: pklas2img.py:48