Skip to content
Permalink
Browse files

Merge pull request #1614 from radosuav/small_fixes

Small fixes for Processing
  • Loading branch information
volaya committed Nov 18, 2014
2 parents eef435e + da91a9e commit d7f7b06ed8af1f86cc31c4d022868637361036b5
@@ -42,6 +42,7 @@
from translate import translate
from pct2rgb import pct2rgb
from merge import merge
from buildvrt import buildvrt
from polygonize import polygonize
from gdaladdo import gdaladdo
from ClipByExtent import ClipByExtent
@@ -114,7 +115,7 @@ def createAlgsList(self):
# extending GeoAlgorithm directly (those that execute GDAL
# using the console)
self.preloadedAlgs = [nearblack(), information(), warp(), translate(),
rgb2pct(), pct2rgb(), merge(), polygonize(), gdaladdo(),
rgb2pct(), pct2rgb(), merge(), buildvrt(), polygonize(), gdaladdo(),
ClipByExtent(), ClipByMask(), contour(), rasterize(), proximity(),
sieve(), fillnodata(), ExtractProjection(), gdal2xyz(),
hillshade(), slope(), aspect(), tri(), tpi(), roughness(),
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
merge.py
---------------------
Date : October 2014
Copyright : (C) 2014 by Radoslaw Guzinski
Email : rmgu at dhi-gras dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Radoslaw Guzinski'
__date__ = 'October 2014'
__copyright__ = '(C) 2014, Radoslaw Guzinski'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'


from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.core.outputs import OutputRaster
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterMultipleInput
from processing.core.parameters import ParameterSelection
from processing.tools.system import *
from processing.algs.gdal.GdalUtils import GdalUtils
import os

class buildvrt(GdalAlgorithm):

INPUT = 'INPUT'
OUTPUT = 'OUTPUT'
RESOLUTION = 'RESOLUTION'
SEPARATE = 'SEPARATE'
PROJ_DIFFERENCE = 'PROJ_DIFFERENCE'

RESOLUTION_OPTIONS = ['average', 'highest', 'lowest']

def defineCharacteristics(self):
self.name = 'Build Virtual Raster'
self.group = '[GDAL] Miscellaneous'
self.addParameter(ParameterMultipleInput(buildvrt.INPUT, 'Input layers', ParameterMultipleInput.TYPE_RASTER))
self.addParameter(ParameterSelection(buildvrt.RESOLUTION, 'Resolution', buildvrt.RESOLUTION_OPTIONS, 0))
self.addParameter(ParameterBoolean(buildvrt.SEPARATE, 'Layer stack', True))
self.addParameter(ParameterBoolean(buildvrt.PROJ_DIFFERENCE, 'Allow projection difference', False))
self.addOutput(OutputRaster(buildvrt.OUTPUT, 'Output layer'))

def processAlgorithm(self, progress):
arguments = []
arguments.append('-resolution')
arguments.append(self.RESOLUTION_OPTIONS[self.getParameterValue(self.RESOLUTION)])
if self.getParameterValue(buildvrt.SEPARATE):
arguments.append('-separate')
if self.getParameterValue(buildvrt.PROJ_DIFFERENCE):
arguments.append('-allow_projection_difference')
# Always write input files to a text file in case there are many of them and the
# length of the command will be longer then allowed in command prompt
listFile = os.path.join(tempFolder(), 'buildvrtInputFiles.txt')
with open(listFile, 'w') as f:
f.write(self.getParameterValue(buildvrt.INPUT).replace(';', '\n'))
arguments.append('-input_file_list')
arguments.append(listFile)
out = self.getOutputValue(buildvrt.OUTPUT)
# Ideally the file extensions should be limited to just .vrt but I'm not sure how
# to do it simply so instead a check is performed.
_, ext = os.path.splitext(out)
if not ext.lower() == '.vrt':
out = out.replace(ext, '.vrt')
self.setOutputValue(self.OUTPUT, out)
arguments.append(out)


GdalUtils.runGdal(['gdalbuildvrt', GdalUtils.escapeAndJoin(arguments)], progress)
@@ -148,7 +148,7 @@ def defineCharacteristicsFromFile(self):
try:
if line.startswith("Parameter") or line.startswith("*Parameter"):
if line.startswith("*Parameter"):
param = ParameterFactory.getFromString(line[1:])
param = getParameterFromString(line[1:])
param.isAdvanced = True
else:
param = getParameterFromString(line)
@@ -151,7 +151,10 @@ def initialize():
ProcessingConfig.readSettings()
RenderingStyles.loadStyles()
Processing.loadFromProviders()


# Inform registered listeners that all providers' algorithms have been loaded
Processing.fireAlgsListHasChanged()

@staticmethod
def updateAlgsList():
"""Call this method when there has been any change that
@@ -182,6 +185,13 @@ def addAlgListListener(listener):
called for all registered listeners.
"""
Processing.listeners.append(listener)

@staticmethod
def removeAlgListListener(listener):
try:
Processing.listeners.remove(listener)
except:
pass

@staticmethod
def fireAlgsListHasChanged():

0 comments on commit d7f7b06

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