Skip to content

Commit 394f1ed

Browse files
committed
[processing] improve some gdal algoruthms
update resources_rc.py
1 parent 223b665 commit 394f1ed

File tree

6 files changed

+650
-158
lines changed

6 files changed

+650
-158
lines changed

python/plugins/processing/gdal/GdalOgrAlgorithmProvider.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
from processing.gdal.contour import contour
4949
from processing.gdal.rasterize import rasterize
5050
from processing.gdal.proximity import proximity
51+
from processing.gdal.sieve import sieve
52+
from processing.gdal.fillnodata import fillnodata
5153

5254
from processing.gdal.ogr2ogr import Ogr2Ogr
5355
from processing.gdal.ogrinfo import OgrInfo
@@ -97,7 +99,8 @@ def createAlgsList(self):
9799
self.preloadedAlgs = [nearblack(), information(), warp(), translate(),
98100
rgb2pct(), pct2rgb(), merge(), polygonize(),
99101
gdaladdo(), ClipByExtent(), ClipByMask(),
100-
contour(), rasterize(), proximity(),
102+
contour(), rasterize(), proximity(), sieve(),
103+
fillnodata(),
101104
OgrInfo(), Ogr2Ogr(), OgrSql()]
102105

103106
#And then we add those that are created as python scripts
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
fillnodata.py
6+
---------------------
7+
Date : August 2012
8+
Copyright : (C) 2012 by Victor Olaya
9+
Email : volayaf 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__ = 'Victor Olaya'
21+
__date__ = 'August 2012'
22+
__copyright__ = '(C) 2012, Victor Olaya'
23+
# This will get replaced with a git SHA1 when you do a git archive
24+
__revision__ = '$Format:%H$'
25+
26+
27+
import os
28+
from PyQt4 import QtGui, QtCore
29+
30+
from processing.core.GeoAlgorithm import GeoAlgorithm
31+
32+
from processing.parameters.ParameterRaster import ParameterRaster
33+
from processing.parameters.ParameterNumber import ParameterNumber
34+
from processing.parameters.ParameterBoolean import ParameterBoolean
35+
from processing.outputs.OutputRaster import OutputRaster
36+
37+
from processing.tools.system import *
38+
39+
from processing.gdal.GdalUtils import GdalUtils
40+
41+
class fillnodata(GeoAlgorithm):
42+
43+
INPUT = "INPUT"
44+
DISTANCE = "DISTANCE"
45+
ITERATIONS = "ITERATIONS"
46+
BAND = "BAND"
47+
MASK = "MASK"
48+
NO_DEFAULT_MASK = "NO_DEFAULT_MASK"
49+
OUTPUT = "OUTPUT"
50+
51+
def getIcon(self):
52+
filepath = os.path.dirname(__file__) + "/icons/fillnodata.png"
53+
return QtGui.QIcon(filepath)
54+
55+
def defineCharacteristics(self):
56+
self.name = "Fill nodata"
57+
self.group = "[GDAL] Analysis"
58+
self.addParameter(ParameterRaster(self.INPUT, "Input layer", False))
59+
self.addParameter(ParameterNumber(self.DISTANCE, "Search distance", 0, 9999, 100))
60+
self.addParameter(ParameterNumber(self.ITERATIONS, "Smooth iterations", 0, 9999, 0))
61+
self.addParameter(ParameterNumber(self.BAND, "Band to operate on", 1, 9999, 1))
62+
self.addParameter(ParameterRaster(self.MASK, "Validity mask", True))
63+
self.addParameter(ParameterBoolean(self.NO_DEFAULT_MASK, "Do not use default validity mask", False))
64+
65+
self.addOutput(OutputRaster(self.OUTPUT, "Output layer"))
66+
67+
def processAlgorithm(self, progress):
68+
output = self.getOutputValue(self.OUTPUT)
69+
70+
arguments = []
71+
arguments.append("-md")
72+
arguments.append(str(self.getParameterValue(self.DISTANCE)))
73+
74+
if self.getParameterValue(self.ITERATIONS) != 0:
75+
arguments.append("-si")
76+
arguments.append(str(self.getParameterValue(self.ITERATIONS)))
77+
78+
arguments.append("-b")
79+
arguments.append(str(self.getParameterValue(self.BAND)))
80+
81+
mask = self.getParameterValue(self.MASK)
82+
if mask is not None:
83+
arguments.append("-mask")
84+
arguments.append(mask)
85+
86+
if self.getParameterValue(self.NO_DEFAULT_MASK):
87+
arguments.append("-nomask")
88+
89+
arguments.append("-of")
90+
arguments.append(GdalUtils.getFormatShortNameFromFilename(output))
91+
92+
arguments.append(self.getParameterValue(self.INPUT))
93+
arguments.append(output)
94+
95+
commands = []
96+
if isWindows():
97+
commands = ["cmd.exe", "/C ", "gdal_fillnodata.bat", GdalUtils.escapeAndJoin(arguments)]
98+
else:
99+
commands = ["gdal_fillnodata.py", GdalUtils.escapeAndJoin(arguments)]
100+
101+
GdalUtils.runGdal(commands, progress)

python/plugins/processing/gdal/scripts/fillnodata.py

Lines changed: 0 additions & 71 deletions
This file was deleted.

python/plugins/processing/gdal/scripts/sieve.py

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
sieve.py
6+
---------------------
7+
Date : August 2012
8+
Copyright : (C) 2012 by Victor Olaya
9+
Email : volayaf 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__ = 'Victor Olaya'
21+
__date__ = 'August 2012'
22+
__copyright__ = '(C) 2012, Victor Olaya'
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 PyQt4 import QtGui, QtCore
28+
29+
from processing.core.GeoAlgorithm import GeoAlgorithm
30+
31+
from processing.parameters.ParameterRaster import ParameterRaster
32+
from processing.parameters.ParameterSelection import ParameterSelection
33+
from processing.parameters.ParameterNumber import ParameterNumber
34+
from processing.outputs.OutputRaster import OutputRaster
35+
36+
from processing.tools.system import *
37+
38+
from processing.gdal.GdalUtils import GdalUtils
39+
40+
class sieve(GeoAlgorithm):
41+
42+
INPUT = "INPUT"
43+
THRESHOLD = "THRESHOLD"
44+
CONNECTIONS = "CONNECTIONS"
45+
OUTPUT = "OUTPUT"
46+
47+
PIXEL_CONNECTIONS = ["4", "8"]
48+
49+
def getIcon(self):
50+
filepath = os.path.dirname(__file__) + "/icons/sieve.png"
51+
return QtGui.QIcon(filepath)
52+
53+
def defineCharacteristics(self):
54+
self.name = "Sieve"
55+
self.group = "[GDAL] Analysis"
56+
self.addParameter(ParameterRaster(self.INPUT, "Input layer", False))
57+
self.addParameter(ParameterNumber(self.THRESHOLD, "Threshold", 0, 9999, 2))
58+
self.addParameter(ParameterSelection(self.CONNECTIONS, "Pixel connection", self.PIXEL_CONNECTIONS, 0))
59+
60+
self.addOutput(OutputRaster(self.OUTPUT, "Output layer"))
61+
62+
def processAlgorithm(self, progress):
63+
output = self.getOutputValue(self.OUTPUT)
64+
65+
arguments = []
66+
arguments.append("-st")
67+
arguments.append(str(self.getParameterValue(self.THRESHOLD)))
68+
69+
arguments.append("-" + self.PIXEL_CONNECTIONS[self.getParameterValue(self.CONNECTIONS)])
70+
71+
arguments.append("-of")
72+
arguments.append(GdalUtils.getFormatShortNameFromFilename(output))
73+
74+
arguments.append(self.getParameterValue(self.INPUT))
75+
arguments.append(output)
76+
77+
commands = []
78+
if isWindows():
79+
commands = ["cmd.exe", "/C ", "gdal_sieve.bat", GdalUtils.escapeAndJoin(arguments)]
80+
else:
81+
commands = ["gdal_sieve.py", GdalUtils.escapeAndJoin(arguments)]
82+
83+
GdalUtils.runGdal(commands, progress)

0 commit comments

Comments
 (0)