22QString QgsRemoveNullGeometryAlgorithm::name()
const
24 return QStringLiteral(
"removenullgeometries" );
27QString QgsRemoveNullGeometryAlgorithm::displayName()
const
29 return QObject::tr(
"Remove null geometries" );
32QStringList QgsRemoveNullGeometryAlgorithm::tags()
const
34 return QObject::tr(
"remove,drop,delete,empty,geometry" ).split(
',' );
37QString QgsRemoveNullGeometryAlgorithm::group()
const
39 return QObject::tr(
"Vector geometry" );
42QString QgsRemoveNullGeometryAlgorithm::groupId()
const
44 return QStringLiteral(
"vectorgeometry" );
47void QgsRemoveNullGeometryAlgorithm::initAlgorithm(
const QVariantMap & )
57 addParameter( nullOutput );
60QString QgsRemoveNullGeometryAlgorithm::shortHelpString()
const
62 return QObject::tr(
"This algorithm removes any features which do not have a geometry from a vector layer. "
63 "All other features will be copied unchanged.\n\n"
64 "Optionally, the features with null geometries can be saved to a separate output.\n\n"
65 "If 'Also remove empty geometries' is checked, the algorithm removes features whose geometries "
66 "have no coordinates, i.e., geometries that are empty. In that case, also the null "
67 "output will reflect this option, containing both null and empty geometries." );
70QgsRemoveNullGeometryAlgorithm *QgsRemoveNullGeometryAlgorithm::createInstance()
const
72 return new QgsRemoveNullGeometryAlgorithm();
77 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
81 const bool removeEmpty = parameterAsBoolean( parameters, QStringLiteral(
"REMOVE_EMPTY" ), context );
83 QString nonNullSinkId;
84 std::unique_ptr< QgsFeatureSink > nonNullSink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, nonNullSinkId, source->fields(),
85 source->wkbType(), source->sourceCrs() ) );
88 std::unique_ptr< QgsFeatureSink > nullSink( parameterAsSink( parameters, QStringLiteral(
"NULL_OUTPUT" ), context, nullSinkId, source->fields() ) );
90 const long count = source->featureCount();
92 const double step = count > 0 ? 100.0 / count : 1;
107 throw QgsProcessingException( writeFeatureError( nonNullSink.get(), parameters, QStringLiteral(
"OUTPUT" ) ) );
112 throw QgsProcessingException( writeFeatureError( nullSink.get(), parameters, QStringLiteral(
"NULL_OUTPUT" ) ) );
121 outputs.insert( QStringLiteral(
"OUTPUT" ), nonNullSinkId );
123 outputs.insert( QStringLiteral(
"NULL_OUTPUT" ), nullSinkId );
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ VectorAnyGeometry
Any vector layer with geometry.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Contains information about the context in which a processing algorithm is executed.
void setCreateByDefault(bool createByDefault)
Sets whether the destination should be created by default.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A boolean parameter for processing algorithms.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.