Skip to content

Commit 9193d8f

Browse files
committed
[processing] drop GdalScriptAlgorithm as it is not used
Also remove OgrAlgorithm base class at it almost completely duplicates GdalAlgorithm class. All affected algorithms updated accordingly.
1 parent ac22e9b commit 9193d8f

19 files changed

+218
-259
lines changed

python/plugins/processing/algs/gdal/ClipByMask.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@
3636

3737
from processing.core.outputs import OutputRaster
3838

39-
from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm
39+
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
4040
from processing.algs.gdal.GdalUtils import GdalUtils
4141

4242
from processing.tools import dataobjects
43+
from processing.tools.vector import ogrConnectionString
4344

4445

45-
class ClipByMask(OgrAlgorithm):
46+
class ClipByMask(GdalAlgorithm):
4647

4748
INPUT = 'INPUT'
4849
OUTPUT = 'OUTPUT'
@@ -114,7 +115,7 @@ def getConsoleCommands(self):
114115
mask = self.getParameterValue(self.MASK)
115116
maskLayer = dataobjects.getObjectFromUri(
116117
self.getParameterValue(self.MASK))
117-
ogrMask = self.ogrConnectionString(mask)[1:-1]
118+
ogrMask = ogrConnectionString(mask)[1:-1]
118119
noData = unicode(self.getParameterValue(self.NO_DATA))
119120
addAlphaBand = self.getParameterValue(self.ALPHA_BAND)
120121
cropToCutline = self.getParameterValue(self.CROP_TO_CUTLINE)

python/plugins/processing/algs/gdal/GdalAlgorithm.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
__revision__ = '$Format:%H$'
2828

2929
import os
30+
3031
from PyQt4.QtGui import QIcon
31-
from processing.script.ScriptAlgorithm import ScriptAlgorithm
32+
3233
from processing.core.GeoAlgorithm import GeoAlgorithm
3334
from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog
3435
from processing.algs.gdal.GdalUtils import GdalUtils
@@ -64,12 +65,3 @@ def commandName(self):
6465
if name.endswith(".py"):
6566
name = name[:-3]
6667
return name
67-
68-
69-
class GdalScriptAlgorithm(ScriptAlgorithm):
70-
71-
def getIcon(self):
72-
return QIcon(os.path.join(pluginPath, 'images', 'gdal.png'))
73-
74-
def getCustomParametersDialog(self):
75-
return GdalAlgorithmDialog(self)

python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py

+2-30
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030

3131
from processing.core.AlgorithmProvider import AlgorithmProvider
3232
from processing.core.ProcessingLog import ProcessingLog
33-
from processing.script.WrongScriptException import WrongScriptException
34-
from processing.algs.gdal.GdalAlgorithm import GdalScriptAlgorithm
3533
from GdalUtils import GdalUtils
3634

3735
from nearblack import nearblack
@@ -95,27 +93,14 @@ class GdalOgrAlgorithmProvider(AlgorithmProvider):
9593
"""This provider incorporates GDAL-based algorithms into the
9694
Processing framework.
9795
98-
Algorithms have been implemented using two different mechanisms,
99-
which should serve as an example of different ways of extending
100-
the processing capabilities of QGIS:
101-
1. when a python script exist for a given process, it has been
102-
adapted as a Processing python script and loaded using the
103-
ScriptAlgorithm class. This algorithms call GDAL using its
104-
Python bindings.
105-
2. Other algorithms are called directly using the command line
106-
interface. These have been implemented individually extending
107-
the GeoAlgorithm class.
96+
Algorithms are called directly using the command line interface.
97+
They implemented individually extending GeoAlgorithm class.
10898
"""
10999

110100
def __init__(self):
111101
AlgorithmProvider.__init__(self)
112102
self.createAlgsList()
113103

114-
def scriptsFolder(self):
115-
"""The folder where script algorithms are stored.
116-
"""
117-
return os.path.dirname(__file__) + '/scripts'
118-
119104
def getDescription(self):
120105
return self.tr('GDAL/OGR')
121106

@@ -147,18 +132,5 @@ def createAlgsList(self):
147132
Ogr2OgrTableToPostGisList(), OgrSql(),
148133
]
149134

150-
# And then we add those that are created as python scripts
151-
folder = self.scriptsFolder()
152-
if os.path.exists(folder):
153-
for descriptionFile in os.listdir(folder):
154-
if descriptionFile.endswith('py'):
155-
try:
156-
fullpath = os.path.join(self.scriptsFolder(),
157-
descriptionFile)
158-
alg = GdalScriptAlgorithm(fullpath)
159-
self.preloadedAlgs.append(alg)
160-
except WrongScriptException as e:
161-
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, e.msg)
162-
163135
def getSupportedOutputRasterLayerExtensions(self):
164136
return GdalUtils.getSupportedRasterExtensions()

python/plugins/processing/algs/gdal/OgrAlgorithm.py

-127
This file was deleted.

python/plugins/processing/algs/gdal/ogr2ogr.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
from processing.core.parameters import ParameterSelection
3333
from processing.core.outputs import OutputVector
3434

35+
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
36+
from processing.algs.gdal.GdalUtils import GdalUtils
37+
3538
from processing.tools.system import isWindows
39+
from processing.tools.vector import ogrConnectionString, ogrLayerName
3640

37-
from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm
38-
from processing.algs.gdal.GdalUtils import GdalUtils
3941

4042
FORMATS = [
4143
'ESRI Shapefile',
@@ -88,7 +90,7 @@
8890
]
8991

9092

91-
class Ogr2Ogr(OgrAlgorithm):
93+
class Ogr2Ogr(GdalAlgorithm):
9294

9395
OUTPUT_LAYER = 'OUTPUT_LAYER'
9496
INPUT_LAYER = 'INPUT_LAYER'
@@ -110,7 +112,7 @@ def defineCharacteristics(self):
110112

111113
def getConsoleCommands(self):
112114
inLayer = self.getParameterValue(self.INPUT_LAYER)
113-
ogrLayer = self.ogrConnectionString(inLayer)[1:-1]
115+
ogrLayer = ogrConnectionString(inLayer)[1:-1]
114116

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

137139
arguments.append(output)
138140
arguments.append(ogrLayer)
139-
arguments.append(self.ogrLayerName(inLayer))
141+
arguments.append(ogrLayerName(inLayer))
140142

141143
commands = []
142144
if isWindows():

python/plugins/processing/algs/gdal/ogr2ogrbuffer.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@
3232
from processing.core.parameters import ParameterTableField
3333
from processing.core.outputs import OutputVector
3434

35-
from processing.tools.system import isWindows
36-
37-
from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm
35+
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
3836
from processing.algs.gdal.GdalUtils import GdalUtils
3937

38+
from processing.tools.system import isWindows
39+
from processing.tools.vector import ogrConnectionString, ogrLayerName
40+
4041

41-
class Ogr2OgrBuffer(OgrAlgorithm):
42+
class Ogr2OgrBuffer(GdalAlgorithm):
4243

4344
OUTPUT_LAYER = 'OUTPUT_LAYER'
4445
INPUT_LAYER = 'INPUT_LAYER'
@@ -74,8 +75,8 @@ def defineCharacteristics(self):
7475

7576
def getConsoleCommands(self):
7677
inLayer = self.getParameterValue(self.INPUT_LAYER)
77-
ogrLayer = self.ogrConnectionString(inLayer)[1:-1]
78-
layername = "'" + self.ogrLayerName(inLayer) + "'"
78+
ogrLayer = ogrConnectionString(inLayer)[1:-1]
79+
layername = "'" + ogrLayerName(inLayer) + "'"
7980
geometry = unicode(self.getParameterValue(self.GEOMETRY))
8081
distance = unicode(self.getParameterValue(self.DISTANCE))
8182
dissolveall = self.getParameterValue(self.DISSOLVEALL)
@@ -85,13 +86,13 @@ def getConsoleCommands(self):
8586
output = self.getOutputFromName(self.OUTPUT_LAYER)
8687
outFile = output.value
8788

88-
output = self.ogrConnectionString(outFile)
89+
output = ogrConnectionString(outFile)
8990
options = unicode(self.getParameterValue(self.OPTIONS))
9091

9192
arguments = []
9293
arguments.append(output)
9394
arguments.append(ogrLayer)
94-
arguments.append(self.ogrLayerName(inLayer))
95+
arguments.append(ogrLayerName(inLayer))
9596
if dissolveall or field != 'None':
9697
arguments.append('-dialect sqlite -sql "SELECT ST_Union(ST_Buffer(')
9798
else:

python/plugins/processing/algs/gdal/ogr2ogrclip.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
from processing.core.parameters import ParameterString
3030
from processing.core.outputs import OutputVector
3131

32-
from processing.tools.system import isWindows
33-
34-
from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm
32+
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
3533
from processing.algs.gdal.GdalUtils import GdalUtils
3634

35+
from processing.tools.system import isWindows
36+
from processing.tools.vector import ogrConnectionString, ogrLayerName
37+
3738

38-
class Ogr2OgrClip(OgrAlgorithm):
39+
class Ogr2OgrClip(GdalAlgorithm):
3940

4041
OUTPUT_LAYER = 'OUTPUT_LAYER'
4142
INPUT_LAYER = 'INPUT_LAYER'
@@ -57,27 +58,27 @@ def defineCharacteristics(self):
5758

5859
def getConsoleCommands(self):
5960
inLayer = self.getParameterValue(self.INPUT_LAYER)
60-
ogrLayer = self.ogrConnectionString(inLayer)[1:-1]
61+
ogrLayer = ogrConnectionString(inLayer)[1:-1]
6162
clipLayer = self.getParameterValue(self.CLIP_LAYER)
62-
ogrClipLayer = self.ogrConnectionString(clipLayer)[1:-1]
63+
ogrClipLayer = ogrConnectionString(clipLayer)[1:-1]
6364

6465
output = self.getOutputFromName(self.OUTPUT_LAYER)
6566
outFile = output.value
6667

67-
output = self.ogrConnectionString(outFile)
68+
output = ogrConnectionString(outFile)
6869
options = unicode(self.getParameterValue(self.OPTIONS))
6970

7071
arguments = []
7172
arguments.append('-clipsrc')
7273
arguments.append(ogrClipLayer)
7374
arguments.append("-clipsrclayer")
74-
arguments.append(self.ogrLayerName(clipLayer))
75+
arguments.append(ogrLayerName(clipLayer))
7576
if len(options) > 0:
7677
arguments.append(options)
7778

7879
arguments.append(output)
7980
arguments.append(ogrLayer)
80-
arguments.append(self.ogrLayerName(inLayer))
81+
arguments.append(ogrLayerName(inLayer))
8182

8283
commands = []
8384
if isWindows():

0 commit comments

Comments
 (0)