Skip to content
Permalink
Browse files

[processing] some code cleaning

  • Loading branch information
volaya committed Sep 14, 2013
1 parent 1882bbc commit 71c8672654bf8a7a434b2953aed7feba6edf2495
@@ -25,12 +25,9 @@

from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qgis.core import *

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.tools import dataobjects, vector

from processing.parameters.ParameterVector import ParameterVector
from processing.parameters.ParameterString import ParameterString
from processing.parameters.ParameterNumber import ParameterNumber
@@ -49,11 +46,6 @@ class AddTableField(GeoAlgorithm):
TYPE_NAMES = ["Integer", "Float", "String"]
TYPES = [QVariant.Int, QVariant.Double, QVariant.String]

#===========================================================================
# def getIcon(self):
# return QtGui.QIcon(os.path.dirname(__file__) + "/../images/qgis.png")
#===========================================================================

def defineCharacteristics(self):
self.name = "Add field to attributes table"
self.group = "Vector table tools"
@@ -35,11 +35,6 @@ class AutoincrementalField(GeoAlgorithm):
INPUT = "INPUT"
OUTPUT = "OUTPUT"

#===========================================================================
# def getIcon(self):
# return QtGui.QIcon(os.path.dirname(__file__) + "/../images/toolbox.png")
#===========================================================================

def processAlgorithm(self, progress):
output = self.getOutputFromName(self.OUTPUT)
vlayer = dataobjects.getObjectFromUri(self.getParameterValue(self.INPUT))
@@ -37,11 +37,6 @@ class EquivalentNumField(GeoAlgorithm):
OUTPUT = "OUTPUT"
FIELD = "FIELD"

#===========================================================================
# def getIcon(self):
# return QtGui.QIcon(os.path.dirname(__file__) + "/../images/qgis.png")
#===========================================================================

def processAlgorithm(self, progress):
fieldname = self.getParameterValue(self.FIELD)
output = self.getOutputFromName(self.OUTPUT)
@@ -36,11 +36,6 @@ class Explode(GeoAlgorithm):
INPUT = "INPUT"
OUTPUT = "OUTPUT"

#===========================================================================
# def getIcon(self):
# return QtGui.QIcon(os.path.dirname(__file__) + "/../images/toolbox.png")
#===========================================================================

def processAlgorithm(self, progress):
vlayer = dataobjects.getObjectFromUri(self.getParameterValue(self.INPUT))
output = self.getOutputFromName(self.OUTPUT)
@@ -5,7 +5,7 @@
FieldPyculator.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Copyright : (C) 2012 by Victor Olaya & NextGIS
Email : volayaf at gmail dot com
***************************************************************************
* *
@@ -17,27 +17,22 @@
***************************************************************************
"""

__author__ = 'Victor Olaya'
__author__ = 'Victor Olaya & NextGIS'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
__copyright__ = '(C) 2012, Victor Olaya & NextGIS'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import sys

from PyQt4.QtCore import *

from qgis.core import *

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.tools import dataobjects, vector
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException

from processing.parameters.ParameterVector import ParameterVector
from processing.parameters.ParameterString import ParameterString
from processing.parameters.ParameterNumber import ParameterNumber
from processing.parameters.ParameterSelection import ParameterSelection

from processing.outputs.OutputVector import OutputVector


@@ -24,17 +24,13 @@
__revision__ = '$Format:%H$'

from PyQt4.QtCore import *

from qgis.core import *

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.tools import dataobjects, vector

from processing.parameters.ParameterVector import ParameterVector
from processing.parameters.ParameterString import ParameterString
from processing.parameters.ParameterNumber import ParameterNumber
from processing.parameters.ParameterSelection import ParameterSelection

from processing.outputs.OutputVector import OutputVector

class FieldsCalculator(GeoAlgorithm):
@@ -32,7 +32,6 @@
from PyQt4.QtGui import *
from processing.tools import dataobjects, vector


class JoinAttributes(GeoAlgorithm):

OUTPUT_LAYER = "OUTPUT_LAYER"
@@ -33,7 +33,6 @@
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.outputs.OutputHTML import OutputHTML
from processing.tools import *
from processing.tools import dataobjects

class MeanAndStdDevPlot(GeoAlgorithm):

@@ -54,7 +53,6 @@ def processAlgorithm(self, progress):
values = vector.getAttributeValues(layer, namefieldname, meanfieldname, stddevfieldname)
plt.close()


ind = np.arange(len(values[namefieldname]))
width = 0.8
plt.bar(ind, values[meanfieldname], width,
@@ -40,8 +40,8 @@ class PointsFromLines(GeoAlgorithm):
OUTPUT_LAYER = "OUTPUT_LAYER"

def defineCharacteristics(self):
self.name = "Get raster values at layer point"
self.group = "Vector geometry tools"
self.name = "Get raster values at line nodes"
self.group = "Vector analysis tools"

self.addParameter(ParameterRaster(self.INPUT_RASTER, "Raster layer"))
self.addParameter(ParameterVector(self.INPUT_VECTOR, "Vector layer", [ParameterVector.VECTOR_TYPE_LINE]))
@@ -41,8 +41,8 @@ class PointsFromPolygons(GeoAlgorithm):
OUTPUT_LAYER = "OUTPUT_LAYER"

def defineCharacteristics(self):
self.name = "Points from polygons"
self.group = "Vector geometry tools"
self.name = "Get raster values at polygon nodes"
self.group = "Vector analysis tools"

self.addParameter(ParameterRaster(self.INPUT_RASTER, "Raster layer"))
self.addParameter(ParameterVector(self.INPUT_VECTOR, "Vector layer", [ParameterVector.VECTOR_TYPE_POLYGON]))
@@ -25,9 +25,7 @@
__revision__ = '$Format:%H$'

from PyQt4.QtGui import *

from processing.core.AlgorithmProvider import AlgorithmProvider

from processing.algs.ftools.PointsInPolygon import PointsInPolygon
from processing.algs.ftools.PointsInPolygonUnique import PointsInPolygonUnique
from processing.algs.ftools.PointsInPolygonWeighted import PointsInPolygonWeighted
@@ -85,7 +83,6 @@
from processing.algs.JoinAttributes import JoinAttributes
from processing.algs.CreateConstantRaster import CreateConstantRaster
from processing.algs.PointsLayerFromTable import PointsLayerFromTable

from processing.algs.PointsDisplacement import PointsDisplacement
from processing.algs.ZonalStatistics import ZonalStatistics
from processing.algs.PointsFromPolygons import PointsFromPolygons
@@ -16,7 +16,7 @@
* *
***************************************************************************
"""
from processing import interface

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
@@ -30,6 +30,8 @@
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from processing import interface
from processing.tools.system import isWindows
from processing.outputs.OutputHTML import OutputHTML
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.parameters.ParameterTable import ParameterTable
@@ -46,14 +48,19 @@
from processing.core.ProcessingConfig import ProcessingConfig
from processing.tools import dataobjects
from processing.grass.GrassUtils import GrassUtils
from processing.tools.system import *
from processing.parameters.ParameterSelection import ParameterSelection
from processing.core.WrongHelpFileException import WrongHelpFileException
from processing.outputs.OutputFile import OutputFile
from processing.parameters.ParameterExtent import ParameterExtent
from processing.parameters.ParameterNumber import ParameterNumber
from processing.parameters.ParameterString import ParameterString

NUM_EXPORTED = 1

def getNumExportedLayers():
NUM_EXPORTED += 1
return NUM_EXPORTED

class GrassAlgorithm(GeoAlgorithm):

GRASS_OUTPUT_TYPE_PARAMETER = "GRASS_OUTPUT_TYPE_PARAMETER"
@@ -275,12 +275,6 @@ def executeGrass(commands, progress, outputCommands = None):
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
return loglines;

@staticmethod
def getGrassVersion():
#I do not know if this should be removed or let the user enter it
#or something like that... This is just a temporary thing
return "6.4.0"

# GRASS session is used to hold the layers already exported or produced in GRASS
# between multiple calls to GRASS algorithms. This way they don't have
# to be loaded multiple times and following algorithms can use the results
@@ -96,7 +96,7 @@ to tag a parameter as "advanced", just add "*" before its declaration. For insta
ADVANCED OUTPUT PROCESSING
--------------------------

In some cases, it might be interesting to take the console otput from GRASS and
In some cases, it might be interesting to take the console output from GRASS and
extract a part of it for saving or formatting.

Two things can be done about this:
@@ -108,7 +108,7 @@ Two things can be done about this:
by low hyphens (for instance r_quantile.py for the r.quantile command), and
add a postProcessResults(alg) method. It will be called when the execution of
the GRASS command is finished.
- Creating a text file. Do as above, but adding an otput of type OutputFile.
- Creating a text file. Do as above, but adding an output of type OutputFile.
Since some GRASS commands might use this type of output, and to make sure that
the value of this output is not passed to the GRASS comman when calling it,
the value of this output is not passed to the GRASS command when calling it,
the output has to be named 'outputtext'
@@ -16,8 +16,6 @@
* *
***************************************************************************
"""
from processing.parameters.ParameterTableField import ParameterTableField

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
@@ -48,7 +46,7 @@
from processing.tools import dataobjects
from processing.parameters.ParameterNumber import ParameterNumber
from processing.parameters.ParameterSelection import ParameterSelection
from processing.tools import dataobjects
from processing.parameters.ParameterTableField import ParameterTableField
from processing.parameters.ParameterExtent import ParameterExtent
from processing.parameters.ParameterFixedTable import ParameterFixedTable
from processing.core.ProcessingLog import ProcessingLog
@@ -329,7 +327,7 @@ def processAlgorithm(self, progress):
def preProcessInputs(self):
name = self.commandLineName().replace('.','_')[len('saga:'):]
try:
module = importlib.import_module('processing.grass.ext.' + name)
module = importlib.import_module('processing.saga.ext.' + name)
except ImportError:
return
if hasattr(module, 'preProcessInputs'):
@@ -30,7 +30,6 @@
from PyQt4.QtCore import *
from qgis.core import *


def userFolder():
userDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/processing"
if not QDir(userDir).exists():
@@ -73,7 +72,7 @@ def getTempFilenameInTempFolder(basename):
return filename

def removeInvalidChars(string):
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:."
string = ''.join(c for c in string if c in validChars)
return string

0 comments on commit 71c8672

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