mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Merge pull request #4412 from nyalldawson/processing_get_features
Port processing vector.features to c++
This commit is contained in:
commit
5169e0db65
@ -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
|
||||
|
127
python/core/processing/qgsprocessingcontext.sip
Normal file
127
python/core/processing/qgsprocessingcontext.sip
Normal file
@ -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 @@ __copyright__ = '(C) 2013, Victor Olaya'
|
||||
|
||||
__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 @@ class ExampleAlgorithm(GeoAlgorithm):
|
||||
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 @@ class ExampleAlgorithm(GeoAlgorithm):
|
||||
# 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 @@ class GdalAlgorithm(GeoAlgorithm):
|
||||
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 @@ class ExtractProjection(GdalAlgorithm):
|
||||
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 @@ class information(GdalAlgorithm):
|
||||
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 @@ class Ogr2OgrTableToPostGisList(GdalAlgorithm):
|
||||
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 @@ class Ogr2OgrToPostGisList(GdalAlgorithm):
|
||||
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 @@ class OgrInfo(GdalAlgorithm):
|
||||
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 @@ class Grass7Algorithm(GeoAlgorithm):
|
||||
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 @@ class nviz7(GeoAlgorithm):
|
||||
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 @@ __revision__ = '$Format:%H$'
|
||||
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 @@ class AddTableField(GeoAlgorithm):
|
||||
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 @@ class AddTableField(GeoAlgorithm):
|
||||
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 @@ class Aspect(GeoAlgorithm):
|
||||
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 @@ __revision__ = '$Format:%H$'
|
||||
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 @@ class AutoincrementalField(GeoAlgorithm):
|
||||
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 @@ class AutoincrementalField(GeoAlgorithm):
|
||||
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,7 +73,7 @@ class BarPlot(GeoAlgorithm):
|
||||
|
||||
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)
|
||||
@ -81,7 +81,7 @@ class BarPlot(GeoAlgorithm):
|
||||
|
||||
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()]
|
||||
|
||||
|
@ -34,7 +34,8 @@ from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.core import (QgsStatisticalSummary,
|
||||
QgsStringStatisticalSummary,
|
||||
QgsDateTimeStatisticalSummary,
|
||||
QgsFeatureRequest)
|
||||
QgsFeatureRequest,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterTable
|
||||
@ -120,7 +121,7 @@ class BasicStatisticsForField(GeoAlgorithm):
|
||||
self.addOutput(OutputNumber(self.THIRDQUARTILE, self.tr('Third quartile')))
|
||||
self.addOutput(OutputNumber(self.IQR, self.tr('Interquartile Range (IQR)')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
field_name = self.getParameterValue(self.FIELD_NAME)
|
||||
@ -129,23 +130,23 @@ class BasicStatisticsForField(GeoAlgorithm):
|
||||
output_file = self.getOutputValue(self.OUTPUT_HTML_FILE)
|
||||
|
||||
request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry).setSubsetOfAttributes([field_name], layer.fields())
|
||||
features = vector.features(layer, request)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context, request)
|
||||
count = QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
data = []
|
||||
data.append(self.tr('Analyzed layer: {}').format(layer.name()))
|
||||
data.append(self.tr('Analyzed field: {}').format(field_name))
|
||||
|
||||
if field.isNumeric():
|
||||
data.extend(self.calcNumericStats(features, feedback, field))
|
||||
data.extend(self.calcNumericStats(features, feedback, field, count))
|
||||
elif field.type() in (QVariant.Date, QVariant.Time, QVariant.DateTime):
|
||||
data.extend(self.calcDateTimeStats(features, feedback, field))
|
||||
data.extend(self.calcDateTimeStats(features, feedback, field, count))
|
||||
else:
|
||||
data.extend(self.calcStringStats(features, feedback, field))
|
||||
data.extend(self.calcStringStats(features, feedback, field, count))
|
||||
|
||||
self.createHTML(output_file, data)
|
||||
|
||||
def calcNumericStats(self, features, feedback, field):
|
||||
count = len(features)
|
||||
def calcNumericStats(self, features, feedback, field, count):
|
||||
total = 100.0 / float(count)
|
||||
stat = QgsStatisticalSummary()
|
||||
for current, ft in enumerate(features):
|
||||
@ -192,8 +193,7 @@ class BasicStatisticsForField(GeoAlgorithm):
|
||||
data.append(self.tr('Interquartile Range (IQR): {}').format(stat.interQuartileRange()))
|
||||
return data
|
||||
|
||||
def calcStringStats(self, features, feedback, field):
|
||||
count = len(features)
|
||||
def calcStringStats(self, features, feedback, field, count):
|
||||
total = 100.0 / float(count)
|
||||
stat = QgsStringStatisticalSummary()
|
||||
for current, ft in enumerate(features):
|
||||
@ -223,8 +223,7 @@ class BasicStatisticsForField(GeoAlgorithm):
|
||||
|
||||
return data
|
||||
|
||||
def calcDateTimeStats(self, features, feedback, field):
|
||||
count = len(features)
|
||||
def calcDateTimeStats(self, features, feedback, field, count):
|
||||
total = 100.0 / float(count)
|
||||
stat = QgsDateTimeStatisticalSummary()
|
||||
for current, ft in enumerate(features):
|
||||
|
@ -33,7 +33,8 @@ from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import (QgsStatisticalSummary,
|
||||
QgsFeatureRequest,
|
||||
QgsProcessingAlgorithm)
|
||||
QgsProcessingAlgorithm,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterTable
|
||||
@ -114,7 +115,7 @@ class BasicStatisticsNumbers(GeoAlgorithm):
|
||||
self.addOutput(OutputNumber(self.NULLVALUES, self.tr('NULL (missed) values')))
|
||||
self.addOutput(OutputNumber(self.IQR, self.tr('Interquartile Range (IQR)')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
fieldName = self.getParameterValue(self.FIELD_NAME)
|
||||
@ -123,8 +124,8 @@ class BasicStatisticsNumbers(GeoAlgorithm):
|
||||
|
||||
request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry).setSubsetOfAttributes([fieldName], layer.fields())
|
||||
stat = QgsStatisticalSummary()
|
||||
features = vector.features(layer, request)
|
||||
count = len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context, request)
|
||||
count = QgsProcessingUtils.featureCount(layer, context)
|
||||
total = 100.0 / float(count)
|
||||
for current, ft in enumerate(features):
|
||||
stat.addVariant(ft[fieldName])
|
||||
|
@ -33,7 +33,8 @@ from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import (QgsProcessingAlgorithm,
|
||||
QgsStringStatisticalSummary,
|
||||
QgsFeatureRequest)
|
||||
QgsFeatureRequest,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterTable
|
||||
@ -100,7 +101,7 @@ class BasicStatisticsStrings(GeoAlgorithm):
|
||||
self.addOutput(OutputNumber(self.MIN_VALUE, self.tr('Minimum string value')))
|
||||
self.addOutput(OutputNumber(self.MAX_VALUE, self.tr('Maximum string value')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
fieldName = self.getParameterValue(self.FIELD_NAME)
|
||||
@ -110,8 +111,8 @@ class BasicStatisticsStrings(GeoAlgorithm):
|
||||
request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry).setSubsetOfAttributes([fieldName],
|
||||
layer.fields())
|
||||
stat = QgsStringStatisticalSummary()
|
||||
features = vector.features(layer, request)
|
||||
count = len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context, request)
|
||||
count = QgsProcessingUtils.featureCount(layer, context)
|
||||
total = 100.0 / float(count)
|
||||
for current, ft in enumerate(features):
|
||||
stat.addValue(ft[fieldName])
|
||||
|
@ -27,7 +27,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
|
||||
from qgis.core import QgsGeometry, QgsWkbTypes
|
||||
from qgis.core import QgsGeometry, QgsWkbTypes, QgsProcessingUtils
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
@ -63,7 +63,7 @@ class Boundary(GeoAlgorithm):
|
||||
dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Boundary')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
@ -83,8 +83,8 @@ class Boundary(GeoAlgorithm):
|
||||
output_wkb,
|
||||
layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, input_feature in enumerate(features):
|
||||
output_feature = input_feature
|
||||
|
@ -27,7 +27,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
|
||||
from qgis.core import QgsGeometry, QgsWkbTypes
|
||||
from qgis.core import QgsGeometry, QgsWkbTypes, QgsProcessingUtils
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
@ -62,7 +62,7 @@ class BoundingBox(GeoAlgorithm):
|
||||
self.tr('Input layer')))
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Bounds'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
@ -72,8 +72,8 @@ class BoundingBox(GeoAlgorithm):
|
||||
QgsWkbTypes.Polygon,
|
||||
layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, input_feature in enumerate(features):
|
||||
output_feature = input_feature
|
||||
|
@ -82,7 +82,7 @@ class BoxPlot(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputHTML(self.OUTPUT, self.tr('Box plot')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
namefieldname = self.getParameterValue(self.NAME_FIELD)
|
||||
@ -90,7 +90,7 @@ class BoxPlot(GeoAlgorithm):
|
||||
|
||||
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()]
|
||||
|
||||
|
@ -25,13 +25,13 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.core import QgsFeature, QgsGeometry
|
||||
from qgis.core import QgsFeature, QgsGeometry, QgsProcessingUtils
|
||||
|
||||
from processing.tools import vector
|
||||
|
||||
|
||||
def buffering(feedback, writer, distance, field, useField, layer, dissolve,
|
||||
segments, endCapStyle=1, joinStyle=1, mitreLimit=2):
|
||||
def buffering(feedback, context, writer, distance, field, useField, layer, dissolve, segments, endCapStyle=1,
|
||||
joinStyle=1, mitreLimit=2):
|
||||
|
||||
if useField:
|
||||
field = layer.fields().lookupField(field)
|
||||
@ -39,8 +39,8 @@ def buffering(feedback, writer, distance, field, useField, layer, dissolve,
|
||||
outFeat = QgsFeature()
|
||||
|
||||
current = 0
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / float(len(features))
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
# With dissolve
|
||||
if dissolve:
|
||||
|
@ -29,7 +29,7 @@ import os
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import QgsWkbTypes
|
||||
from qgis.core import QgsWkbTypes, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
@ -63,7 +63,7 @@ class Centroids(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Centroids'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
@ -73,8 +73,8 @@ class Centroids(GeoAlgorithm):
|
||||
QgsWkbTypes.Point,
|
||||
layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, input_feature in enumerate(features):
|
||||
output_feature = input_feature
|
||||
if input_feature.geometry():
|
||||
|
@ -30,7 +30,7 @@ import os
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
|
||||
from qgis.core import QgsSettings, QgsGeometry, QgsFeature, QgsField, QgsWkbTypes
|
||||
from qgis.core import QgsSettings, QgsGeometry, QgsFeature, QgsField, QgsWkbTypes, QgsProcessingUtils
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
from processing.core.parameters import ParameterSelection
|
||||
@ -87,7 +87,7 @@ class CheckValidity(GeoAlgorithm):
|
||||
self.ERROR_OUTPUT,
|
||||
self.tr('Error output')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
settings = QgsSettings()
|
||||
initial_method_setting = settings.value(settings_method_key, 1)
|
||||
|
||||
@ -95,11 +95,11 @@ class CheckValidity(GeoAlgorithm):
|
||||
if method != 0:
|
||||
settings.setValue(settings_method_key, method)
|
||||
try:
|
||||
self.doCheck(feedback)
|
||||
self.doCheck(context, feedback)
|
||||
finally:
|
||||
settings.setValue(settings_method_key, initial_method_setting)
|
||||
|
||||
def doCheck(self, feedback):
|
||||
def doCheck(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
@ -136,8 +136,8 @@ class CheckValidity(GeoAlgorithm):
|
||||
layer.crs())
|
||||
error_count = 0
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, inFeat in enumerate(features):
|
||||
geom = inFeat.geometry()
|
||||
attrs = inFeat.attributes()
|
||||
|
@ -29,7 +29,7 @@ import os
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import QgsFeature, QgsGeometry, QgsFeatureRequest, QgsWkbTypes
|
||||
from qgis.core import QgsFeature, QgsGeometry, QgsFeatureRequest, QgsWkbTypes, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
@ -65,7 +65,7 @@ class Clip(GeoAlgorithm):
|
||||
self.tr('Clip layer'), [dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
self.addOutput(OutputVector(Clip.OUTPUT, self.tr('Clipped')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
source_layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(Clip.INPUT))
|
||||
mask_layer = dataobjects.getLayerFromString(
|
||||
@ -78,7 +78,7 @@ class Clip(GeoAlgorithm):
|
||||
|
||||
# first build up a list of clip geometries
|
||||
clip_geoms = []
|
||||
for maskFeat in vector.features(mask_layer, QgsFeatureRequest().setSubsetOfAttributes([])):
|
||||
for maskFeat in QgsProcessingUtils.getFeatures(mask_layer, context, QgsFeatureRequest().setSubsetOfAttributes([])):
|
||||
clip_geoms.append(maskFeat.geometry())
|
||||
|
||||
# are we clipping against a single feature? if so, we can show finer progress reports
|
||||
@ -96,7 +96,8 @@ class Clip(GeoAlgorithm):
|
||||
tested_feature_ids = set()
|
||||
|
||||
for i, clip_geom in enumerate(clip_geoms):
|
||||
input_features = [f for f in vector.features(source_layer, QgsFeatureRequest().setFilterRect(clip_geom.boundingBox()))]
|
||||
input_features = [f for f in QgsProcessingUtils.getFeatures(source_layer, context,
|
||||
QgsFeatureRequest().setFilterRect(clip_geom.boundingBox()))]
|
||||
|
||||
if not input_features:
|
||||
continue
|
||||
|
@ -78,7 +78,7 @@ class ConcaveHull(GeoAlgorithm):
|
||||
self.addOutput(
|
||||
OutputVector(ConcaveHull.OUTPUT, self.tr('Concave hull'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(ConcaveHull.INPUT))
|
||||
alpha = self.getParameterValue(self.ALPHA)
|
||||
holes = self.getParameterValue(self.HOLES)
|
||||
|
@ -31,7 +31,7 @@ import os
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
|
||||
from qgis.core import QgsField, QgsFeature, QgsGeometry, QgsWkbTypes
|
||||
from qgis.core import QgsField, QgsFeature, QgsGeometry, QgsWkbTypes, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
@ -76,7 +76,7 @@ class ConvexHull(GeoAlgorithm):
|
||||
self.tr('Method'), self.methods))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Convex hull'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
useField = self.getParameterValue(self.METHOD) == 1
|
||||
@ -112,15 +112,15 @@ class ConvexHull(GeoAlgorithm):
|
||||
|
||||
fid = 0
|
||||
val = None
|
||||
features = vector.features(layer)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
if useField:
|
||||
unique = layer.uniqueValues(index)
|
||||
current = 0
|
||||
total = 100.0 / (len(features) * len(unique))
|
||||
total = 100.0 / (QgsProcessingUtils.featureCount(layer, context) * len(unique))
|
||||
for i in unique:
|
||||
first = True
|
||||
hull = []
|
||||
features = vector.features(layer)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
for f in features:
|
||||
idVar = f[fieldName]
|
||||
if str(idVar).strip() == str(i).strip():
|
||||
@ -149,7 +149,7 @@ class ConvexHull(GeoAlgorithm):
|
||||
else:
|
||||
hull = []
|
||||
total = 100.0 / layer.featureCount()
|
||||
features = vector.features(layer)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
for current, f in enumerate(features):
|
||||
inGeom = f.geometry()
|
||||
points = vector.extractPoints(inGeom)
|
||||
|
@ -66,7 +66,7 @@ class CreateAttributeIndex(GeoAlgorithm):
|
||||
self.addOutput(OutputVector(self.OUTPUT,
|
||||
self.tr('Indexed layer'), True))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
file_name = self.getParameterValue(self.INPUT)
|
||||
layer = dataobjects.getLayerFromString(file_name)
|
||||
field = self.getParameterValue(self.FIELD)
|
||||
|
@ -67,7 +67,7 @@ class CreateConstantRaster(GeoAlgorithm):
|
||||
self.addOutput(OutputRaster(self.OUTPUT,
|
||||
self.tr('Constant')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
value = self.getParameterValue(self.NUMBER)
|
||||
|
@ -76,7 +76,7 @@ class Datasources2Vrt(GeoAlgorithm):
|
||||
self.addOutput(OutputString(self.VRT_STRING,
|
||||
self.tr('Virtual string')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
input_layers = self.getParameterValue(self.DATASOURCES)
|
||||
unioned = self.getParameterValue(self.UNIONED)
|
||||
vrtPath = self.getOutputValue(self.VRT_FILE)
|
||||
|
@ -73,7 +73,7 @@ class DefineProjection(GeoAlgorithm):
|
||||
self.addOutput(OutputVector(self.OUTPUT,
|
||||
self.tr('Layer with projection'), True))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
fileName = self.getParameterValue(self.INPUT)
|
||||
layer = dataobjects.getLayerFromString(fileName)
|
||||
crs = QgsCoordinateReferenceSystem(self.getParameterValue(self.CRS))
|
||||
|
@ -31,7 +31,7 @@ import os
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
|
||||
from qgis.core import QgsField, QgsFeatureRequest, QgsFeature, QgsGeometry, QgsPoint, QgsWkbTypes
|
||||
from qgis.core import QgsField, QgsFeatureRequest, QgsFeature, QgsGeometry, QgsPoint, QgsWkbTypes, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
@ -69,7 +69,7 @@ class Delaunay(GeoAlgorithm):
|
||||
self.tr('Delaunay triangulation'),
|
||||
datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
|
||||
@ -84,8 +84,8 @@ class Delaunay(GeoAlgorithm):
|
||||
ptDict = {}
|
||||
ptNdx = -1
|
||||
c = voronoi.Context()
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, inFeat in enumerate(features):
|
||||
geom = QgsGeometry(inFeat.geometry())
|
||||
if geom.isNull():
|
||||
|
@ -25,7 +25,8 @@ __copyright__ = '(C) 2010, Michael Minn'
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.core import (QgsApplication)
|
||||
from qgis.core import (QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
from processing.core.parameters import ParameterTableField
|
||||
@ -64,7 +65,7 @@ class DeleteColumn(GeoAlgorithm):
|
||||
self.tr('Fields to delete'), self.INPUT, multiple=True))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Output layer')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
|
||||
|
||||
fields_to_delete = self.getParameterValue(self.COLUMNS).split(';')
|
||||
@ -85,8 +86,8 @@ class DeleteColumn(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
|
||||
layer.wkbType(), layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, f in enumerate(features):
|
||||
attributes = f.attributes()
|
||||
|
@ -26,7 +26,8 @@ __copyright__ = '(C) 2010, Michael Minn'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.core import (QgsFeatureRequest,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
from processing.core.outputs import OutputVector
|
||||
@ -58,7 +59,7 @@ class DeleteDuplicateGeometries(GeoAlgorithm):
|
||||
self.tr('Input layer')))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Cleaned')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
|
||||
@ -67,9 +68,9 @@ class DeleteDuplicateGeometries(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
|
||||
layer.wkbType(), layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
|
||||
total = 100.0 / len(features)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
geoms = dict()
|
||||
for current, f in enumerate(features):
|
||||
geoms[f.id()] = f.geometry()
|
||||
|
@ -24,7 +24,8 @@ __copyright__ = '(C) 2015, Etienne Trimaille'
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.core import (QgsApplication)
|
||||
from qgis.core import (QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import (ParameterVector,
|
||||
ParameterNumber)
|
||||
@ -64,7 +65,7 @@ class DeleteHoles(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Cleaned'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
min_area = self.getParameterValue(self.MIN_AREA)
|
||||
@ -81,8 +82,8 @@ class DeleteHoles(GeoAlgorithm):
|
||||
layer.wkbType(),
|
||||
layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, f in enumerate(features):
|
||||
if f.hasGeometry():
|
||||
|
@ -31,7 +31,8 @@ import os
|
||||
from qgis.core import (QgsGeometry,
|
||||
QgsPoint,
|
||||
QgsWkbTypes,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -76,7 +77,7 @@ class DensifyGeometries(GeoAlgorithm):
|
||||
self.addOutput(OutputVector(self.OUTPUT,
|
||||
self.tr('Densified')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
vertices = self.getParameterValue(self.VERTICES)
|
||||
@ -87,8 +88,8 @@ class DensifyGeometries(GeoAlgorithm):
|
||||
self.OUTPUT).getVectorWriter(layer.fields().toList(),
|
||||
layer.wkbType(), layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, f in enumerate(features):
|
||||
feature = f
|
||||
if feature.hasGeometry():
|
||||
|
@ -32,7 +32,8 @@ from math import sqrt
|
||||
from qgis.core import (QgsPoint,
|
||||
QgsGeometry,
|
||||
QgsWkbTypes,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -71,7 +72,7 @@ class DensifyGeometriesInterval(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Densified')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
|
||||
interval = self.getParameterValue(self.INTERVAL)
|
||||
|
||||
@ -81,8 +82,8 @@ class DensifyGeometriesInterval(GeoAlgorithm):
|
||||
self.OUTPUT).getVectorWriter(layer.fields().toList(),
|
||||
layer.wkbType(), layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, f in enumerate(features):
|
||||
feature = f
|
||||
if feature.hasGeometry():
|
||||
|
@ -29,7 +29,7 @@ import os
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry, QgsWkbTypes
|
||||
from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry, QgsWkbTypes, QgsProcessingUtils
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -65,7 +65,7 @@ class Difference(GeoAlgorithm):
|
||||
self.tr('Difference layer')))
|
||||
self.addOutput(OutputVector(Difference.OUTPUT, self.tr('Difference')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layerA = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(Difference.INPUT))
|
||||
layerB = dataobjects.getLayerFromString(
|
||||
@ -79,8 +79,8 @@ class Difference(GeoAlgorithm):
|
||||
|
||||
outFeat = QgsFeature()
|
||||
index = vector.spatialindex(layerB)
|
||||
selectionA = vector.features(layerA)
|
||||
total = 100.0 / len(selectionA)
|
||||
selectionA = QgsProcessingUtils.getFeatures(layerA, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layerA, context)
|
||||
for current, inFeatA in enumerate(selectionA):
|
||||
geom = inFeatA.geometry()
|
||||
diff_geom = QgsGeometry(geom)
|
||||
|
@ -30,7 +30,7 @@ from collections import defaultdict
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import QgsFeature, QgsGeometry
|
||||
from qgis.core import QgsFeature, QgsGeometry, QgsProcessingUtils
|
||||
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
@ -73,7 +73,7 @@ class Dissolve(GeoAlgorithm):
|
||||
self.tr('Unique ID fields'), Dissolve.INPUT, optional=True, multiple=True))
|
||||
self.addOutput(OutputVector(Dissolve.OUTPUT, self.tr('Dissolved')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
useField = not self.getParameterValue(Dissolve.DISSOLVE_ALL)
|
||||
field_names = self.getParameterValue(Dissolve.FIELD)
|
||||
vlayerA = dataobjects.getLayerFromString(
|
||||
@ -86,8 +86,8 @@ class Dissolve(GeoAlgorithm):
|
||||
vlayerA.crs())
|
||||
|
||||
outFeat = QgsFeature()
|
||||
features = vector.features(vlayerA)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(vlayerA, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(vlayerA, context)
|
||||
|
||||
if not useField:
|
||||
first = True
|
||||
|
@ -28,7 +28,8 @@ __revision__ = '$Format:%H$'
|
||||
from qgis.core import (QgsFeatureRequest,
|
||||
QgsWkbTypes,
|
||||
QgsCoordinateReferenceSystem,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
from processing.core.outputs import OutputVector
|
||||
@ -65,7 +66,7 @@ class DropGeometry(GeoAlgorithm):
|
||||
dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
self.addOutput(OutputVector(self.OUTPUT_TABLE, self.tr('Dropped geometry')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
writer = self.getOutputFromName(
|
||||
@ -75,8 +76,8 @@ class DropGeometry(GeoAlgorithm):
|
||||
QgsCoordinateReferenceSystem())
|
||||
|
||||
request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry)
|
||||
features = vector.features(layer, request)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context, request)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, input_feature in enumerate(features):
|
||||
writer.addFeature(input_feature)
|
||||
|
@ -77,7 +77,7 @@ class EliminateSelection(GeoAlgorithm):
|
||||
self.modes))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Eliminated'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
inLayer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
|
||||
boundary = self.getParameterValue(self.MODE) == self.MODE_BOUNDARY
|
||||
smallestArea = self.getParameterValue(self.MODE) == self.MODE_SMALLEST_AREA
|
||||
|
@ -28,7 +28,8 @@ __revision__ = '$Format:%H$'
|
||||
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 ParameterTableField
|
||||
@ -64,7 +65,7 @@ class EquivalentNumField(GeoAlgorithm):
|
||||
self.tr('Class field'), self.INPUT))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Layer with index field')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
fieldname = self.getParameterValue(self.FIELD)
|
||||
output = self.getOutputFromName(self.OUTPUT)
|
||||
vlayer = dataobjects.getLayerFromString(
|
||||
@ -77,8 +78,8 @@ class EquivalentNumField(GeoAlgorithm):
|
||||
outFeat = QgsFeature()
|
||||
classes = {}
|
||||
|
||||
features = vector.features(vlayer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(vlayer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(vlayer, context)
|
||||
for current, feature in enumerate(features):
|
||||
feedback.setProgress(int(current * total))
|
||||
inGeom = feature.geometry()
|
||||
|
@ -30,7 +30,8 @@ from qgis.core import (QgsFeature,
|
||||
QgsVectorLayer,
|
||||
QgsCoordinateReferenceSystem,
|
||||
QgsWkbTypes,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
@ -103,7 +104,7 @@ class ExecuteSQL(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('SQL Output')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layers = self.getParameterValue(self.INPUT_DATASOURCES)
|
||||
query = self.getParameterValue(self.INPUT_QUERY)
|
||||
uid_field = self.getParameterValue(self.INPUT_UID_FIELD)
|
||||
@ -151,8 +152,8 @@ class ExecuteSQL(GeoAlgorithm):
|
||||
vLayer.wkbType() if geometry_type != 1 else 1,
|
||||
vLayer.crs())
|
||||
|
||||
features = vector.features(vLayer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(vLayer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(vLayer, context)
|
||||
outFeat = QgsFeature()
|
||||
for current, inFeat in enumerate(features):
|
||||
outFeat.setAttributes(inFeat.attributes())
|
||||
|
@ -29,7 +29,8 @@ __revision__ = '$Format:%H$'
|
||||
from qgis.core import (QgsFeature,
|
||||
QgsGeometry,
|
||||
QgsWkbTypes,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
from processing.core.outputs import OutputVector
|
||||
@ -62,7 +63,7 @@ class Explode(GeoAlgorithm):
|
||||
[dataobjects.TYPE_VECTOR_LINE]))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Exploded'), datatype=[dataobjects.TYPE_VECTOR_LINE]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
vlayer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
output = self.getOutputFromName(self.OUTPUT)
|
||||
@ -70,8 +71,8 @@ class Explode(GeoAlgorithm):
|
||||
writer = output.getVectorWriter(fields, QgsWkbTypes.LineString,
|
||||
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, feature in enumerate(features):
|
||||
feedback.setProgress(int(current * total))
|
||||
inGeom = feature.geometry()
|
||||
|
@ -30,7 +30,7 @@ import os
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
|
||||
from qgis.core import QgsProject, QgsCoordinateTransform, QgsFeature, QgsField, QgsWkbTypes
|
||||
from qgis.core import QgsProject, QgsCoordinateTransform, QgsFeature, QgsField, QgsWkbTypes, QgsProcessingUtils
|
||||
from qgis.utils import iface
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
@ -75,7 +75,7 @@ class ExportGeometryInfo(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Added geom info')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
method = self.getParameterValue(self.METHOD)
|
||||
@ -132,8 +132,8 @@ class ExportGeometryInfo(GeoAlgorithm):
|
||||
outFeat.initAttributes(len(fields))
|
||||
outFeat.setFields(fields)
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, f in enumerate(features):
|
||||
inGeom = f.geometry()
|
||||
|
||||
|
@ -25,7 +25,8 @@ __copyright__ = '(C) 2016, Nyall Dawson'
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.core import (QgsApplication)
|
||||
from qgis.core import (QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.parameters import ParameterVector, ParameterNumber
|
||||
@ -65,7 +66,7 @@ class ExtendLines(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Extended lines')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
@ -78,8 +79,8 @@ class ExtendLines(GeoAlgorithm):
|
||||
start_distance = self.getParameterValue(self.START_DISTANCE)
|
||||
end_distance = self.getParameterValue(self.END_DISTANCE)
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, input_feature in enumerate(features):
|
||||
output_feature = input_feature
|
||||
|
@ -30,7 +30,7 @@ import os
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
|
||||
from qgis.core import QgsField, QgsPoint, QgsGeometry, QgsFeature, QgsWkbTypes
|
||||
from qgis.core import QgsField, QgsPoint, QgsGeometry, QgsFeature, QgsWkbTypes, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -71,7 +71,7 @@ class ExtentFromLayer(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Extent'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
byFeature = self.getParameterValue(self.BY_FEATURE)
|
||||
@ -93,7 +93,7 @@ class ExtentFromLayer(GeoAlgorithm):
|
||||
QgsWkbTypes.Polygon, layer.crs())
|
||||
|
||||
if byFeature:
|
||||
self.featureExtent(layer, writer, feedback)
|
||||
self.featureExtent(layer, context, writer, feedback)
|
||||
else:
|
||||
self.layerExtent(layer, writer, feedback)
|
||||
|
||||
@ -132,9 +132,9 @@ class ExtentFromLayer(GeoAlgorithm):
|
||||
feat.setAttributes(attrs)
|
||||
writer.addFeature(feat)
|
||||
|
||||
def featureExtent(self, layer, writer, feedback):
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
def featureExtent(self, layer, context, writer, feedback):
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
feat = QgsFeature()
|
||||
for current, f in enumerate(features):
|
||||
rect = f.geometry().boundingBox()
|
||||
|
@ -104,7 +104,7 @@ class ExtractByAttribute(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Extracted (attribute)')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
|
||||
fieldName = self.getParameterValue(self.FIELD)
|
||||
operator = self.OPERATORS[self.getParameterValue(self.OPERATOR)]
|
||||
|
@ -67,7 +67,7 @@ class ExtractByExpression(GeoAlgorithm):
|
||||
self.tr("Expression"), parent_layer=self.INPUT))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Extracted (expression)')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
|
||||
expression_string = self.getParameterValue(self.EXPRESSION)
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.fields(), layer.wkbType(), layer.crs())
|
||||
|
@ -26,7 +26,8 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.core import (QgsFeatureRequest,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
from processing.core.parameters import ParameterSelection
|
||||
@ -85,7 +86,7 @@ class ExtractByLocation(GeoAlgorithm):
|
||||
0.0, None, 0.0))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Extracted (location)')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
filename = self.getParameterValue(self.INPUT)
|
||||
layer = dataobjects.getLayerFromString(filename)
|
||||
filename = self.getParameterValue(self.INTERSECT)
|
||||
@ -101,12 +102,12 @@ class ExtractByLocation(GeoAlgorithm):
|
||||
|
||||
if 'disjoint' in predicates:
|
||||
disjoinSet = []
|
||||
for feat in vector.features(layer):
|
||||
for feat in QgsProcessingUtils.getFeatures(layer, context):
|
||||
disjoinSet.append(feat.id())
|
||||
|
||||
selectedSet = []
|
||||
features = vector.features(selectLayer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(selectLayer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(selectLayer, context)
|
||||
for current, f in enumerate(features):
|
||||
geom = vector.snapToPrecision(f.geometry(), precision)
|
||||
bbox = vector.bufferedBoundingBox(geom.boundingBox(), 0.51 * precision)
|
||||
@ -133,8 +134,8 @@ class ExtractByLocation(GeoAlgorithm):
|
||||
if 'disjoint' in predicates:
|
||||
selectedSet = selectedSet + disjoinSet
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, f in enumerate(features):
|
||||
if f.id() in selectedSet:
|
||||
writer.addFeature(f)
|
||||
|
@ -31,7 +31,7 @@ import math
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
|
||||
from qgis.core import QgsFeature, QgsGeometry, QgsWkbTypes, QgsField
|
||||
from qgis.core import QgsFeature, QgsGeometry, QgsWkbTypes, QgsField, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -66,7 +66,7 @@ class ExtractNodes(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Nodes'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
|
||||
@ -78,8 +78,8 @@ class ExtractNodes(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
|
||||
fields, QgsWkbTypes.Point, layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, f in enumerate(features):
|
||||
input_geometry = f.geometry()
|
||||
if not input_geometry:
|
||||
|
@ -36,7 +36,8 @@ from qgis.core import (QgsWkbTypes,
|
||||
QgsFeature,
|
||||
QgsGeometry,
|
||||
QgsField,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
|
||||
|
||||
@ -68,7 +69,7 @@ class ExtractSpecificNodes(GeoAlgorithm):
|
||||
self.tr('Node indices'), default='0'))
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Nodes'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
@ -93,8 +94,8 @@ class ExtractSpecificNodes(GeoAlgorithm):
|
||||
raise GeoAlgorithmExecutionException(
|
||||
self.tr('\'{}\' is not a valid node index').format(node))
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, f in enumerate(features):
|
||||
|
||||
|
@ -31,7 +31,8 @@ import sys
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
from qgis.core import (QgsFeature,
|
||||
QgsField,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -92,7 +93,7 @@ class FieldsPyculator(GeoAlgorithm):
|
||||
self.tr('Formula'), 'value = ', multiline=True))
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Calculated')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
fieldName = self.getParameterValue(self.FIELD_NAME)
|
||||
fieldType = self.getParameterValue(self.FIELD_TYPE)
|
||||
fieldLength = self.getParameterValue(self.FIELD_LENGTH)
|
||||
@ -144,8 +145,8 @@ class FieldsPyculator(GeoAlgorithm):
|
||||
self.tr("FieldPyculator code execute error. Field code block can't be executed!\n{0}\n{1}").format(str(sys.exc_info()[0].__name__), str(sys.exc_info()[1])))
|
||||
|
||||
# Run
|
||||
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))
|
||||
attrs = feat.attributes()
|
||||
|
@ -34,7 +34,8 @@ from qgis.core import (QgsExpression,
|
||||
QgsDistanceArea,
|
||||
QgsProject,
|
||||
GEO_NONE,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -97,7 +98,7 @@ class FieldsCalculator(GeoAlgorithm):
|
||||
self.addParameter(ParameterString(self.FORMULA, self.tr('Formula')))
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Calculated')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT_LAYER))
|
||||
fieldName = self.getParameterValue(self.FIELD_NAME)
|
||||
fieldType = self.TYPES[self.getParameterValue(self.FIELD_TYPE)]
|
||||
@ -137,8 +138,8 @@ class FieldsCalculator(GeoAlgorithm):
|
||||
error = ''
|
||||
calculationSuccess = True
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
rownum = 1
|
||||
for current, f in enumerate(features):
|
||||
|
@ -34,7 +34,8 @@ from qgis.core import (QgsField,
|
||||
QgsProject,
|
||||
QgsFeature,
|
||||
GEO_NONE,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.parameters import ParameterTable
|
||||
@ -110,7 +111,7 @@ class FieldsMapper(GeoAlgorithm):
|
||||
self.tr('Refactored'),
|
||||
base_input=self.INPUT_LAYER))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = self.getParameterValue(self.INPUT_LAYER)
|
||||
mapping = self.getParameterValue(self.FIELDS_MAPPING)
|
||||
output = self.getOutputFromName(self.OUTPUT_LAYER)
|
||||
@ -151,9 +152,10 @@ class FieldsMapper(GeoAlgorithm):
|
||||
error_exp = None
|
||||
inFeat = QgsFeature()
|
||||
outFeat = QgsFeature()
|
||||
features = vector.features(layer)
|
||||
if len(features):
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
count = QgsProcessingUtils.featureCount(layer, context)
|
||||
if count > 0:
|
||||
total = 100.0 / count
|
||||
for current, inFeat in enumerate(features):
|
||||
rownum = current + 1
|
||||
|
||||
|
@ -82,7 +82,7 @@ class FindProjection(GeoAlgorithm):
|
||||
self.addOutput(OutputHTML(self.OUTPUT_HTML_FILE,
|
||||
self.tr('Candidates')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
|
@ -27,7 +27,8 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.core import (QgsWkbTypes,
|
||||
QgsGeometry,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -67,7 +68,7 @@ class FixGeometry(GeoAlgorithm):
|
||||
self.addOutput(OutputVector(self.OUTPUT,
|
||||
self.tr('Layer with fixed geometries')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
|
||||
@ -77,11 +78,11 @@ class FixGeometry(GeoAlgorithm):
|
||||
QgsWkbTypes.multiType(layer.wkbType()),
|
||||
layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
if len(features) == 0:
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
if QgsProcessingUtils.featureCount(layer, context) == 0:
|
||||
raise GeoAlgorithmExecutionException(self.tr('There are no features in the input layer'))
|
||||
|
||||
total = 100.0 / len(features)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, inputFeature in enumerate(features):
|
||||
outputFeature = inputFeature
|
||||
if inputFeature.geometry():
|
||||
|
@ -95,7 +95,7 @@ class FixedDistanceBuffer(GeoAlgorithm):
|
||||
self.tr('Mitre limit'), 1, default=2))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Buffer'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
|
||||
distance = self.getParameterValue(self.DISTANCE)
|
||||
dissolve = self.getParameterValue(self.DISSOLVE)
|
||||
@ -108,5 +108,5 @@ class FixedDistanceBuffer(GeoAlgorithm):
|
||||
self.OUTPUT).getVectorWriter(layer.fields().toList(),
|
||||
QgsWkbTypes.Polygon, layer.crs())
|
||||
|
||||
buff.buffering(feedback, writer, distance, None, False, layer,
|
||||
dissolve, segments, end_cap_style, join_style, miter_limit)
|
||||
buff.buffering(feedback, context, writer, distance, None, False, layer, dissolve, segments, end_cap_style,
|
||||
join_style, miter_limit)
|
||||
|
@ -30,7 +30,8 @@ from qgis.core import (QgsWkbTypes,
|
||||
QgsExpressionContext,
|
||||
QgsExpressionContextUtils,
|
||||
QgsGeometry,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
@ -84,7 +85,7 @@ class GeometryByExpression(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Modified geometry')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
@ -117,8 +118,8 @@ class GeometryByExpression(GeoAlgorithm):
|
||||
raise GeoAlgorithmExecutionException(
|
||||
self.tr('Evaluation error: {0}').format(expression.evalErrorString()))
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, input_feature in enumerate(features):
|
||||
output_feature = input_feature
|
||||
|
||||
|
@ -28,7 +28,8 @@ __revision__ = '$Format:%H$'
|
||||
from qgis.core import (QgsFeature,
|
||||
QgsGeometry,
|
||||
QgsWkbTypes,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -72,7 +73,7 @@ class GeometryConvert(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Converted')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
index = self.getParameterValue(self.TYPE)
|
||||
@ -95,8 +96,8 @@ class GeometryConvert(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
|
||||
layer.fields(), newType, layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, f in enumerate(features):
|
||||
geom = f.geometry()
|
||||
|
@ -88,7 +88,7 @@ class GridLine(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Grid'), datatype=[dataobjects.TYPE_VECTOR_LINE]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
extent = self.getParameterValue(self.EXTENT).split(',')
|
||||
hSpacing = self.getParameterValue(self.HSPACING)
|
||||
vSpacing = self.getParameterValue(self.VSPACING)
|
||||
|
@ -90,7 +90,7 @@ class GridPolygon(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Grid'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
idx = self.getParameterValue(self.TYPE)
|
||||
extent = self.getParameterValue(self.EXTENT).split(',')
|
||||
hSpacing = self.getParameterValue(self.HSPACING)
|
||||
|
@ -29,7 +29,8 @@ from qgis.core import (QgsGeometry,
|
||||
QgsFeature,
|
||||
QgsPoint,
|
||||
QgsWkbTypes,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
@ -71,7 +72,7 @@ class Gridify(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Snapped')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
|
||||
hSpacing = self.getParameterValue(self.HSPACING)
|
||||
vSpacing = self.getParameterValue(self.VSPACING)
|
||||
@ -83,8 +84,8 @@ class Gridify(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
|
||||
layer.fields(), layer.wkbType(), layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, f in enumerate(features):
|
||||
geom = f.geometry()
|
||||
|
@ -29,7 +29,7 @@ import os
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import QgsFeatureRequest
|
||||
from qgis.core import QgsFeatureRequest, QgsProcessingUtils
|
||||
from qgis.analysis import QgsKernelDensityEstimation
|
||||
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
@ -130,7 +130,7 @@ class Heatmap(GeoAlgorithm):
|
||||
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
|
||||
self.tr('Heatmap')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
@ -171,8 +171,8 @@ class Heatmap(GeoAlgorithm):
|
||||
|
||||
request = QgsFeatureRequest()
|
||||
request.setSubsetOfAttributes(attrs)
|
||||
features = vector.features(layer, request)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context, request)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, f in enumerate(features):
|
||||
if kde.addFeature(f) != QgsKernelDensityEstimation.Success:
|
||||
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
|
||||
|
@ -72,7 +72,7 @@ class Hillshade(GeoAlgorithm):
|
||||
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
|
||||
self.tr('Hillshade')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
inputFile = self.getParameterValue(self.INPUT_LAYER)
|
||||
zFactor = self.getParameterValue(self.Z_FACTOR)
|
||||
azimuth = self.getParameterValue(self.AZIMUTH)
|
||||
|
@ -34,7 +34,8 @@ from qgis.core import (QgsField,
|
||||
QgsFeatureRequest,
|
||||
QgsWkbTypes,
|
||||
QgsApplication,
|
||||
QgsProject)
|
||||
QgsProject,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -94,7 +95,7 @@ class HubDistanceLines(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Hub distance'), datatype=[dataobjects.TYPE_VECTOR_LINE]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layerPoints = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.POINTS))
|
||||
layerHubs = dataobjects.getLayerFromString(
|
||||
@ -121,8 +122,8 @@ class HubDistanceLines(GeoAlgorithm):
|
||||
distance.setEllipsoid(QgsProject.instance().ellipsoid())
|
||||
|
||||
# Scan source points, find nearest hub, and write to output file
|
||||
features = vector.features(layerPoints)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layerPoints, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layerPoints, context)
|
||||
for current, f in enumerate(features):
|
||||
src = f.geometry().boundingBox().center()
|
||||
|
||||
|
@ -34,7 +34,8 @@ from qgis.core import (QgsField,
|
||||
QgsFeatureRequest,
|
||||
QgsWkbTypes,
|
||||
QgsApplication,
|
||||
QgsProject)
|
||||
QgsProject,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -94,7 +95,7 @@ class HubDistancePoints(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Hub distance'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layerPoints = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.POINTS))
|
||||
layerHubs = dataobjects.getLayerFromString(
|
||||
@ -121,8 +122,8 @@ class HubDistancePoints(GeoAlgorithm):
|
||||
distance.setEllipsoid(QgsProject.instance().ellipsoid())
|
||||
|
||||
# Scan source points, find nearest hub, and write to output file
|
||||
features = vector.features(layerPoints)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layerPoints, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layerPoints, context)
|
||||
for current, f in enumerate(features):
|
||||
src = f.geometry().boundingBox().center()
|
||||
|
||||
|
@ -30,7 +30,8 @@ from qgis.core import (QgsFeature,
|
||||
QgsGeometry,
|
||||
QgsPoint,
|
||||
QgsWkbTypes,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -74,7 +75,7 @@ class HubLines(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Hub lines'), datatype=[dataobjects.TYPE_VECTOR_LINE]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layerHub = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.HUBS))
|
||||
layerSpoke = dataobjects.getLayerFromString(
|
||||
@ -90,9 +91,9 @@ class HubLines(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
|
||||
layerSpoke.fields(), QgsWkbTypes.LineString, layerSpoke.crs())
|
||||
|
||||
spokes = vector.features(layerSpoke)
|
||||
hubs = vector.features(layerHub)
|
||||
total = 100.0 / len(spokes)
|
||||
spokes = QgsProcessingUtils.getFeatures(layerSpoke, context)
|
||||
hubs = QgsProcessingUtils.getFeatures(layerHub, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layerSpoke, context)
|
||||
|
||||
for current, spokepoint in enumerate(spokes):
|
||||
p = spokepoint.geometry().boundingBox().center()
|
||||
|
@ -33,7 +33,8 @@ from osgeo import gdal, ogr, osr
|
||||
|
||||
from qgis.core import (QgsRectangle,
|
||||
QgsGeometry,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterRaster
|
||||
@ -81,7 +82,7 @@ class HypsometricCurves(GeoAlgorithm):
|
||||
self.addOutput(OutputDirectory(self.OUTPUT_DIRECTORY,
|
||||
self.tr('Hypsometric curves')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
rasterPath = self.getParameterValue(self.INPUT_DEM)
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.BOUNDARY_LAYER))
|
||||
@ -112,8 +113,8 @@ class HypsometricCurves(GeoAlgorithm):
|
||||
memVectorDriver = ogr.GetDriverByName('Memory')
|
||||
memRasterDriver = gdal.GetDriverByName('MEM')
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, f in enumerate(features):
|
||||
geom = f.geometry()
|
||||
|
@ -145,7 +145,7 @@ class IdwInterpolation(GeoAlgorithm):
|
||||
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
|
||||
self.tr('Interpolated')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
interpolationData = self.getParameterValue(self.INTERPOLATION_DATA)
|
||||
coefficient = self.getParameterValue(self.DISTANCE_COEFFICIENT)
|
||||
columns = self.getParameterValue(self.COLUMNS)
|
||||
|
@ -113,7 +113,7 @@ class ImportIntoPostGIS(GeoAlgorithm):
|
||||
self.addParameter(ParameterBoolean(self.FORCE_SINGLEPART,
|
||||
self.tr('Create single-part geometries instead of multi-part'), False))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
connection = self.getParameterValue(self.DATABASE)
|
||||
db = postgis.GeoDB.from_name(connection)
|
||||
|
||||
|
@ -80,7 +80,7 @@ class ImportIntoSpatialite(GeoAlgorithm):
|
||||
self.addParameter(ParameterBoolean(self.DROP_STRING_LENGTH, self.tr('Drop length constraints on character fields'), False))
|
||||
self.addParameter(ParameterBoolean(self.FORCE_SINGLEPART, self.tr('Create single-part geometries instead of multi-part'), False))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
database = self.getParameterValue(self.DATABASE)
|
||||
uri = QgsDataSourceUri(database)
|
||||
if uri.database() is '':
|
||||
|
@ -29,7 +29,7 @@ import os
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry, QgsWkbTypes
|
||||
from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry, QgsWkbTypes, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
@ -74,7 +74,7 @@ class Intersection(GeoAlgorithm):
|
||||
self.tr('Intersect layer')))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Intersection')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
vlayerA = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
vlayerB = dataobjects.getLayerFromString(
|
||||
@ -86,8 +86,8 @@ class Intersection(GeoAlgorithm):
|
||||
geomType, vlayerA.crs())
|
||||
outFeat = QgsFeature()
|
||||
index = vector.spatialindex(vlayerB)
|
||||
selectionA = vector.features(vlayerA)
|
||||
total = 100.0 / len(selectionA)
|
||||
selectionA = QgsProcessingUtils.getFeatures(vlayerA, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(vlayerA, context)
|
||||
for current, inFeatA in enumerate(selectionA):
|
||||
feedback.setProgress(int(current * total))
|
||||
geom = inFeatA.geometry()
|
||||
|
@ -29,7 +29,8 @@ __revision__ = '$Format:%H$'
|
||||
import os
|
||||
|
||||
from qgis.core import (QgsFeature,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -76,7 +77,7 @@ class JoinAttributes(GeoAlgorithm):
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER,
|
||||
self.tr('Joined layer')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
input = self.getParameterValue(self.INPUT_LAYER)
|
||||
input2 = self.getParameterValue(self.INPUT_LAYER_2)
|
||||
output = self.getOutputFromName(self.OUTPUT_LAYER)
|
||||
@ -95,8 +96,8 @@ class JoinAttributes(GeoAlgorithm):
|
||||
|
||||
# Cache attributes of Layer 2
|
||||
cache = {}
|
||||
features = vector.features(layer2)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer2, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer2, context)
|
||||
for current, feat in enumerate(features):
|
||||
attrs = feat.attributes()
|
||||
joinValue2 = str(attrs[joinField2Index])
|
||||
@ -106,8 +107,8 @@ class JoinAttributes(GeoAlgorithm):
|
||||
|
||||
# Create output vector layer with additional attribute
|
||||
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):
|
||||
outFeat.setGeometry(feat.geometry())
|
||||
attrs = feat.attributes()
|
||||
|
@ -30,7 +30,8 @@ import os
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import (QgsFeatureRequest, QgsFeature, QgsGeometry,
|
||||
QgsWkbTypes, QgsFields)
|
||||
QgsWkbTypes, QgsFields,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -80,7 +81,7 @@ class LinesIntersection(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Intersections'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layerA = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT_A))
|
||||
layerB = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT_B))
|
||||
fieldA = self.getParameterValue(self.FIELD_A)
|
||||
@ -110,8 +111,8 @@ class LinesIntersection(GeoAlgorithm):
|
||||
spatialIndex = vector.spatialindex(layerB)
|
||||
|
||||
outFeat = QgsFeature()
|
||||
features = vector.features(layerA)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layerA, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layerA, context)
|
||||
hasIntersections = False
|
||||
|
||||
for current, inFeatA in enumerate(features):
|
||||
|
@ -29,7 +29,7 @@ import os
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import QgsFeature, QgsGeometry, QgsWkbTypes
|
||||
from qgis.core import QgsFeature, QgsGeometry, QgsWkbTypes, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -65,7 +65,7 @@ class LinesToPolygons(GeoAlgorithm):
|
||||
[dataobjects.TYPE_VECTOR_LINE]))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Polygons from lines'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
|
||||
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
|
||||
@ -73,8 +73,8 @@ class LinesToPolygons(GeoAlgorithm):
|
||||
)
|
||||
|
||||
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, f in enumerate(features):
|
||||
outGeomList = []
|
||||
if f.geometry().isMultipart():
|
||||
|
@ -71,7 +71,7 @@ class MeanAndStdDevPlot(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputHTML(self.OUTPUT, self.tr('Plot')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
namefieldname = self.getParameterValue(self.NAME_FIELD)
|
||||
@ -79,7 +79,7 @@ class MeanAndStdDevPlot(GeoAlgorithm):
|
||||
|
||||
output = self.getOutputValue(self.OUTPUT)
|
||||
|
||||
values = vector.values(layer, namefieldname, valuefieldname)
|
||||
values = vector.values(layer, context, namefieldname, valuefieldname)
|
||||
|
||||
d = {}
|
||||
for i in range(len(values[namefieldname])):
|
||||
|
@ -31,7 +31,7 @@ import os
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
|
||||
from qgis.core import QgsField, QgsFeature, QgsGeometry, QgsPoint, QgsWkbTypes
|
||||
from qgis.core import QgsField, QgsFeature, QgsGeometry, QgsPoint, QgsWkbTypes, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
@ -78,7 +78,7 @@ class MeanCoords(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(MeanCoords.OUTPUT, self.tr('Mean coordinates'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.POINTS))
|
||||
weightField = self.getParameterValue(self.WEIGHT)
|
||||
uniqueField = self.getParameterValue(self.UID)
|
||||
@ -101,8 +101,8 @@ class MeanCoords(GeoAlgorithm):
|
||||
fieldList, QgsWkbTypes.Point, layer.crs()
|
||||
)
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
means = {}
|
||||
for current, feat in enumerate(features):
|
||||
feedback.setProgress(int(current * total))
|
||||
|
@ -63,7 +63,7 @@ class Merge(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Merged')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
inLayers = self.getParameterValue(self.LAYERS)
|
||||
|
||||
layers = []
|
||||
|
@ -27,7 +27,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
|
||||
from qgis.core import QgsFeature
|
||||
from qgis.core import QgsFeature, QgsProcessingUtils
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
@ -65,7 +65,7 @@ class MergeLines(GeoAlgorithm):
|
||||
self.tr('Input layer'), [dataobjects.TYPE_VECTOR_LINE]))
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Merged'), datatype=[dataobjects.TYPE_VECTOR_LINE]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
@ -75,8 +75,8 @@ class MergeLines(GeoAlgorithm):
|
||||
layer.wkbType(),
|
||||
layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, inFeat in enumerate(features):
|
||||
outFeat = QgsFeature()
|
||||
|
@ -29,7 +29,7 @@ import os
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import QgsWkbTypes
|
||||
from qgis.core import QgsWkbTypes, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -60,15 +60,15 @@ class MultipartToSingleparts(GeoAlgorithm):
|
||||
self.addParameter(ParameterVector(self.INPUT, self.tr('Input layer')))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Single parts')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
|
||||
geomType = QgsWkbTypes.singleType(layer.wkbType())
|
||||
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
|
||||
layer.fields().toList(), geomType, layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, f in enumerate(features):
|
||||
input_geometry = f.geometry()
|
||||
if input_geometry:
|
||||
|
@ -33,7 +33,7 @@ import codecs
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import QgsFeatureRequest, QgsFeature, QgsDistanceArea
|
||||
from qgis.core import QgsFeatureRequest, QgsFeature, QgsDistanceArea, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -82,7 +82,7 @@ class NearestNeighbourAnalysis(GeoAlgorithm):
|
||||
self.tr('Number of points')))
|
||||
self.addOutput(OutputNumber(self.Z_SCORE, self.tr('Z-Score')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.POINTS))
|
||||
output = self.getOutputValue(self.OUTPUT)
|
||||
|
||||
@ -95,8 +95,8 @@ class NearestNeighbourAnalysis(GeoAlgorithm):
|
||||
A = layer.extent()
|
||||
A = float(A.width() * A.height())
|
||||
|
||||
features = vector.features(layer)
|
||||
count = len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
count = QgsProcessingUtils.featureCount(layer, context)
|
||||
total = 100.0 / count
|
||||
for current, feat in enumerate(features):
|
||||
neighbourID = spatialIndex.nearestNeighbor(
|
||||
|
@ -28,7 +28,8 @@ __revision__ = '$Format:%H$'
|
||||
import os
|
||||
|
||||
from qgis.core import (QgsApplication,
|
||||
QgsWkbTypes)
|
||||
QgsWkbTypes,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
@ -82,7 +83,7 @@ class OffsetLine(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Offset'), datatype=[dataobjects.TYPE_VECTOR_LINE]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
@ -97,8 +98,8 @@ class OffsetLine(GeoAlgorithm):
|
||||
join_style = self.getParameterValue(self.JOIN_STYLE) + 1
|
||||
miter_limit = self.getParameterValue(self.MITRE_LIMIT)
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, input_feature in enumerate(features):
|
||||
output_feature = input_feature
|
||||
|
@ -32,7 +32,8 @@ from qgis.core import (QgsField,
|
||||
QgsFeature,
|
||||
QgsWkbTypes,
|
||||
QgsFeatureRequest,
|
||||
QgsApplication)
|
||||
QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -71,7 +72,7 @@ class OrientedMinimumBoundingBox(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Oriented_MBBox'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
byFeature = self.getParameterValue(self.BY_FEATURE)
|
||||
@ -93,16 +94,16 @@ class OrientedMinimumBoundingBox(GeoAlgorithm):
|
||||
QgsWkbTypes.Polygon, layer.crs())
|
||||
|
||||
if byFeature:
|
||||
self.featureOmbb(layer, writer, feedback)
|
||||
self.featureOmbb(layer, context, writer, feedback)
|
||||
else:
|
||||
self.layerOmmb(layer, writer, feedback)
|
||||
self.layerOmmb(layer, context, writer, feedback)
|
||||
|
||||
del writer
|
||||
|
||||
def layerOmmb(self, layer, writer, feedback):
|
||||
def layerOmmb(self, layer, context, writer, feedback):
|
||||
req = QgsFeatureRequest().setSubsetOfAttributes([])
|
||||
features = vector.features(layer, req)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context, req)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
newgeometry = QgsGeometry()
|
||||
first = True
|
||||
for current, inFeat in enumerate(features):
|
||||
@ -126,9 +127,9 @@ class OrientedMinimumBoundingBox(GeoAlgorithm):
|
||||
height])
|
||||
writer.addFeature(outFeat)
|
||||
|
||||
def featureOmbb(self, layer, writer, feedback):
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
def featureOmbb(self, layer, context, writer, feedback):
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
outFeat = QgsFeature()
|
||||
for current, inFeat in enumerate(features):
|
||||
geometry, area, angle, width, height = inFeat.geometry().orientedMinimumBoundingBox()
|
||||
|
@ -25,7 +25,8 @@ __copyright__ = '(C) 2016, Nyall Dawson'
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from qgis.core import (QgsApplication)
|
||||
from qgis.core import (QgsApplication,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
from processing.core.parameters import ParameterVector, ParameterNumber
|
||||
@ -75,7 +76,7 @@ class Orthogonalize(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Orthogonalized')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
max_iterations = self.getParameterValue(self.MAX_ITERATIONS)
|
||||
@ -86,8 +87,8 @@ class Orthogonalize(GeoAlgorithm):
|
||||
layer.wkbType(),
|
||||
layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, input_feature in enumerate(features):
|
||||
output_feature = input_feature
|
||||
|
@ -33,7 +33,7 @@ import math
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import QgsFeatureRequest, QgsDistanceArea
|
||||
from qgis.core import QgsFeatureRequest, QgsDistanceArea, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterNumber
|
||||
@ -90,7 +90,7 @@ class PointDistance(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputTable(self.DISTANCE_MATRIX, self.tr('Distance matrix')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
inLayer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
inField = self.getParameterValue(self.INPUT_FIELD)
|
||||
@ -103,24 +103,24 @@ class PointDistance(GeoAlgorithm):
|
||||
outputFile = self.getOutputFromName(self.DISTANCE_MATRIX)
|
||||
|
||||
if nPoints < 1:
|
||||
nPoints = len(vector.features(targetLayer))
|
||||
nPoints = QgsProcessingUtils.featureCount(targetLayer, context)
|
||||
|
||||
self.writer = outputFile.getTableWriter([])
|
||||
|
||||
if matType == 0:
|
||||
# Linear distance matrix
|
||||
self.linearMatrix(inLayer, inField, targetLayer, targetField,
|
||||
self.linearMatrix(context, inLayer, inField, targetLayer, targetField,
|
||||
matType, nPoints, feedback)
|
||||
elif matType == 1:
|
||||
# Standard distance matrix
|
||||
self.regularMatrix(inLayer, inField, targetLayer, targetField,
|
||||
self.regularMatrix(context, inLayer, inField, targetLayer, targetField,
|
||||
nPoints, feedback)
|
||||
elif matType == 2:
|
||||
# Summary distance matrix
|
||||
self.linearMatrix(inLayer, inField, targetLayer, targetField,
|
||||
self.linearMatrix(context, inLayer, inField, targetLayer, targetField,
|
||||
matType, nPoints, feedback)
|
||||
|
||||
def linearMatrix(self, inLayer, inField, targetLayer, targetField,
|
||||
def linearMatrix(self, context, inLayer, inField, targetLayer, targetField,
|
||||
matType, nPoints, feedback):
|
||||
if matType == 0:
|
||||
self.writer.addRecord(['InputID', 'TargetID', 'Distance'])
|
||||
@ -134,8 +134,8 @@ class PointDistance(GeoAlgorithm):
|
||||
|
||||
distArea = QgsDistanceArea()
|
||||
|
||||
features = vector.features(inLayer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(inLayer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(inLayer, context)
|
||||
for current, inFeat in enumerate(features):
|
||||
inGeom = inFeat.geometry()
|
||||
inID = str(inFeat.attributes()[inIdx])
|
||||
@ -164,7 +164,7 @@ class PointDistance(GeoAlgorithm):
|
||||
|
||||
feedback.setProgress(int(current * total))
|
||||
|
||||
def regularMatrix(self, inLayer, inField, targetLayer, targetField,
|
||||
def regularMatrix(self, context, inLayer, inField, targetLayer, targetField,
|
||||
nPoints, feedback):
|
||||
index = vector.spatialindex(targetLayer)
|
||||
|
||||
@ -173,8 +173,8 @@ class PointDistance(GeoAlgorithm):
|
||||
distArea = QgsDistanceArea()
|
||||
|
||||
first = True
|
||||
features = vector.features(inLayer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(inLayer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(inLayer, context)
|
||||
for current, inFeat in enumerate(features):
|
||||
inGeom = inFeat.geometry()
|
||||
inID = str(inFeat.attributes()[inIdx])
|
||||
|
@ -27,7 +27,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
|
||||
from qgis.core import QgsWkbTypes
|
||||
from qgis.core import QgsWkbTypes, QgsProcessingUtils
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
@ -62,7 +62,7 @@ class PointOnSurface(GeoAlgorithm):
|
||||
self.tr('Input layer')))
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Point'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
@ -72,8 +72,8 @@ class PointOnSurface(GeoAlgorithm):
|
||||
QgsWkbTypes.Point,
|
||||
layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, input_feature in enumerate(features):
|
||||
output_feature = input_feature
|
||||
|
@ -31,7 +31,7 @@ import math
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import QgsFeature, QgsWkbTypes, QgsField
|
||||
from qgis.core import QgsFeature, QgsWkbTypes, QgsField, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector, ParameterNumber
|
||||
@ -76,7 +76,7 @@ class PointsAlongGeometry(GeoAlgorithm):
|
||||
self.tr('End offset'), default=0.0))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Points'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
distance = self.getParameterValue(self.DISTANCE)
|
||||
@ -90,8 +90,8 @@ class PointsAlongGeometry(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
|
||||
fields, QgsWkbTypes.Point, layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, input_feature in enumerate(features):
|
||||
input_geometry = input_feature.geometry()
|
||||
if not input_geometry:
|
||||
|
@ -31,7 +31,8 @@ from qgis.core import (QgsApplication,
|
||||
QgsFeatureRequest,
|
||||
QgsFeature,
|
||||
QgsGeometry,
|
||||
QgsPoint)
|
||||
QgsPoint,
|
||||
QgsProcessingUtils)
|
||||
from processing.tools import dataobjects, vector
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -72,7 +73,7 @@ class PointsDisplacement(GeoAlgorithm):
|
||||
self.tr('Horizontal distribution for two point case')))
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Displaced'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
radius = self.getParameterValue(self.DISTANCE)
|
||||
horizontal = self.getParameterValue(self.HORIZONTAL)
|
||||
output = self.getOutputFromName(self.OUTPUT_LAYER)
|
||||
@ -82,9 +83,9 @@ class PointsDisplacement(GeoAlgorithm):
|
||||
writer = output.getVectorWriter(layer.fields(),
|
||||
layer.wkbType(), layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
|
||||
total = 100.0 / len(features)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
duplicates = dict()
|
||||
for current, f in enumerate(features):
|
||||
|
@ -35,7 +35,8 @@ from qgis.core import (QgsApplication,
|
||||
QgsField,
|
||||
QgsGeometry,
|
||||
QgsPoint,
|
||||
QgsWkbTypes)
|
||||
QgsWkbTypes,
|
||||
QgsProcessingUtils)
|
||||
from processing.tools import vector, raster, dataobjects
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterRaster
|
||||
@ -72,7 +73,7 @@ class PointsFromLines(GeoAlgorithm):
|
||||
self.tr('Vector layer'), [dataobjects.TYPE_VECTOR_LINE]))
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Points along line'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT_VECTOR))
|
||||
|
||||
rasterPath = str(self.getParameterValue(self.INPUT_RASTER))
|
||||
@ -96,8 +97,8 @@ class PointsFromLines(GeoAlgorithm):
|
||||
self.lineId = 0
|
||||
self.pointId = 0
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, f in enumerate(features):
|
||||
geom = f.geometry()
|
||||
if geom.isMultipart():
|
||||
|
@ -34,7 +34,8 @@ from qgis.core import (QgsApplication,
|
||||
QgsFeature,
|
||||
QgsGeometry,
|
||||
QgsWkbTypes,
|
||||
QgsPointV2)
|
||||
QgsPointV2,
|
||||
QgsProcessingUtils)
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterRaster
|
||||
@ -72,7 +73,7 @@ class PointsFromPolygons(GeoAlgorithm):
|
||||
self.tr('Vector layer'), [dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Points from polygons'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT_VECTOR))
|
||||
|
||||
rasterPath = str(self.getParameterValue(self.INPUT_RASTER))
|
||||
@ -96,8 +97,8 @@ class PointsFromPolygons(GeoAlgorithm):
|
||||
polyId = 0
|
||||
pointId = 0
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, f in enumerate(features):
|
||||
geom = f.geometry()
|
||||
bbox = geom.boundingBox()
|
||||
|
@ -30,7 +30,7 @@ import os
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
|
||||
from qgis.core import QgsGeometry, QgsFeatureRequest, QgsFeature, QgsField
|
||||
from qgis.core import QgsGeometry, QgsFeatureRequest, QgsFeature, QgsField, QgsProcessingUtils
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -69,7 +69,7 @@ class PointsInPolygon(GeoAlgorithm):
|
||||
self.tr('Count field name'), 'NUMPOINTS'))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Count'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
polyLayer = dataobjects.getLayerFromString(self.getParameterValue(self.POLYGONS))
|
||||
pointLayer = dataobjects.getLayerFromString(self.getParameterValue(self.POINTS))
|
||||
fieldName = self.getParameterValue(self.FIELD)
|
||||
@ -90,8 +90,8 @@ class PointsInPolygon(GeoAlgorithm):
|
||||
outFeat = QgsFeature()
|
||||
geom = QgsGeometry()
|
||||
|
||||
features = vector.features(polyLayer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(polyLayer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(polyLayer, context)
|
||||
for current, ftPoly in enumerate(features):
|
||||
geom = ftPoly.geometry()
|
||||
engine = QgsGeometry.createGeometryEngine(geom.geometry())
|
||||
|
@ -30,7 +30,8 @@ from qgis.core import (QgsApplication,
|
||||
QgsField,
|
||||
QgsFeatureRequest,
|
||||
QgsFeature,
|
||||
QgsGeometry)
|
||||
QgsGeometry,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
from processing.core.parameters import ParameterString
|
||||
@ -73,7 +74,7 @@ class PointsInPolygonUnique(GeoAlgorithm):
|
||||
self.tr('Count field name'), 'NUMPOINTS'))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Unique count'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
polyLayer = dataobjects.getLayerFromString(self.getParameterValue(self.POLYGONS))
|
||||
pointLayer = dataobjects.getLayerFromString(self.getParameterValue(self.POINTS))
|
||||
fieldName = self.getParameterValue(self.FIELD)
|
||||
@ -95,8 +96,8 @@ class PointsInPolygonUnique(GeoAlgorithm):
|
||||
outFeat = QgsFeature()
|
||||
geom = QgsGeometry()
|
||||
|
||||
features = vector.features(polyLayer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(polyLayer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(polyLayer, context)
|
||||
for current, ftPoly in enumerate(features):
|
||||
geom = ftPoly.geometry()
|
||||
engine = QgsGeometry.createGeometryEngine(geom.geometry())
|
||||
|
@ -31,7 +31,8 @@ from qgis.core import (QgsApplication,
|
||||
QgsField,
|
||||
QgsFeatureRequest,
|
||||
QgsFeature,
|
||||
QgsGeometry)
|
||||
QgsGeometry,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
from processing.core.parameters import ParameterString
|
||||
@ -80,7 +81,7 @@ class PointsInPolygonWeighted(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Weighted count'), datatype=[dataobjects.TYPE_VECTOR_POLYGON]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
polyLayer = dataobjects.getLayerFromString(self.getParameterValue(self.POLYGONS))
|
||||
pointLayer = dataobjects.getLayerFromString(self.getParameterValue(self.POINTS))
|
||||
fieldName = self.getParameterValue(self.FIELD)
|
||||
@ -101,8 +102,8 @@ class PointsInPolygonWeighted(GeoAlgorithm):
|
||||
outFeat = QgsFeature()
|
||||
geom = QgsGeometry()
|
||||
|
||||
features = vector.features(polyLayer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(polyLayer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(polyLayer, context)
|
||||
for current, ftPoly in enumerate(features):
|
||||
geom = ftPoly.geometry()
|
||||
engine = QgsGeometry.createGeometryEngine(geom.geometry())
|
||||
|
@ -29,7 +29,8 @@ from qgis.core import (QgsApplication,
|
||||
QgsWkbTypes,
|
||||
QgsPointV2,
|
||||
QgsCoordinateReferenceSystem,
|
||||
QgsGeometry)
|
||||
QgsGeometry,
|
||||
QgsProcessingUtils)
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterTable
|
||||
from processing.core.parameters import ParameterTableField
|
||||
@ -81,7 +82,7 @@ class PointsLayerFromTable(GeoAlgorithm):
|
||||
self.tr('Target CRS'), 'EPSG:4326'))
|
||||
self.addOutput(OutputVector(self.OUTPUT, self.tr('Points from table'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
source = self.getParameterValue(self.INPUT)
|
||||
vlayer = dataobjects.getLayerFromString(source)
|
||||
output = self.getOutputFromName(self.OUTPUT)
|
||||
@ -108,8 +109,8 @@ class PointsLayerFromTable(GeoAlgorithm):
|
||||
|
||||
writer = output.getVectorWriter(fields, wkb_type, target_crs)
|
||||
|
||||
features = vector.features(vlayer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(vlayer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(vlayer, context)
|
||||
|
||||
for current, feature in enumerate(features):
|
||||
feedback.setProgress(int(current * total))
|
||||
|
@ -36,7 +36,8 @@ from qgis.core import (QgsApplication,
|
||||
QgsField,
|
||||
QgsGeometry,
|
||||
QgsDistanceArea,
|
||||
QgsWkbTypes)
|
||||
QgsWkbTypes,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.parameters import ParameterVector
|
||||
@ -87,7 +88,7 @@ class PointsToPaths(GeoAlgorithm):
|
||||
self.addOutput(OutputVector(self.OUTPUT_LINES, self.tr('Paths'), datatype=[dataobjects.TYPE_VECTOR_LINE]))
|
||||
self.addOutput(OutputDirectory(self.OUTPUT_TEXT, self.tr('Directory')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.VECTOR))
|
||||
groupField = self.getParameterValue(self.GROUP_FIELD)
|
||||
@ -104,8 +105,8 @@ class PointsToPaths(GeoAlgorithm):
|
||||
fields, QgsWkbTypes.LineString, layer.crs())
|
||||
|
||||
points = dict()
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
for current, f in enumerate(features):
|
||||
point = f.geometry().asPoint()
|
||||
group = f[groupField]
|
||||
|
@ -69,7 +69,7 @@ class PolarPlot(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputHTML(self.OUTPUT, self.tr('Polar plot')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT))
|
||||
namefieldname = self.getParameterValue(self.NAME_FIELD) # NOQA FIXME unused?
|
||||
@ -77,7 +77,7 @@ class PolarPlot(GeoAlgorithm):
|
||||
|
||||
output = self.getOutputValue(self.OUTPUT)
|
||||
|
||||
values = vector.values(layer, valuefieldname)
|
||||
values = vector.values(layer, context, valuefieldname)
|
||||
|
||||
data = [go.Area(r=values[valuefieldname],
|
||||
t=np.degrees(np.arange(0.0, 2 * np.pi, 2 * np.pi / len(values[valuefieldname]))))]
|
||||
|
@ -27,7 +27,7 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
|
||||
from qgis.core import QgsWkbTypes, QgsField, NULL
|
||||
from qgis.core import QgsWkbTypes, QgsField, NULL, QgsProcessingUtils
|
||||
|
||||
from qgis.PyQt.QtCore import QVariant
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
@ -70,7 +70,7 @@ class PoleOfInaccessibility(GeoAlgorithm):
|
||||
self.tr('Tolerance (layer units)'), default=1.0, minValue=0.0))
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Point'), datatype=[dataobjects.TYPE_VECTOR_POINT]))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
tolerance = self.getParameterValue(self.TOLERANCE)
|
||||
@ -84,8 +84,8 @@ class PoleOfInaccessibility(GeoAlgorithm):
|
||||
QgsWkbTypes.Point,
|
||||
layer.crs())
|
||||
|
||||
features = vector.features(layer)
|
||||
total = 100.0 / len(features)
|
||||
features = QgsProcessingUtils.getFeatures(layer, context)
|
||||
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
|
||||
|
||||
for current, input_feature in enumerate(features):
|
||||
output_feature = input_feature
|
||||
|
@ -32,7 +32,8 @@ from qgis.PyQt.QtGui import QIcon
|
||||
from qgis.core import (QgsProcessingAlgorithm,
|
||||
QgsGeometry,
|
||||
QgsFeature,
|
||||
QgsWkbTypes)
|
||||
QgsWkbTypes,
|
||||
QgsProcessingUtils)
|
||||
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
@ -70,7 +71,7 @@ class PolygonCentroids(GeoAlgorithm):
|
||||
|
||||
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Centroids')))
|
||||
|
||||
def processAlgorithm(self, feedback):
|
||||
def processAlgorithm(self, context, feedback):
|
||||
layer = dataobjects.getLayerFromString(
|
||||
self.getParameterValue(self.INPUT_LAYER))
|
||||
|
||||
@ -82,8 +83,8 @@ class PolygonCentroids(GeoAlgorithm):
|
||||
|
||||
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):
|
||||
inGeom = feat.geometry()
|
||||
attrs = feat.attributes()
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user