Skip to content
Permalink
Browse files
Merge pull request #4412 from nyalldawson/processing_get_features
Port processing vector.features to c++
  • Loading branch information
nyalldawson committed Apr 26, 2017
2 parents fea6bff + a4cd66f commit 5169e0db65f631e6d1f889ae984f6e61d0ec6795
Showing with 1,242 additions and 767 deletions.
  1. +1 −0 python/core/core.sip
  2. +127 −0 python/core/processing/qgsprocessingcontext.sip
  3. +27 −0 python/core/processing/qgsprocessingutils.sip
  4. +6 −4 python/plugins/processing/algs/exampleprovider/ExampleAlgorithm.py
  5. +1 −1 python/plugins/processing/algs/gdal/GdalAlgorithm.py
  6. +1 −1 python/plugins/processing/algs/gdal/extractprojection.py
  7. +1 −1 python/plugins/processing/algs/gdal/information.py
  8. +2 −2 python/plugins/processing/algs/gdal/ogr2ogrtabletopostgislist.py
  9. +2 −2 python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py
  10. +1 −1 python/plugins/processing/algs/gdal/ogrinfo.py
  11. +1 −1 python/plugins/processing/algs/grass7/Grass7Algorithm.py
  12. +1 −1 python/plugins/processing/algs/grass7/nviz7.py
  13. +5 −4 python/plugins/processing/algs/qgis/AddTableField.py
  14. +1 −1 python/plugins/processing/algs/qgis/Aspect.py
  15. +5 −4 python/plugins/processing/algs/qgis/AutoincrementalField.py
  16. +2 −2 python/plugins/processing/algs/qgis/BarPlot.py
  17. +11 −12 python/plugins/processing/algs/qgis/BasicStatistics.py
  18. +5 −4 python/plugins/processing/algs/qgis/BasicStatisticsNumbers.py
  19. +5 −4 python/plugins/processing/algs/qgis/BasicStatisticsStrings.py
  20. +4 −4 python/plugins/processing/algs/qgis/Boundary.py
  21. +4 −4 python/plugins/processing/algs/qgis/BoundingBox.py
  22. +2 −2 python/plugins/processing/algs/qgis/BoxPlot.py
  23. +5 −5 python/plugins/processing/algs/qgis/Buffer.py
  24. +4 −4 python/plugins/processing/algs/qgis/Centroids.py
  25. +6 −6 python/plugins/processing/algs/qgis/CheckValidity.py
  26. +5 −4 python/plugins/processing/algs/qgis/Clip.py
  27. +1 −1 python/plugins/processing/algs/qgis/ConcaveHull.py
  28. +6 −6 python/plugins/processing/algs/qgis/ConvexHull.py
  29. +1 −1 python/plugins/processing/algs/qgis/CreateAttributeIndex.py
  30. +1 −1 python/plugins/processing/algs/qgis/CreateConstantRaster.py
  31. +1 −1 python/plugins/processing/algs/qgis/Datasources2Vrt.py
  32. +1 −1 python/plugins/processing/algs/qgis/DefineProjection.py
  33. +4 −4 python/plugins/processing/algs/qgis/Delaunay.py
  34. +5 −4 python/plugins/processing/algs/qgis/DeleteColumn.py
  35. +5 −4 python/plugins/processing/algs/qgis/DeleteDuplicateGeometries.py
  36. +5 −4 python/plugins/processing/algs/qgis/DeleteHoles.py
  37. +5 −4 python/plugins/processing/algs/qgis/DensifyGeometries.py
  38. +5 −4 python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py
  39. +4 −4 python/plugins/processing/algs/qgis/Difference.py
  40. +4 −4 python/plugins/processing/algs/qgis/Dissolve.py
  41. +5 −4 python/plugins/processing/algs/qgis/DropGeometry.py
  42. +1 −1 python/plugins/processing/algs/qgis/EliminateSelection.py
  43. +5 −4 python/plugins/processing/algs/qgis/EquivalentNumField.py
  44. +5 −4 python/plugins/processing/algs/qgis/ExecuteSQL.py
  45. +5 −4 python/plugins/processing/algs/qgis/Explode.py
  46. +4 −4 python/plugins/processing/algs/qgis/ExportGeometryInfo.py
  47. +5 −4 python/plugins/processing/algs/qgis/ExtendLines.py
  48. +6 −6 python/plugins/processing/algs/qgis/ExtentFromLayer.py
  49. +1 −1 python/plugins/processing/algs/qgis/ExtractByAttribute.py
  50. +1 −1 python/plugins/processing/algs/qgis/ExtractByExpression.py
  51. +8 −7 python/plugins/processing/algs/qgis/ExtractByLocation.py
  52. +4 −4 python/plugins/processing/algs/qgis/ExtractNodes.py
  53. +5 −4 python/plugins/processing/algs/qgis/ExtractSpecificNodes.py
  54. +5 −4 python/plugins/processing/algs/qgis/FieldPyculator.py
  55. +5 −4 python/plugins/processing/algs/qgis/FieldsCalculator.py
  56. +7 −5 python/plugins/processing/algs/qgis/FieldsMapper.py
  57. +1 −1 python/plugins/processing/algs/qgis/FindProjection.py
  58. +6 −5 python/plugins/processing/algs/qgis/FixGeometry.py
  59. +3 −3 python/plugins/processing/algs/qgis/FixedDistanceBuffer.py
  60. +5 −4 python/plugins/processing/algs/qgis/GeometryByExpression.py
  61. +5 −4 python/plugins/processing/algs/qgis/GeometryConvert.py
  62. +1 −1 python/plugins/processing/algs/qgis/GridLine.py
  63. +1 −1 python/plugins/processing/algs/qgis/GridPolygon.py
  64. +5 −4 python/plugins/processing/algs/qgis/Gridify.py
  65. +4 −4 python/plugins/processing/algs/qgis/Heatmap.py
  66. +1 −1 python/plugins/processing/algs/qgis/Hillshade.py
  67. +5 −4 python/plugins/processing/algs/qgis/HubDistanceLines.py
  68. +5 −4 python/plugins/processing/algs/qgis/HubDistancePoints.py
  69. +6 −5 python/plugins/processing/algs/qgis/HubLines.py
  70. +5 −4 python/plugins/processing/algs/qgis/HypsometricCurves.py
  71. +1 −1 python/plugins/processing/algs/qgis/IdwInterpolation.py
  72. +1 −1 python/plugins/processing/algs/qgis/ImportIntoPostGIS.py
  73. +1 −1 python/plugins/processing/algs/qgis/ImportIntoSpatialite.py
  74. +4 −4 python/plugins/processing/algs/qgis/Intersection.py
  75. +7 −6 python/plugins/processing/algs/qgis/JoinAttributes.py
  76. +5 −4 python/plugins/processing/algs/qgis/LinesIntersection.py
  77. +4 −4 python/plugins/processing/algs/qgis/LinesToPolygons.py
  78. +2 −2 python/plugins/processing/algs/qgis/MeanAndStdDevPlot.py
  79. +4 −4 python/plugins/processing/algs/qgis/MeanCoords.py
  80. +1 −1 python/plugins/processing/algs/qgis/Merge.py
  81. +4 −4 python/plugins/processing/algs/qgis/MergeLines.py
  82. +4 −4 python/plugins/processing/algs/qgis/MultipartToSingleparts.py
  83. +4 −4 python/plugins/processing/algs/qgis/NearestNeighbourAnalysis.py
  84. +5 −4 python/plugins/processing/algs/qgis/OffsetLine.py
  85. +11 −10 python/plugins/processing/algs/qgis/OrientedMinimumBoundingBox.py
  86. +5 −4 python/plugins/processing/algs/qgis/Orthogonalize.py
  87. +12 −12 python/plugins/processing/algs/qgis/PointDistance.py
  88. +4 −4 python/plugins/processing/algs/qgis/PointOnSurface.py
  89. +4 −4 python/plugins/processing/algs/qgis/PointsAlongGeometry.py
  90. +5 −4 python/plugins/processing/algs/qgis/PointsDisplacement.py
  91. +5 −4 python/plugins/processing/algs/qgis/PointsFromLines.py
  92. +5 −4 python/plugins/processing/algs/qgis/PointsFromPolygons.py
  93. +4 −4 python/plugins/processing/algs/qgis/PointsInPolygon.py
  94. +5 −4 python/plugins/processing/algs/qgis/PointsInPolygonUnique.py
  95. +5 −4 python/plugins/processing/algs/qgis/PointsInPolygonWeighted.py
  96. +5 −4 python/plugins/processing/algs/qgis/PointsLayerFromTable.py
  97. +5 −4 python/plugins/processing/algs/qgis/PointsToPaths.py
  98. +2 −2 python/plugins/processing/algs/qgis/PolarPlot.py
  99. +4 −4 python/plugins/processing/algs/qgis/PoleOfInaccessibility.py
  100. +5 −4 python/plugins/processing/algs/qgis/PolygonCentroids.py
  101. +5 −4 python/plugins/processing/algs/qgis/Polygonize.py
  102. +4 −4 python/plugins/processing/algs/qgis/PolygonsToLines.py
  103. +1 −1 python/plugins/processing/algs/qgis/PostGISExecuteSQL.py
  104. +5 −4 python/plugins/processing/algs/qgis/RandomExtract.py
  105. +9 −8 python/plugins/processing/algs/qgis/RandomExtractWithinSubsets.py
  106. +1 −1 python/plugins/processing/algs/qgis/RandomPointsAlongLines.py
  107. +1 −1 python/plugins/processing/algs/qgis/RandomPointsExtent.py
  108. +1 −1 python/plugins/processing/algs/qgis/RandomPointsLayer.py
  109. +4 −3 python/plugins/processing/algs/qgis/RandomPointsPolygonsFixed.py
  110. +4 −3 python/plugins/processing/algs/qgis/RandomPointsPolygonsVariable.py
  111. +1 −1 python/plugins/processing/algs/qgis/RandomSelection.py
  112. +4 −4 python/plugins/processing/algs/qgis/RandomSelectionWithinSubsets.py
  113. +1 −1 python/plugins/processing/algs/qgis/RasterCalculator.py
  114. +1 −1 python/plugins/processing/algs/qgis/RasterLayerHistogram.py
  115. +1 −1 python/plugins/processing/algs/qgis/RasterLayerStatistics.py
  116. +4 −3 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsFixed.py
  117. +4 −3 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py
  118. +1 −1 python/plugins/processing/algs/qgis/RegularPoints.py
  119. +1 −1 python/plugins/processing/algs/qgis/Relief.py
  120. +5 −4 python/plugins/processing/algs/qgis/RemoveNullGeometry.py
  121. +4 −4 python/plugins/processing/algs/qgis/ReprojectLayer.py
  122. +5 −4 python/plugins/processing/algs/qgis/ReverseLineDirection.py
  123. +1 −1 python/plugins/processing/algs/qgis/Ruggedness.py
  124. +1 −1 python/plugins/processing/algs/qgis/SaveSelectedFeatures.py
  125. +1 −1 python/plugins/processing/algs/qgis/SelectByAttribute.py
  126. +1 −1 python/plugins/processing/algs/qgis/SelectByAttributeSum.py
  127. +1 −1 python/plugins/processing/algs/qgis/SelectByExpression.py
  128. +5 −5 python/plugins/processing/algs/qgis/SelectByLocation.py
  129. +3 −3 python/plugins/processing/algs/qgis/ServiceAreaFromLayer.py
  130. +1 −1 python/plugins/processing/algs/qgis/ServiceAreaFromPoint.py
  131. +1 −1 python/plugins/processing/algs/qgis/SetRasterStyle.py
  132. +1 −1 python/plugins/processing/algs/qgis/SetVectorStyle.py
  133. +4 −4 python/plugins/processing/algs/qgis/ShortestPathLayerToPoint.py
  134. +4 −4 python/plugins/processing/algs/qgis/ShortestPathPointToLayer.py
  135. +1 −1 python/plugins/processing/algs/qgis/ShortestPathPointToPoint.py
  136. +4 −4 python/plugins/processing/algs/qgis/SimplifyGeometries.py
  137. +4 −4 python/plugins/processing/algs/qgis/SinglePartsToMultiparts.py
  138. +5 −4 python/plugins/processing/algs/qgis/SingleSidedBuffer.py
  139. +1 −1 python/plugins/processing/algs/qgis/Slope.py
  140. +5 −4 python/plugins/processing/algs/qgis/Smooth.py
  141. +5 −4 python/plugins/processing/algs/qgis/SnapGeometries.py
  142. +1 −1 python/plugins/processing/algs/qgis/SpatialIndex.py
  143. +5 −5 python/plugins/processing/algs/qgis/SpatialJoin.py
  144. +1 −1 python/plugins/processing/algs/qgis/SpatialiteExecuteSQL.py
  145. +5 −4 python/plugins/processing/algs/qgis/SplitLinesWithLines.py
  146. +7 −6 python/plugins/processing/algs/qgis/SplitWithLines.py
  147. +5 −4 python/plugins/processing/algs/qgis/StatisticsByCategories.py
  148. +4 −4 python/plugins/processing/algs/qgis/SumLines.py
  149. +5 −5 python/plugins/processing/algs/qgis/SymmetricalDifference.py
  150. +5 −4 python/plugins/processing/algs/qgis/TextToFloat.py
  151. +1 −1 python/plugins/processing/algs/qgis/TinInterpolation.py
  152. +4 −3 python/plugins/processing/algs/qgis/TopoColors.py
  153. +5 −4 python/plugins/processing/algs/qgis/Translate.py
  154. +1 −1 python/plugins/processing/algs/qgis/TruncateTable.py
  155. +6 −6 python/plugins/processing/algs/qgis/Union.py
  156. +5 −3 python/plugins/processing/algs/qgis/UniqueValues.py
  157. +2 −3 python/plugins/processing/algs/qgis/VariableDistanceBuffer.py
  158. +1 −1 python/plugins/processing/algs/qgis/VectorGridLines.py
  159. +1 −1 python/plugins/processing/algs/qgis/VectorGridPolygons.py
  160. +2 −2 python/plugins/processing/algs/qgis/VectorLayerHistogram.py
  161. +2 −2 python/plugins/processing/algs/qgis/VectorLayerScatterplot.py
  162. +2 −2 python/plugins/processing/algs/qgis/VectorLayerScatterplot3D.py
  163. +4 −3 python/plugins/processing/algs/qgis/VectorSplit.py
  164. +4 −4 python/plugins/processing/algs/qgis/VoronoiPolygons.py
  165. +6 −4 python/plugins/processing/algs/qgis/ZonalStatistics.py
  166. +1 −1 python/plugins/processing/algs/qgis/ZonalStatisticsQgis.py
  167. +3 −2 python/plugins/processing/algs/qgis/scripts/Frequency_analysis.py
  168. +2 −2 python/plugins/processing/algs/qgis/scripts/Keep_n_biggest_parts.py
  169. +3 −3 python/plugins/processing/algs/qgis/scripts/Number_of_unique_values_in_classes.py
  170. +1 −1 python/plugins/processing/algs/qgis/ui/FieldsCalculatorDialog.py
  171. +1 −1 python/plugins/processing/algs/r/RAlgorithm.py
  172. +1 −1 python/plugins/processing/algs/saga/SagaAlgorithm.py
  173. +1 −1 python/plugins/processing/algs/saga/SplitRGBBands.py
  174. +11 −8 python/plugins/processing/core/GeoAlgorithm.py
  175. +2 −1 python/plugins/processing/core/Processing.py
  176. +2 −2 python/plugins/processing/core/parameters.py
  177. +4 −2 python/plugins/processing/gui/AlgorithmDialog.py
  178. +9 −7 python/plugins/processing/gui/AlgorithmExecutor.py
  179. +1 −1 python/plugins/processing/gui/BatchAlgorithmDialog.py
  180. +1 −1 python/plugins/processing/gui/ProcessingToolbox.py
  181. +1 −1 python/plugins/processing/gui/menus.py
  182. +2 −2 python/plugins/processing/modeler/ModelerAlgorithm.py
  183. +1 −1 python/plugins/processing/preconfigured/PreconfiguredAlgorithm.py
  184. +2 −1 python/plugins/processing/script/ScriptAlgorithm.py
  185. +8 −3 python/plugins/processing/tests/AlgorithmsTestBase.py
  186. +12 −108 python/plugins/processing/tests/ToolsTest.py
  187. +4 −4 python/plugins/processing/tests/testdata/scripts/centroids.py
  188. +27 −1 python/plugins/processing/tools/dataobjects.py
  189. +1 −1 python/plugins/processing/tools/general.py
  190. +6 −90 python/plugins/processing/tools/vector.py
  191. +1 −0 src/core/CMakeLists.txt
  192. +149 −0 src/core/processing/qgsprocessingcontext.h
  193. +57 −0 src/core/processing/qgsprocessingutils.cpp
  194. +25 −0 src/core/processing/qgsprocessingutils.h
  195. +162 −0 tests/src/core/testqgsprocessing.cpp
@@ -276,6 +276,7 @@
%Include layertree/qgslayertreeutils.sip

%Include processing/qgsprocessingalgorithm.sip
%Include processing/qgsprocessingcontext.sip
%Include processing/qgsprocessingfeedback.sip
%Include processing/qgsprocessingprovider.sip
%Include processing/qgsprocessingregistry.sip
@@ -0,0 +1,127 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsProcessingContext
{
%Docstring
Contains information about the context in which a processing algorithm is executed.

Contextual information includes settings such as the associated project, and
expression context.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsprocessingcontext.h"
%End
public:

enum Flag
{
UseSelectionIfPresent,
};
typedef QFlags<QgsProcessingContext::Flag> Flags;


QgsProcessingContext();
%Docstring
Constructor for QgsProcessingContext.
%End

QgsProcessingContext::Flags flags() const;
%Docstring
Returns any flags set in the context.
\see setFlags()
:rtype: QgsProcessingContext.Flags
%End

void setFlags( const QgsProcessingContext::Flags &flags );
%Docstring
Sets ``flags`` for the context.
\see flags()
%End

QgsProject *project() const;
%Docstring
Returns the project in which the algorithm is being executed.
\see setProject()
:rtype: QgsProject
%End

void setProject( QgsProject *project );
%Docstring
Sets the ``project`` in which the algorithm will be executed.
\see project()
%End

QgsExpressionContext expressionContext() const;
%Docstring
Returns the expression context.
:rtype: QgsExpressionContext
%End

void setExpressionContext( const QgsExpressionContext &context );
%Docstring
Sets the expression ``context``.
%End

QgsFeatureRequest::InvalidGeometryCheck invalidGeometryCheck() const;
%Docstring
Returns the behavior used for checking invalid geometries in input layers.
\see setInvalidGeometryCheck()
:rtype: QgsFeatureRequest.InvalidGeometryCheck
%End

void setInvalidGeometryCheck( const QgsFeatureRequest::InvalidGeometryCheck &check );
%Docstring
Sets the behavior used for checking invalid geometries in input layers.
\see invalidGeometryCheck()
%End


void setInvalidGeometryCallback( SIP_PYCALLABLE / AllowNone / );
%Docstring
Sets a callback function to use when encountering an invalid geometry and
invalidGeometryCheck() is set to GeometryAbortOnInvalid. This function will be
called using the feature with invalid geometry as a parameter.
.. versionadded:: 3.0
\see invalidGeometryCallback()
%End
%MethodCode
Py_BEGIN_ALLOW_THREADS

sipCpp->setInvalidGeometryCallback( [a0]( const QgsFeature &arg )
{
SIP_BLOCK_THREADS
Py_XDECREF( sipCallMethod( NULL, a0, "D", &arg, sipType_QgsFeature, NULL ) );
SIP_UNBLOCK_THREADS
} );

Py_END_ALLOW_THREADS
%End


};
QFlags<QgsProcessingContext::Flag> operator|(QgsProcessingContext::Flag f1, QFlags<QgsProcessingContext::Flag> f2);






/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -97,6 +97,33 @@ class QgsProcessingUtils
:rtype: str
%End

static QgsFeatureIterator getFeatures( QgsVectorLayer *layer, const QgsProcessingContext &context, const QgsFeatureRequest &request = QgsFeatureRequest() );
%Docstring
Returns an iterator for the features in a ``layer``, respecting
the settings from the supplied ``context``.
An optional base ``request`` can be used to optimise the returned
iterator, eg by restricting the returned attributes or geometry.
:rtype: QgsFeatureIterator
%End

static long featureCount( QgsVectorLayer *layer, const QgsProcessingContext &context );
%Docstring
Returns an approximate feature count for a ``layer``, when
the settings from the supplied ``context`` are respected. E.g. if the
context is set to only use selected features, then calling this will
return the count of selected features in the layer.
:rtype: long
%End

static QList< QVariant > uniqueValues( QgsVectorLayer *layer, int fieldIndex, const QgsProcessingContext &context );
%Docstring
Returns a list of unique values contained in a single field in a ``layer``, when
the settings from the supplied ``context`` are respected. E.g. if the
context is set to only use selected features, then calling this will
return unique values from selected features in the layer.
:rtype: list of QVariant
%End

};


@@ -25,7 +25,7 @@

__revision__ = '$Format:%H$'

from qgis.core import QgsVectorFileWriter, QgsSettings
from qgis.core import QgsVectorFileWriter, QgsSettings, QgsProcessingUtils

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
@@ -79,8 +79,10 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(self.OUTPUT_LAYER,
self.tr('Output layer with selected features')))

def processAlgorithm(self, feedback):
"""Here is where the processing itself takes place."""
def processAlgorithm(self, context, feedback):
"""Here is where the processing itself takes place.
:param context:
"""

# The first thing to do is retrieve the values of the parameters
# entered by the user
@@ -111,7 +113,7 @@ def processAlgorithm(self, feedback):
# selection that might exist in layer and the configuration that
# indicates should algorithm use only selected features or all
# of them
features = vector.features(vectorLayer)
features = QgsProcessingUtils.getFeatures(vectorLayer, context)
for f in features:
writer.addFeature(f)

@@ -58,7 +58,7 @@ def svgIconPath(self):
def getCustomParametersDialog(self):
return GdalAlgorithmDialog(self)

def processAlgorithm(self, feedback):
def processAlgorithm(self, context, feedback):
commands = self.getConsoleCommands()
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
supported = QgsVectorFileWriter.supportedFormatExtensions()
@@ -64,7 +64,7 @@ def defineCharacteristics(self):
def getConsoleCommands(self):
return ["extractprojection"]

def processAlgorithm(self, feedback):
def processAlgorithm(self, context, feedback):
rasterPath = self.getParameterValue(self.INPUT)
createPrj = self.getParameterValue(self.PRJ_FILE)

@@ -77,7 +77,7 @@ def getConsoleCommands(self):
arguments.append(self.getParameterValue(information.INPUT))
return ['gdalinfo', GdalUtils.escapeAndJoin(arguments)]

def processAlgorithm(self, feedback):
def processAlgorithm(self, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(), feedback)
output = self.getOutputValue(information.OUTPUT)
with open(output, 'w') as f:
@@ -125,9 +125,9 @@ def defineCharacteristics(self):
self.addParameter(ParameterString(self.OPTIONS,
self.tr('Additional creation options'), '', optional=True))

def processAlgorithm(self, feedback):
def processAlgorithm(self, context, feedback):
self.processing = True
GdalAlgorithm.processAlgorithm(self, feedback)
GdalAlgorithm.processAlgorithm(self, context, feedback)
self.processing = False

def getConsoleCommands(self):
@@ -177,9 +177,9 @@ def defineCharacteristics(self):
self.addParameter(ParameterString(self.OPTIONS,
self.tr('Additional creation options'), '', optional=True))

def processAlgorithm(self, feedback):
def processAlgorithm(self, context, feedback):
self.processing = True
GdalAlgorithm.processAlgorithm(self, feedback)
GdalAlgorithm.processAlgorithm(None, self)
self.processing = False

def getConsoleCommands(self):
@@ -70,7 +70,7 @@ def getConsoleCommands(self):
arguments.append(conn)
return arguments

def processAlgorithm(self, feedback):
def processAlgorithm(self, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(), feedback)
output = self.getOutputValue(self.OUTPUT)
with open(output, 'w') as f:
@@ -247,7 +247,7 @@ def getDefaultCellsize(self):
cellsize = 100
return cellsize

def processAlgorithm(self, feedback):
def processAlgorithm(self, context, feedback):
if system.isWindows():
path = Grass7Utils.grassPath()
if path == '':
@@ -92,7 +92,7 @@ def defineCharacteristics(self):
self.tr('GRASS region cellsize (leave 0 for default)'),
0, None, 0.0))

def processAlgorithm(self, feedback):
def processAlgorithm(self, context, feedback):
commands = []
vector = self.getParameterValue(self.VECTOR)
elevation = self.getParameterValue(self.ELEVATION)
@@ -28,7 +28,8 @@
from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsField,
QgsFeature,
QgsApplication)
QgsApplication,
QgsProcessingUtils)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterString
@@ -83,7 +84,7 @@ def defineCharacteristics(self):
self.addOutput(OutputVector(
self.OUTPUT_LAYER, self.tr('Added')))

def processAlgorithm(self, feedback):
def processAlgorithm(self, context, feedback):
fieldType = self.getParameterValue(self.FIELD_TYPE)
fieldName = self.getParameterValue(self.FIELD_NAME)
fieldLength = self.getParameterValue(self.FIELD_LENGTH)
@@ -99,8 +100,8 @@ def processAlgorithm(self, feedback):
writer = output.getVectorWriter(fields, layer.wkbType(),
layer.crs())
outFeat = QgsFeature()
features = vector.features(layer)
total = 100.0 / len(features)
features = QgsProcessingUtils.getFeatures(layer, context)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
for current, feat in enumerate(features):
feedback.setProgress(int(current * total))
geom = feat.geometry()
@@ -66,7 +66,7 @@ def defineCharacteristics(self):
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
self.tr('Aspect')))

def processAlgorithm(self, feedback):
def processAlgorithm(self, context, feedback):
inputFile = self.getParameterValue(self.INPUT_LAYER)
zFactor = self.getParameterValue(self.Z_FACTOR)
outputFile = self.getOutputValue(self.OUTPUT_LAYER)
@@ -28,7 +28,8 @@
from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsField,
QgsFeature,
QgsApplication)
QgsApplication,
QgsProcessingUtils)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
@@ -60,7 +61,7 @@ def defineCharacteristics(self):
self.tr('Input layer')))
self.addOutput(OutputVector(self.OUTPUT, self.tr('Incremented')))

def processAlgorithm(self, feedback):
def processAlgorithm(self, context, feedback):
output = self.getOutputFromName(self.OUTPUT)
vlayer = \
dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
@@ -69,8 +70,8 @@ def processAlgorithm(self, feedback):
writer = output.getVectorWriter(fields, vlayer.wkbType(),
vlayer.crs())
outFeat = QgsFeature()
features = vector.features(vlayer)
total = 100.0 / len(features)
features = QgsProcessingUtils.getFeatures(vlayer, context)
total = 100.0 / QgsProcessingUtils.featureCount(vlayer, context)
for current, feat in enumerate(features):
feedback.setProgress(int(current * total))
geom = feat.geometry()
@@ -73,15 +73,15 @@ def defineCharacteristics(self):

self.addOutput(OutputHTML(self.OUTPUT, self.tr('Bar plot')))

def processAlgorithm(self, feedback):
def processAlgorithm(self, context, feedback):
layer = dataobjects.getLayerFromString(
self.getParameterValue(self.INPUT))
namefieldname = self.getParameterValue(self.NAME_FIELD)
valuefieldname = self.getParameterValue(self.VALUE_FIELD)

output = self.getOutputValue(self.OUTPUT)

values = vector.values(layer, valuefieldname)
values = vector.values(layer, context, valuefieldname)

x_var = [i[namefieldname] for i in layer.getFeatures()]

Loading

0 comments on commit 5169e0d

Please sign in to comment.