Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes for Processing #1614

Merged
merged 6 commits into from Nov 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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
Expand Down Expand Up @@ -112,7 +113,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(),
Expand Down
82 changes: 82 additions & 0 deletions python/plugins/processing/algs/gdal/buildvrt.py
@@ -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)
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/otb/OTBAlgorithm.py
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion python/plugins/processing/core/Processing.py
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down