Skip to content
Permalink
Browse files

[processing] added box with console commands for gdal/ogr algs

  • Loading branch information
volaya committed May 7, 2015
1 parent 90ce59c commit 1964a7c7443d643510764c23d39e7dd6c064df54
Showing with 172 additions and 117 deletions.
  1. +2 −3 python/plugins/processing/algs/gdal/ClipByExtent.py
  2. +2 −3 python/plugins/processing/algs/gdal/ClipByMask.py
  3. +2 −3 python/plugins/processing/algs/gdal/ColorRelief.py
  4. +12 −0 python/plugins/processing/algs/gdal/GdalAlgorithm.py
  5. +58 −0 python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py
  6. +2 −3 python/plugins/processing/algs/gdal/GridAverage.py
  7. +2 −3 python/plugins/processing/algs/gdal/GridDataMetrics.py
  8. +2 −3 python/plugins/processing/algs/gdal/GridInvDist.py
  9. +2 −3 python/plugins/processing/algs/gdal/GridNearest.py
  10. +2 −3 python/plugins/processing/algs/gdal/aspect.py
  11. +2 −2 python/plugins/processing/algs/gdal/buildvrt.py
  12. +2 −3 python/plugins/processing/algs/gdal/contour.py
  13. +3 −0 python/plugins/processing/algs/gdal/extractprojection.py
  14. +2 −2 python/plugins/processing/algs/gdal/fillnodata.py
  15. +2 −2 python/plugins/processing/algs/gdal/gdal2xyz.py
  16. +2 −3 python/plugins/processing/algs/gdal/gdaladdo.py
  17. +3 −3 python/plugins/processing/algs/gdal/gdalcalc.py
  18. +2 −2 python/plugins/processing/algs/gdal/gdaltindex.py
  19. +2 −3 python/plugins/processing/algs/gdal/hillshade.py
  20. +5 −3 python/plugins/processing/algs/gdal/information.py
  21. +2 −2 python/plugins/processing/algs/gdal/merge.py
  22. +2 −3 python/plugins/processing/algs/gdal/nearblack.py
  23. +3 −2 python/plugins/processing/algs/gdal/ogr2ogr.py
  24. +2 −2 python/plugins/processing/algs/gdal/ogr2ogrbuffer.py
  25. +2 −2 python/plugins/processing/algs/gdal/ogr2ogrclip.py
  26. +2 −2 python/plugins/processing/algs/gdal/ogr2ogrclipextent.py
  27. +2 −2 python/plugins/processing/algs/gdal/ogr2ogrdissolve.py
  28. +2 −2 python/plugins/processing/algs/gdal/ogr2ogronesidebuffer.py
  29. +2 −2 python/plugins/processing/algs/gdal/ogr2ogrpointsonlines.py
  30. +2 −2 python/plugins/processing/algs/gdal/ogr2ogrtabletopostgislist.py
  31. +2 −2 python/plugins/processing/algs/gdal/ogr2ogrtopostgis.py
  32. +2 −2 python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py
  33. +5 −3 python/plugins/processing/algs/gdal/ogrinfo.py
  34. +2 −3 python/plugins/processing/algs/gdal/ogrsql.py
  35. +2 −2 python/plugins/processing/algs/gdal/pct2rgb.py
  36. +2 −2 python/plugins/processing/algs/gdal/polygonize.py
  37. +2 −2 python/plugins/processing/algs/gdal/proximity.py
  38. +2 −4 python/plugins/processing/algs/gdal/rasterize.py
  39. +1 −4 python/plugins/processing/algs/gdal/rasterize_over.py
  40. +2 −2 python/plugins/processing/algs/gdal/rgb2pct.py
  41. +2 −3 python/plugins/processing/algs/gdal/roughness.py
  42. +2 −2 python/plugins/processing/algs/gdal/sieve.py
  43. +2 −3 python/plugins/processing/algs/gdal/slope.py
  44. +2 −3 python/plugins/processing/algs/gdal/tpi.py
  45. +2 −3 python/plugins/processing/algs/gdal/translate.py
  46. +2 −3 python/plugins/processing/algs/gdal/tri.py
  47. +2 −3 python/plugins/processing/algs/gdal/warp.py
  48. +1 −0 python/plugins/processing/algs/lidar/lastools/LAStoolsUtils.py
  49. +3 −3 python/plugins/processing/algs/lidar/lastools/las2shp.py
@@ -56,7 +56,7 @@ def defineCharacteristics(self):
self.tr('Additional creation parameters'), '', optional=True))
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Clipped')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
out = self.getOutputValue(self.OUTPUT)
noData = str(self.getParameterValue(self.NO_DATA))
projwin = str(self.getParameterValue(self.PROJWIN))
@@ -82,5 +82,4 @@ def processAlgorithm(self, progress):
arguments.append(self.getParameterValue(self.INPUT))
arguments.append(out)

GdalUtils.runGdal(['gdal_translate',
GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdal_translate', GdalUtils.escapeAndJoin(arguments)]
@@ -66,7 +66,7 @@ def defineCharacteristics(self):
self.tr('Additional creation parameters'), '', optional=True))
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Output layer')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
out = self.getOutputValue(self.OUTPUT)
mask = self.getParameterValue(self.MASK)
noData = str(self.getParameterValue(self.NO_DATA))
@@ -104,5 +104,4 @@ def processAlgorithm(self, progress):
arguments.append(self.getParameterValue(self.INPUT))
arguments.append(out)

GdalUtils.runGdal(['gdalwarp', GdalUtils.escapeAndJoin(arguments)],
progress)
return ['gdalwarp', GdalUtils.escapeAndJoin(arguments)]
@@ -65,7 +65,7 @@ def defineCharacteristics(self):

self.addOutput(OutputRaster(self.OUTPUT, self.tr('Color relief')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
arguments = ['color-relief']
arguments.append(unicode(self.getParameterValue(self.INPUT)))
arguments.append(unicode(self.getParameterValue(self.COLOR_TABLE)))
@@ -87,5 +87,4 @@ def processAlgorithm(self, progress):
elif mode == 2:
arguments.append('-nearest_color_entry')

GdalUtils.runGdal(['gdaldem',
GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
@@ -17,6 +17,7 @@
***************************************************************************
"""


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
@@ -29,14 +30,25 @@
from PyQt4 import QtGui
from processing.script.ScriptAlgorithm import ScriptAlgorithm
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog
from processing.algs.gdal.GdalUtils import GdalUtils


class GdalAlgorithm(GeoAlgorithm):

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

def getCustomParametersDialog(self):
return GdalAlgorithmDialog(self)

def processAlgorithm(self, progress):
GdalUtils.runGdal(self.getConsoleCommands(), progress)

class GdalScriptAlgorithm(ScriptAlgorithm):

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

def getCustomParametersDialog(self):
return GdalAlgorithmDialog(self)
@@ -0,0 +1,58 @@

from PyQt4.QtGui import *
from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.gui.AlgorithmDialogBase import AlgorithmDialogBase
from processing.gui.ParametersPanel import ParametersPanel

class GdalAlgorithmDialog(AlgorithmDialog):

def __init__(self, alg):
AlgorithmDialogBase.__init__(self, alg)

self.alg = alg

self.mainWidget = GdalParametersPanel(self, alg)
self.setMainWidget()
self.mainWidget.parametersHaveChanged()

class GdalParametersPanel(ParametersPanel):

def __init__(self, parent, alg):
ParametersPanel.__init__(self, parent, alg)

w = QWidget()
layout = QVBoxLayout()
layout.setMargin(9)
layout.setSpacing(6)
label = QLabel()
label.setText("GDAL/OGR console call")
layout.addWidget(label)
self.text = QPlainTextEdit()
self.text.setEnabled(False)
layout.addWidget(self.text)
w.setLayout(layout)
self.layout().addWidget(w)

self.connectParameterSignals()
self.parametersHaveChanged()

def connectParameterSignals(self):
for w in self.widgets.values():
if isinstance(w, QLineEdit):
w.textChanged.connect(self.parametersHaveChanged)
elif isinstance(w, QComboBox):
w.currentIndexChanged.connect(self.parametersHaveChanged)
elif isinstance(w, QCheckBox):
w.stateChanged.connect(self.parametersHaveChanged)

def parametersHaveChanged(self):
try:
self.parent.setParamValues()
for output in self.alg.outputs:
if output.value is None:
output.value = "[temporary file]"
commands = self.alg.getConsoleCommands()
commands = [c for c in commands if c not in ['cmd.exe', '/C ']]
self.text.setPlainText(" ".join(commands))
except:
self.text.setPlainText("")
@@ -76,7 +76,7 @@ def defineCharacteristics(self):

self.addOutput(OutputRaster(self.OUTPUT, self.tr('Average')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
arguments = ['-l']
arguments.append(
os.path.basename(os.path.splitext(
@@ -101,5 +101,4 @@ def processAlgorithm(self, progress):
arguments.append(unicode(self.getParameterValue(self.INPUT)))
arguments.append(unicode(self.getOutputValue(self.OUTPUT)))

GdalUtils.runGdal(['gdal_grid',
GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdal_grid',GdalUtils.escapeAndJoin(arguments)]
@@ -82,7 +82,7 @@ def defineCharacteristics(self):

self.addOutput(OutputRaster(self.OUTPUT, self.tr('Interpolated metrics')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
arguments = ['-l']
arguments.append(
os.path.basename(os.path.splitext(
@@ -120,5 +120,4 @@ def processAlgorithm(self, progress):
arguments.append(unicode(self.getParameterValue(self.INPUT)))
arguments.append(unicode(self.getOutputValue(self.OUTPUT)))

GdalUtils.runGdal(['gdal_grid',
GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdal_grid', GdalUtils.escapeAndJoin(arguments)]
@@ -86,7 +86,7 @@ def defineCharacteristics(self):

self.addOutput(OutputRaster(self.OUTPUT, self.tr('Interpolated IDW')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
arguments = ['-l']
arguments.append(
os.path.basename(os.path.splitext(
@@ -114,5 +114,4 @@ def processAlgorithm(self, progress):
arguments.append(unicode(self.getParameterValue(self.INPUT)))
arguments.append(unicode(self.getOutputValue(self.OUTPUT)))

GdalUtils.runGdal(['gdal_grid',
GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdal_grid', GdalUtils.escapeAndJoin(arguments)]
@@ -74,7 +74,7 @@ def defineCharacteristics(self):

self.addOutput(OutputRaster(self.OUTPUT, self.tr('Interpolated nearest neighbor')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
arguments = ['-l']
arguments.append(
os.path.basename(os.path.splitext(
@@ -98,5 +98,4 @@ def processAlgorithm(self, progress):
arguments.append(unicode(self.getParameterValue(self.INPUT)))
arguments.append(unicode(self.getOutputValue(self.OUTPUT)))

GdalUtils.runGdal(['gdal_grid',
GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdal_grid', GdalUtils.escapeAndJoin(arguments)]
@@ -66,7 +66,7 @@ def defineCharacteristics(self):

self.addOutput(OutputRaster(self.OUTPUT, 'Aspect'))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
arguments = ['aspect']
arguments.append(unicode(self.getParameterValue(self.INPUT)))
output = unicode(self.getOutputValue(self.OUTPUT))
@@ -91,5 +91,4 @@ def processAlgorithm(self, progress):
if self.getParameterValue(self.ZERO_FLAT):
arguments.append('-zero_for_flat')

GdalUtils.runGdal(['gdaldem',
GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
@@ -59,7 +59,7 @@ def defineCharacteristics(self):
self.tr('Allow projection difference'), False))
self.addOutput(OutputRaster(buildvrt.OUTPUT, self.tr('Virtual')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
arguments = []
arguments.append('-resolution')
arguments.append(self.RESOLUTION_OPTIONS[self.getParameterValue(self.RESOLUTION)])
@@ -84,4 +84,4 @@ def processAlgorithm(self, progress):
arguments.append(out)


GdalUtils.runGdal(['gdalbuildvrt', GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdalbuildvrt', GdalUtils.escapeAndJoin(arguments)]
@@ -61,7 +61,7 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(self.OUTPUT_VECTOR,
self.tr('Output file for contour lines (vector)')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
interval = str(self.getParameterValue(self.INTERVAL))
fieldName = str(self.getParameterValue(self.FIELD_NAME))
extra = str(self.getParameterValue(self.EXTRA))
@@ -79,5 +79,4 @@ def processAlgorithm(self, progress):
arguments.append(self.getParameterValue(self.INPUT_RASTER))
arguments.append(self.getOutputValue(self.OUTPUT_VECTOR))

GdalUtils.runGdal(['gdal_contour',
GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdal_contour', GdalUtils.escapeAndJoin(arguments)]
@@ -46,6 +46,9 @@ def defineCharacteristics(self):
self.addParameter(ParameterBoolean(self.PRJ_FILE,
self.tr('Create also .prj file'), False))

def getConsoleCommands(self):
return ""

def processAlgorithm(self, progress):
rasterPath = self.getParameterValue(self.INPUT)
createPrj = self.getParameterValue(self.PRJ_FILE)
@@ -66,7 +66,7 @@ def defineCharacteristics(self):

self.addOutput(OutputRaster(self.OUTPUT, self.tr('Filled')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
output = self.getOutputValue(self.OUTPUT)

arguments = []
@@ -102,4 +102,4 @@ def processAlgorithm(self, progress):
commands = ['gdal_fillnodata.py',
GdalUtils.escapeAndJoin(arguments)]

GdalUtils.runGdal(commands, progress)
return commands
@@ -52,7 +52,7 @@ def defineCharacteristics(self):

self.addOutput(OutputTable(self.OUTPUT, self.tr('xyz')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
arguments = []
arguments.append('-band')
arguments.append(str(self.getParameterValue(self.BAND)))
@@ -68,4 +68,4 @@ def processAlgorithm(self, progress):
else:
commands = ['gdal2xyz.py', GdalUtils.escapeAndJoin(arguments)]

GdalUtils.runGdal(commands, progress)
return commands, progress
@@ -75,7 +75,7 @@ def defineCharacteristics(self):
self.tr('Overview format'), self.FORMATS, 0))
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Pyramidized'), True))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
inFile = self.getParameterValue(self.INPUT)
clearOverviews = self.getParameterValue(self.CLEAN)
ovrFormat = self.getParameterValue(self.FORMAT)
@@ -97,5 +97,4 @@ def processAlgorithm(self, progress):
arguments.extend(self.getParameterValue(self.LEVELS).split(' '))
self.setOutputValue(self.OUTPUT, inFile)

GdalUtils.runGdal(['gdaladdo', GdalUtils.escapeAndJoin(arguments)],
progress)
return ['gdaladdo', GdalUtils.escapeAndJoin(arguments)]
@@ -100,7 +100,7 @@ def defineCharacteristics(self):
self.tr('Additional creation parameters'), '', optional=True))
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Calculated')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
out = self.getOutputValue(self.OUTPUT)
extra = str(self.getParameterValue(self.EXTRA))
#debug = self.getParameterValue(self.DEBUG)
@@ -154,6 +154,6 @@ def processAlgorithm(self, progress):
arguments.append(out)

if isWindows():
GdalUtils.runGdal(['gdal_calc', GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdal_calc', GdalUtils.escapeAndJoin(arguments)]
else:
GdalUtils.runGdal(['gdal_calc.py', GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdal_calc.py', GdalUtils.escapeAndJoin(arguments)]
@@ -54,7 +54,7 @@ def defineCharacteristics(self):
self.tr('Skip files with different projection reference'), False))
self.addOutput(OutputVector(gdaltindex.OUTPUT, self.tr('Tiled')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
fieldName = str(self.getParameterValue(self.FIELD_NAME))

arguments = []
@@ -67,4 +67,4 @@ def processAlgorithm(self, progress):
arguments.extend(unicode(self.getParameterValue(gdaltindex.INPUT)).split(';'))


GdalUtils.runGdal(['gdaltindex', GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdaltindex', GdalUtils.escapeAndJoin(arguments)]
@@ -70,7 +70,7 @@ def defineCharacteristics(self):

self.addOutput(OutputRaster(self.OUTPUT, self.tr('Hillshade')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
arguments = ['hillshade']
arguments.append(unicode(self.getParameterValue(self.INPUT)))
arguments.append(unicode(self.getOutputValue(self.OUTPUT)))
@@ -93,5 +93,4 @@ def processAlgorithm(self, progress):
arguments.append('-alg')
arguments.append('ZevenbergenThorne')

GdalUtils.runGdal(['gdaldem',
GdalUtils.escapeAndJoin(arguments)], progress)
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
@@ -54,15 +54,17 @@ def defineCharacteristics(self):
self.addOutput(OutputHTML(information.OUTPUT,
self.tr('Layer information')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
arguments = []
if self.getParameterValue(information.NOGCP):
arguments.append('-nogcp')
if self.getParameterValue(information.NOMETADATA):
arguments.append('-nomd')
arguments.append(self.getParameterValue(information.INPUT))
GdalUtils.runGdal(['gdalinfo', GdalUtils.escapeAndJoin(arguments)],
progress)
return ['gdalinfo', GdalUtils.escapeAndJoin(arguments)]

def processAlgorithm(self, progress):
GdalUtils.runGdal(self.getConsoleCommands(), progress)
output = self.getOutputValue(information.OUTPUT)
f = open(output, 'w')
f.write('<pre>')
@@ -59,7 +59,7 @@ def defineCharacteristics(self):

self.addOutput(OutputRaster(merge.OUTPUT, self.tr('Merged')))

def processAlgorithm(self, progress):
def getConsoleCommands(self):
arguments = []
arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
@@ -81,4 +81,4 @@ def processAlgorithm(self, progress):
else:
commands = ['gdal_merge.py', GdalUtils.escapeAndJoin(arguments)]

GdalUtils.runGdal(commands, progress)
return commands

0 comments on commit 1964a7c

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