Skip to content

Commit

Permalink
[processing] drop GdalScriptAlgorithm as it is not used
Browse files Browse the repository at this point in the history
Also remove OgrAlgorithm base class at it almost completely duplicates
GdalAlgorithm class. All affected algorithms updated accordingly.
  • Loading branch information
alexbruy committed Jan 22, 2016
1 parent ac22e9b commit 9193d8f
Show file tree
Hide file tree
Showing 19 changed files with 218 additions and 259 deletions.
7 changes: 4 additions & 3 deletions python/plugins/processing/algs/gdal/ClipByMask.py
Expand Up @@ -36,13 +36,14 @@

from processing.core.outputs import OutputRaster

from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils

from processing.tools import dataobjects
from processing.tools.vector import ogrConnectionString


class ClipByMask(OgrAlgorithm):
class ClipByMask(GdalAlgorithm):

INPUT = 'INPUT'
OUTPUT = 'OUTPUT'
Expand Down Expand Up @@ -114,7 +115,7 @@ def getConsoleCommands(self):
mask = self.getParameterValue(self.MASK)
maskLayer = dataobjects.getObjectFromUri(
self.getParameterValue(self.MASK))
ogrMask = self.ogrConnectionString(mask)[1:-1]
ogrMask = ogrConnectionString(mask)[1:-1]
noData = unicode(self.getParameterValue(self.NO_DATA))
addAlphaBand = self.getParameterValue(self.ALPHA_BAND)
cropToCutline = self.getParameterValue(self.CROP_TO_CUTLINE)
Expand Down
12 changes: 2 additions & 10 deletions python/plugins/processing/algs/gdal/GdalAlgorithm.py
Expand Up @@ -27,8 +27,9 @@
__revision__ = '$Format:%H$'

import os

from PyQt4.QtGui import QIcon
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
Expand Down Expand Up @@ -64,12 +65,3 @@ def commandName(self):
if name.endswith(".py"):
name = name[:-3]
return name


class GdalScriptAlgorithm(ScriptAlgorithm):

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdal.png'))

def getCustomParametersDialog(self):
return GdalAlgorithmDialog(self)
32 changes: 2 additions & 30 deletions python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py
Expand Up @@ -30,8 +30,6 @@

from processing.core.AlgorithmProvider import AlgorithmProvider
from processing.core.ProcessingLog import ProcessingLog
from processing.script.WrongScriptException import WrongScriptException
from processing.algs.gdal.GdalAlgorithm import GdalScriptAlgorithm
from GdalUtils import GdalUtils

from nearblack import nearblack
Expand Down Expand Up @@ -95,27 +93,14 @@ class GdalOgrAlgorithmProvider(AlgorithmProvider):
"""This provider incorporates GDAL-based algorithms into the
Processing framework.
Algorithms have been implemented using two different mechanisms,
which should serve as an example of different ways of extending
the processing capabilities of QGIS:
1. when a python script exist for a given process, it has been
adapted as a Processing python script and loaded using the
ScriptAlgorithm class. This algorithms call GDAL using its
Python bindings.
2. Other algorithms are called directly using the command line
interface. These have been implemented individually extending
the GeoAlgorithm class.
Algorithms are called directly using the command line interface.
They implemented individually extending GeoAlgorithm class.
"""

def __init__(self):
AlgorithmProvider.__init__(self)
self.createAlgsList()

def scriptsFolder(self):
"""The folder where script algorithms are stored.
"""
return os.path.dirname(__file__) + '/scripts'

def getDescription(self):
return self.tr('GDAL/OGR')

Expand Down Expand Up @@ -147,18 +132,5 @@ def createAlgsList(self):
Ogr2OgrTableToPostGisList(), OgrSql(),
]

# And then we add those that are created as python scripts
folder = self.scriptsFolder()
if os.path.exists(folder):
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('py'):
try:
fullpath = os.path.join(self.scriptsFolder(),
descriptionFile)
alg = GdalScriptAlgorithm(fullpath)
self.preloadedAlgs.append(alg)
except WrongScriptException as e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, e.msg)

def getSupportedOutputRasterLayerExtensions(self):
return GdalUtils.getSupportedRasterExtensions()
127 changes: 0 additions & 127 deletions python/plugins/processing/algs/gdal/OgrAlgorithm.py

This file was deleted.

12 changes: 7 additions & 5 deletions python/plugins/processing/algs/gdal/ogr2ogr.py
Expand Up @@ -32,10 +32,12 @@
from processing.core.parameters import ParameterSelection
from processing.core.outputs import OutputVector

from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils

from processing.tools.system import isWindows
from processing.tools.vector import ogrConnectionString, ogrLayerName

from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils

FORMATS = [
'ESRI Shapefile',
Expand Down Expand Up @@ -88,7 +90,7 @@
]


class Ogr2Ogr(OgrAlgorithm):
class Ogr2Ogr(GdalAlgorithm):

OUTPUT_LAYER = 'OUTPUT_LAYER'
INPUT_LAYER = 'INPUT_LAYER'
Expand All @@ -110,7 +112,7 @@ def defineCharacteristics(self):

def getConsoleCommands(self):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = self.ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer)[1:-1]

output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value
Expand All @@ -136,7 +138,7 @@ def getConsoleCommands(self):

arguments.append(output)
arguments.append(ogrLayer)
arguments.append(self.ogrLayerName(inLayer))
arguments.append(ogrLayerName(inLayer))

commands = []
if isWindows():
Expand Down
17 changes: 9 additions & 8 deletions python/plugins/processing/algs/gdal/ogr2ogrbuffer.py
Expand Up @@ -32,13 +32,14 @@
from processing.core.parameters import ParameterTableField
from processing.core.outputs import OutputVector

from processing.tools.system import isWindows

from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils

from processing.tools.system import isWindows
from processing.tools.vector import ogrConnectionString, ogrLayerName


class Ogr2OgrBuffer(OgrAlgorithm):
class Ogr2OgrBuffer(GdalAlgorithm):

OUTPUT_LAYER = 'OUTPUT_LAYER'
INPUT_LAYER = 'INPUT_LAYER'
Expand Down Expand Up @@ -74,8 +75,8 @@ def defineCharacteristics(self):

def getConsoleCommands(self):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = self.ogrConnectionString(inLayer)[1:-1]
layername = "'" + self.ogrLayerName(inLayer) + "'"
ogrLayer = ogrConnectionString(inLayer)[1:-1]
layername = "'" + ogrLayerName(inLayer) + "'"
geometry = unicode(self.getParameterValue(self.GEOMETRY))
distance = unicode(self.getParameterValue(self.DISTANCE))
dissolveall = self.getParameterValue(self.DISSOLVEALL)
Expand All @@ -85,13 +86,13 @@ def getConsoleCommands(self):
output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value

output = self.ogrConnectionString(outFile)
output = ogrConnectionString(outFile)
options = unicode(self.getParameterValue(self.OPTIONS))

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append(self.ogrLayerName(inLayer))
arguments.append(ogrLayerName(inLayer))
if dissolveall or field != 'None':
arguments.append('-dialect sqlite -sql "SELECT ST_Union(ST_Buffer(')
else:
Expand Down
19 changes: 10 additions & 9 deletions python/plugins/processing/algs/gdal/ogr2ogrclip.py
Expand Up @@ -29,13 +29,14 @@
from processing.core.parameters import ParameterString
from processing.core.outputs import OutputVector

from processing.tools.system import isWindows

from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils

from processing.tools.system import isWindows
from processing.tools.vector import ogrConnectionString, ogrLayerName


class Ogr2OgrClip(OgrAlgorithm):
class Ogr2OgrClip(GdalAlgorithm):

OUTPUT_LAYER = 'OUTPUT_LAYER'
INPUT_LAYER = 'INPUT_LAYER'
Expand All @@ -57,27 +58,27 @@ def defineCharacteristics(self):

def getConsoleCommands(self):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = self.ogrConnectionString(inLayer)[1:-1]
ogrLayer = ogrConnectionString(inLayer)[1:-1]
clipLayer = self.getParameterValue(self.CLIP_LAYER)
ogrClipLayer = self.ogrConnectionString(clipLayer)[1:-1]
ogrClipLayer = ogrConnectionString(clipLayer)[1:-1]

output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value

output = self.ogrConnectionString(outFile)
output = ogrConnectionString(outFile)
options = unicode(self.getParameterValue(self.OPTIONS))

arguments = []
arguments.append('-clipsrc')
arguments.append(ogrClipLayer)
arguments.append("-clipsrclayer")
arguments.append(self.ogrLayerName(clipLayer))
arguments.append(ogrLayerName(clipLayer))
if len(options) > 0:
arguments.append(options)

arguments.append(output)
arguments.append(ogrLayer)
arguments.append(self.ogrLayerName(inLayer))
arguments.append(ogrLayerName(inLayer))

commands = []
if isWindows():
Expand Down

0 comments on commit 9193d8f

Please sign in to comment.