Skip to content

Commit d7f7b06

Browse files
committedNov 18, 2014
Merge pull request #1614 from radosuav/small_fixes
Small fixes for Processing
2 parents eef435e + da91a9e commit d7f7b06

File tree

4 files changed

+96
-3
lines changed

4 files changed

+96
-3
lines changed
 

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from translate import translate
4343
from pct2rgb import pct2rgb
4444
from merge import merge
45+
from buildvrt import buildvrt
4546
from polygonize import polygonize
4647
from gdaladdo import gdaladdo
4748
from ClipByExtent import ClipByExtent
@@ -114,7 +115,7 @@ def createAlgsList(self):
114115
# extending GeoAlgorithm directly (those that execute GDAL
115116
# using the console)
116117
self.preloadedAlgs = [nearblack(), information(), warp(), translate(),
117-
rgb2pct(), pct2rgb(), merge(), polygonize(), gdaladdo(),
118+
rgb2pct(), pct2rgb(), merge(), buildvrt(), polygonize(), gdaladdo(),
118119
ClipByExtent(), ClipByMask(), contour(), rasterize(), proximity(),
119120
sieve(), fillnodata(), ExtractProjection(), gdal2xyz(),
120121
hillshade(), slope(), aspect(), tri(), tpi(), roughness(),
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
merge.py
6+
---------------------
7+
Date : October 2014
8+
Copyright : (C) 2014 by Radoslaw Guzinski
9+
Email : rmgu at dhi-gras 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__ = 'Radoslaw Guzinski'
21+
__date__ = 'October 2014'
22+
__copyright__ = '(C) 2014, Radoslaw Guzinski'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
29+
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
30+
from processing.core.outputs import OutputRaster
31+
from processing.core.parameters import ParameterBoolean
32+
from processing.core.parameters import ParameterMultipleInput
33+
from processing.core.parameters import ParameterSelection
34+
from processing.tools.system import *
35+
from processing.algs.gdal.GdalUtils import GdalUtils
36+
import os
37+
38+
class buildvrt(GdalAlgorithm):
39+
40+
INPUT = 'INPUT'
41+
OUTPUT = 'OUTPUT'
42+
RESOLUTION = 'RESOLUTION'
43+
SEPARATE = 'SEPARATE'
44+
PROJ_DIFFERENCE = 'PROJ_DIFFERENCE'
45+
46+
RESOLUTION_OPTIONS = ['average', 'highest', 'lowest']
47+
48+
def defineCharacteristics(self):
49+
self.name = 'Build Virtual Raster'
50+
self.group = '[GDAL] Miscellaneous'
51+
self.addParameter(ParameterMultipleInput(buildvrt.INPUT, 'Input layers', ParameterMultipleInput.TYPE_RASTER))
52+
self.addParameter(ParameterSelection(buildvrt.RESOLUTION, 'Resolution', buildvrt.RESOLUTION_OPTIONS, 0))
53+
self.addParameter(ParameterBoolean(buildvrt.SEPARATE, 'Layer stack', True))
54+
self.addParameter(ParameterBoolean(buildvrt.PROJ_DIFFERENCE, 'Allow projection difference', False))
55+
self.addOutput(OutputRaster(buildvrt.OUTPUT, 'Output layer'))
56+
57+
def processAlgorithm(self, progress):
58+
arguments = []
59+
arguments.append('-resolution')
60+
arguments.append(self.RESOLUTION_OPTIONS[self.getParameterValue(self.RESOLUTION)])
61+
if self.getParameterValue(buildvrt.SEPARATE):
62+
arguments.append('-separate')
63+
if self.getParameterValue(buildvrt.PROJ_DIFFERENCE):
64+
arguments.append('-allow_projection_difference')
65+
# Always write input files to a text file in case there are many of them and the
66+
# length of the command will be longer then allowed in command prompt
67+
listFile = os.path.join(tempFolder(), 'buildvrtInputFiles.txt')
68+
with open(listFile, 'w') as f:
69+
f.write(self.getParameterValue(buildvrt.INPUT).replace(';', '\n'))
70+
arguments.append('-input_file_list')
71+
arguments.append(listFile)
72+
out = self.getOutputValue(buildvrt.OUTPUT)
73+
# Ideally the file extensions should be limited to just .vrt but I'm not sure how
74+
# to do it simply so instead a check is performed.
75+
_, ext = os.path.splitext(out)
76+
if not ext.lower() == '.vrt':
77+
out = out.replace(ext, '.vrt')
78+
self.setOutputValue(self.OUTPUT, out)
79+
arguments.append(out)
80+
81+
82+
GdalUtils.runGdal(['gdalbuildvrt', GdalUtils.escapeAndJoin(arguments)], progress)

‎python/plugins/processing/algs/otb/OTBAlgorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def defineCharacteristicsFromFile(self):
148148
try:
149149
if line.startswith("Parameter") or line.startswith("*Parameter"):
150150
if line.startswith("*Parameter"):
151-
param = ParameterFactory.getFromString(line[1:])
151+
param = getParameterFromString(line[1:])
152152
param.isAdvanced = True
153153
else:
154154
param = getParameterFromString(line)

‎python/plugins/processing/core/Processing.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ def initialize():
151151
ProcessingConfig.readSettings()
152152
RenderingStyles.loadStyles()
153153
Processing.loadFromProviders()
154-
154+
155+
# Inform registered listeners that all providers' algorithms have been loaded
156+
Processing.fireAlgsListHasChanged()
157+
155158
@staticmethod
156159
def updateAlgsList():
157160
"""Call this method when there has been any change that
@@ -182,6 +185,13 @@ def addAlgListListener(listener):
182185
called for all registered listeners.
183186
"""
184187
Processing.listeners.append(listener)
188+
189+
@staticmethod
190+
def removeAlgListListener(listener):
191+
try:
192+
Processing.listeners.remove(listener)
193+
except:
194+
pass
185195

186196
@staticmethod
187197
def fireAlgsListHasChanged():

0 commit comments

Comments
 (0)
Please sign in to comment.