Skip to content
Permalink
Browse files

[processing] Skip more unnecessary geometry checks

(cherry-picked from 405d8f2)
  • Loading branch information
nyalldawson committed Apr 10, 2018
1 parent 9b0ddc6 commit 07207e0f9be3e708493516ccdc9fb8b6f798ef03
Showing with 109 additions and 32 deletions.
  1. +5 −1 python/plugins/processing/algs/qgis/AddTableField.py
  2. +3 −2 python/plugins/processing/algs/qgis/BasicStatistics.py
  3. +1 −2 python/plugins/processing/algs/qgis/CheckValidity.py
  4. +5 −1 python/plugins/processing/algs/qgis/DeleteColumn.py
  5. +3 −1 python/plugins/processing/algs/qgis/ExtractSpecificVertices.py
  6. +5 −1 python/plugins/processing/algs/qgis/GeometryByExpression.py
  7. +4 −2 python/plugins/processing/algs/qgis/PointsLayerFromTable.py
  8. +2 −1 python/plugins/processing/algs/qgis/PointsToPaths.py
  9. +4 −2 python/plugins/processing/algs/qgis/RandomExtract.py
  10. +4 −2 python/plugins/processing/algs/qgis/RandomExtractWithinSubsets.py
  11. +5 −1 python/plugins/processing/algs/qgis/SetMValue.py
  12. +3 −0 python/plugins/processing/algs/qgis/SetZValue.py
  13. +2 −1 python/plugins/processing/algs/qgis/StatisticsByCategories.py
  14. +5 −1 python/plugins/processing/algs/qgis/TextToFloat.py
  15. +2 −1 python/plugins/processing/algs/qgis/UniqueValues.py
  16. +5 −0 src/analysis/processing/qgsalgorithmaddincrementalfield.cpp
  17. +1 −0 src/analysis/processing/qgsalgorithmaddincrementalfield.h
  18. +5 −0 src/analysis/processing/qgsalgorithmassignprojection.cpp
  19. +1 −0 src/analysis/processing/qgsalgorithmassignprojection.h
  20. +5 −0 src/analysis/processing/qgsalgorithmdropgeometry.cpp
  21. +1 −0 src/analysis/processing/qgsalgorithmdropgeometry.h
  22. +5 −0 src/analysis/processing/qgsalgorithmdropmzvalues.cpp
  23. +1 −0 src/analysis/processing/qgsalgorithmdropmzvalues.h
  24. +2 −2 src/analysis/processing/qgsalgorithmextractvertices.cpp
  25. +4 −4 src/analysis/processing/qgsalgorithmjoinwithlines.cpp
  26. +2 −2 src/analysis/processing/qgsalgorithmmeancoordinates.cpp
  27. +6 −0 src/analysis/processing/qgsalgorithmmultiparttosinglepart.cpp
  28. +1 −0 src/analysis/processing/qgsalgorithmmultiparttosinglepart.h
  29. +5 −0 src/analysis/processing/qgsalgorithmpromotetomultipart.cpp
  30. +1 −1 src/analysis/processing/qgsalgorithmpromotetomultipart.h
  31. +6 −0 src/analysis/processing/qgsalgorithmremoveduplicatevertices.cpp
  32. +1 −0 src/analysis/processing/qgsalgorithmremoveduplicatevertices.h
  33. +2 −2 src/analysis/processing/qgsalgorithmremovenullgeometry.cpp
  34. +2 −2 src/analysis/processing/qgsalgorithmuniquevalueindex.cpp
@@ -30,7 +30,8 @@
QgsProcessing,
QgsProcessingParameterString,
QgsProcessingParameterNumber,
QgsProcessingParameterEnum)
QgsProcessingParameterEnum,
QgsProcessingFeatureSource)
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm


@@ -93,6 +94,9 @@ def outputFields(self, inputFields):
inputFields.append(self.field)
return inputFields

def sourceFlags(self):
return QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks

def processFeature(self, feature, context, feedback):
attributes = feature.attributes()
attributes.append(None)
@@ -38,7 +38,8 @@
QgsProcessingParameterFeatureSource,
QgsProcessingParameterField,
QgsProcessingParameterFileDestination,
QgsProcessingOutputNumber)
QgsProcessingOutputNumber,
QgsProcessingFeatureSource)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm

@@ -133,7 +134,7 @@ def processAlgorithm(self, parameters, context, feedback):
output_file = self.parameterAsFileOutput(parameters, self.OUTPUT_HTML_FILE, context)

request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry).setSubsetOfAttributes([field_name], source.fields())
features = source.getFeatures(request)
features = source.getFeatures(request, QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks)
count = source.featureCount()

data = []
@@ -43,8 +43,7 @@
QgsProcessingParameterFeatureSource,
QgsProcessingParameterEnum,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputNumber
)
QgsProcessingOutputNumber)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm

settings_method_key = "/qgis/digitizing/validate_geometries"
@@ -26,7 +26,8 @@
__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessingParameterField,
QgsProcessing)
QgsProcessing,
QgsProcessingFeatureSource)
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm


@@ -83,6 +84,9 @@ def outputFields(self, input_fields):
input_fields.remove(index)
return input_fields

def sourceFlags(self):
return QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks

def processFeature(self, feature, context, feedback):
attributes = feature.attributes()
for index in self.field_indices:
@@ -32,9 +32,11 @@
QgsVertexId,
QgsFeature,
QgsFeatureSink,
QgsFeatureRequest,
QgsGeometry,
QgsField,
QgsProcessing,
QgsProcessingFeatureSource,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterString,
QgsProcessingParameterFeatureSink,
@@ -103,7 +105,7 @@ def processAlgorithm(self, parameters, context, feedback):
raise QgsProcessingException(
self.tr('\'{}\' is not a valid vertex index').format(vertex))

features = source.getFeatures()
features = source.getFeatures(QgsFeatureRequest(), QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks)
total = 100.0 / source.featureCount() if source.featureCount() else 0

for current, f in enumerate(features):
@@ -31,7 +31,8 @@
QgsProcessingException,
QgsProcessingParameterBoolean,
QgsProcessingParameterEnum,
QgsProcessingParameterExpression)
QgsProcessingParameterExpression,
QgsProcessingFeatureSource)

from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm

@@ -104,6 +105,9 @@ def prepareAlgorithm(self, parameters, context, feedback):
def outputWkbType(self, input_wkb_type):
return self.wkb_type

def sourceFlags(self):
return QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks

def processFeature(self, feature, context, feedback):
self.expression_context.setFeature(feature)
value = self.expression.evaluate(self.expression_context)
@@ -34,7 +34,9 @@
QgsProcessingParameterFeatureSink,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterCrs,
QgsProcessingParameterField)
QgsProcessingParameterField,
QgsProcessingFeatureSource,
QgsFeatureRequest)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm


@@ -107,7 +109,7 @@ def processAlgorithm(self, parameters, context, feedback):
fields, wkb_type, target_crs)

request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry)
features = source.getFeatures()
features = source.getFeatures(QgsFeatureRequest(), QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks)
total = 100.0 / source.featureCount() if source.featureCount() else 0

for current, feature in enumerate(features):
@@ -41,6 +41,7 @@
QgsProcessingParameterFeatureSource,
QgsProcessingParameterField,
QgsProcessingParameterString,
QgsProcessingFeatureSource,
QgsProcessing,
QgsProcessingParameterFeatureSink,
QgsProcessingParameterFolderDestination)
@@ -126,7 +127,7 @@ def processAlgorithm(self, parameters, context, feedback):
fields, output_wkb, source.sourceCrs())

points = dict()
features = source.getFeatures(QgsFeatureRequest().setSubsetOfAttributes([group_field_index, order_field_index]))
features = source.getFeatures(QgsFeatureRequest().setSubsetOfAttributes([group_field_index, order_field_index]), QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks)
total = 100.0 / source.featureCount() if source.featureCount() else 0
for current, f in enumerate(features):
if feedback.isCanceled():
@@ -32,7 +32,9 @@
QgsProcessingParameterFeatureSource,
QgsProcessingParameterEnum,
QgsProcessingParameterNumber,
QgsProcessingParameterFeatureSink)
QgsProcessingParameterFeatureSink,
QgsFeatureRequest,
QgsProcessingFeatureSource)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm


@@ -78,7 +80,7 @@ def processAlgorithm(self, parameters, context, feedback):
source = self.parameterAsSource(parameters, self.INPUT, context)
method = self.parameterAsEnum(parameters, self.METHOD, context)

features = source.getFeatures()
features = source.getFeatures(QgsFeatureRequest(), QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks)
featureCount = source.featureCount()
value = self.parameterAsInt(parameters, self.NUMBER, context)

@@ -33,7 +33,9 @@
QgsProcessingParameterEnum,
QgsProcessingParameterField,
QgsProcessingParameterNumber,
QgsProcessingParameterFeatureSink)
QgsProcessingParameterFeatureSink,
QgsProcessingFeatureSource,
QgsFeatureRequest)
from collections import defaultdict
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm

@@ -88,7 +90,7 @@ def processAlgorithm(self, parameters, context, feedback):

index = source.fields().lookupField(field)

features = source.getFeatures()
features = source.getFeatures(QgsFeatureRequest(), QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks)
featureCount = source.featureCount()
unique = source.uniqueValues(index)
value = self.parameterAsInt(parameters, self.NUMBER, context)
@@ -31,7 +31,8 @@
QgsWkbTypes,
QgsPropertyDefinition,
QgsProcessingParameters,
QgsProcessingParameterNumber)
QgsProcessingParameterNumber,
QgsProcessingFeatureSource)


from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm
@@ -85,6 +86,9 @@ def prepareAlgorithm(self, parameters, context, feedback):
self.m_property = parameters[self.M_VALUE]
return True

def sourceFlags(self):
return QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks

def processFeature(self, feature, context, feedback):
input_geometry = feature.geometry()
if input_geometry:
@@ -79,6 +79,9 @@ def initParameters(self, config=None):
def outputWkbType(self, inputWkb):
return QgsWkbTypes.addZ(inputWkb)

def sourceFlags(self):
return QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks

def prepareAlgorithm(self, parameters, context, feedback):
self.z_value = self.parameterAsDouble(parameters, self.Z_VALUE, context)
self.dynamic_z = QgsProcessingParameters.isDynamic(parameters, self.Z_VALUE)
@@ -39,6 +39,7 @@
QgsFeature,
QgsFeatureSink,
QgsProcessing,
QgsProcessingFeatureSource,
NULL)
from qgis.PyQt.QtCore import QVariant
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
@@ -155,7 +156,7 @@ def addField(name):
attrs = []
attrs.extend(category_field_indexes)
request.setSubsetOfAttributes(attrs)
features = source.getFeatures(request)
features = source.getFeatures(request, QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks)
total = 50.0 / source.featureCount() if source.featureCount() else 0
if field_type == 'none':
values = defaultdict(lambda: 0)
@@ -28,7 +28,8 @@
from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsField,
QgsProcessing,
QgsProcessingParameterField)
QgsProcessingParameterField,
QgsProcessingFeatureSource)
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm


@@ -76,6 +77,9 @@ def prepareAlgorithm(self, parameters, context, feedback):
self.field_name = self.parameterAsString(parameters, self.FIELD, context)
return True

def sourceFlags(self):
return QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks

def processFeature(self, feature, context, feedback):
value = feature[self.field_idx]
try:
@@ -42,6 +42,7 @@
QgsProcessingParameterFeatureSink,
QgsProcessingOutputNumber,
QgsProcessingOutputString,
QgsProcessingFeatureSource,
QgsProcessingParameterFileDestination)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
@@ -118,7 +119,7 @@ def processAlgorithm(self, parameters, context, feedback):
request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry)
request.setSubsetOfAttributes(field_indices)
total = 100.0 / source.featureCount() if source.featureCount() else 0
for current, f in enumerate(source.getFeatures(request)):
for current, f in enumerate(source.getFeatures(request, QgsProcessingFeatureSource.FlagSkipGeometryValidityChecks)):
if feedback.isCanceled():
break

@@ -69,6 +69,11 @@ QgsAddIncrementalFieldAlgorithm *QgsAddIncrementalFieldAlgorithm::createInstance
return new QgsAddIncrementalFieldAlgorithm();
}

QgsProcessingFeatureSource::Flag QgsAddIncrementalFieldAlgorithm::sourceFlags() const
{
return QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks;
}

void QgsAddIncrementalFieldAlgorithm::initParameters( const QVariantMap & )
{
addParameter( new QgsProcessingParameterString( QStringLiteral( "FIELD_NAME" ), QObject::tr( "Field name" ), QStringLiteral( "AUTO" ) ) );
@@ -48,6 +48,7 @@ class QgsAddIncrementalFieldAlgorithm : public QgsProcessingFeatureBasedAlgorith
void initParameters( const QVariantMap &configuration = QVariantMap() ) override;
QString outputName() const override;
QgsFields outputFields( const QgsFields &inputFields ) const override;
QgsProcessingFeatureSource::Flag sourceFlags() const override;

bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
@@ -67,6 +67,11 @@ void QgsAssignProjectionAlgorithm::initParameters( const QVariantMap & )
addParameter( new QgsProcessingParameterCrs( QStringLiteral( "CRS" ), QObject::tr( "Assigned CRS" ), QStringLiteral( "EPSG:4326" ) ) );
}

QgsProcessingFeatureSource::Flag QgsAssignProjectionAlgorithm::sourceFlags() const
{
return QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks;
}

bool QgsAssignProjectionAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
mDestCrs = parameterAsCrs( parameters, QStringLiteral( "CRS" ), context );
@@ -47,6 +47,7 @@ class QgsAssignProjectionAlgorithm : public QgsProcessingFeatureBasedAlgorithm
void initParameters( const QVariantMap &configuration = QVariantMap() ) override;
QgsCoordinateReferenceSystem outputCrs( const QgsCoordinateReferenceSystem & ) const override { return mDestCrs; }
QString outputName() const override;
QgsProcessingFeatureSource::Flag sourceFlags() const override;

bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
@@ -69,6 +69,11 @@ QgsWkbTypes::Type QgsDropGeometryAlgorithm::outputWkbType( QgsWkbTypes::Type ) c
return QgsWkbTypes::NoGeometry;
}

QgsProcessingFeatureSource::Flag QgsDropGeometryAlgorithm::sourceFlags() const
{
return QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks;
}

QgsFeatureRequest QgsDropGeometryAlgorithm::request() const
{
return QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry );
@@ -48,6 +48,7 @@ class QgsDropGeometryAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QString outputName() const override;
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override;
QgsFeatureRequest request() const override;
QgsProcessingFeatureSource::Flag sourceFlags() const override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
};

@@ -75,6 +75,11 @@ QgsWkbTypes::Type QgsDropMZValuesAlgorithm::outputWkbType( QgsWkbTypes::Type inp
return wkb;
}

QgsProcessingFeatureSource::Flag QgsDropMZValuesAlgorithm::sourceFlags() const
{
return QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks;
}

bool QgsDropMZValuesAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
mDropM = parameterAsBool( parameters, QStringLiteral( "DROP_M_VALUES" ), context );
@@ -47,6 +47,7 @@ class QgsDropMZValuesAlgorithm : public QgsProcessingFeatureBasedAlgorithm
void initParameters( const QVariantMap &configuration = QVariantMap() ) override;
QString outputName() const override;
QgsWkbTypes::Type outputWkbType( QgsWkbTypes::Type inputWkbType ) const override;
QgsProcessingFeatureSource::Flag sourceFlags() const override;
bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;

@@ -68,7 +68,7 @@ void QgsExtractVerticesAlgorithm::initAlgorithm( const QVariantMap & )

QVariantMap QgsExtractVerticesAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
std::unique_ptr< QgsFeatureSource > featureSource( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
std::unique_ptr< QgsProcessingFeatureSource > featureSource( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
if ( !featureSource )
throw QgsProcessingException( QObject::tr( "Could not load source layer for INPUT" ) );

@@ -99,7 +99,7 @@ QVariantMap QgsExtractVerticesAlgorithm::processAlgorithm( const QVariantMap &pa
throw QgsProcessingException( QObject::tr( "Could not create destination layer for OUTPUT" ) );;

double step = featureSource->featureCount() > 0 ? 100.0 / featureSource->featureCount() : 1;
QgsFeatureIterator fi = featureSource->getFeatures( QgsFeatureRequest() );
QgsFeatureIterator fi = featureSource->getFeatures( QgsFeatureRequest(), QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks );
QgsFeature f;
int i = -1;
while ( fi.nextFeature( f ) )
@@ -87,8 +87,8 @@ QVariantMap QgsJoinWithLinesAlgorithm::processAlgorithm( const QVariantMap &para
if ( parameters.value( QStringLiteral( "SPOKES" ) ) == parameters.value( QStringLiteral( "HUBS" ) ) )
throw QgsProcessingException( QObject::tr( "Same layer given for both hubs and spokes" ) );

std::unique_ptr< QgsFeatureSource > hubSource( parameterAsSource( parameters, QStringLiteral( "HUBS" ), context ) );
std::unique_ptr< QgsFeatureSource > spokeSource( parameterAsSource( parameters, QStringLiteral( "SPOKES" ), context ) );
std::unique_ptr< QgsProcessingFeatureSource > hubSource( parameterAsSource( parameters, QStringLiteral( "HUBS" ), context ) );
std::unique_ptr< QgsProcessingFeatureSource > spokeSource( parameterAsSource( parameters, QStringLiteral( "SPOKES" ), context ) );
if ( !hubSource || !spokeSource )
throw QgsProcessingException( QObject::tr( "Could not load source layers" ) );

@@ -192,7 +192,7 @@ QVariantMap QgsJoinWithLinesAlgorithm::processAlgorithm( const QVariantMap &para
return p;
};

QgsFeatureIterator hubFeatures = hubSource->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( hubFields2Fetch ) );
QgsFeatureIterator hubFeatures = hubSource->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( hubFields2Fetch ), QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks );
double step = hubSource->featureCount() > 0 ? 100.0 / hubSource->featureCount() : 1;
int i = 0;
QgsFeature hubFeature;
@@ -224,7 +224,7 @@ QVariantMap QgsJoinWithLinesAlgorithm::processAlgorithm( const QVariantMap &para
spokeRequest.setSubsetOfAttributes( spokeFields2Fetch );
spokeRequest.setFilterExpression( QgsExpression::createFieldEqualityExpression( fieldSpokeName, hubFeature.attribute( fieldHubIndex ) ) );

QgsFeatureIterator spokeFeatures = spokeSource->getFeatures( spokeRequest );
QgsFeatureIterator spokeFeatures = spokeSource->getFeatures( spokeRequest, QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks );
QgsFeature spokeFeature;
while ( spokeFeatures.nextFeature( spokeFeature ) )
{

0 comments on commit 07207e0

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