22using namespace Qt::StringLiterals;
26QString QgsFilterByGeometryAlgorithm::name()
const
28 return u
"filterbygeometry"_s;
31QString QgsFilterByGeometryAlgorithm::displayName()
const
33 return QObject::tr(
"Filter by geometry type" );
36QStringList QgsFilterByGeometryAlgorithm::tags()
const
38 return QObject::tr(
"extract,filter,geometry,linestring,point,polygon" ).split(
',' );
41QString QgsFilterByGeometryAlgorithm::group()
const
43 return QObject::tr(
"Vector selection" );
46QString QgsFilterByGeometryAlgorithm::groupId()
const
48 return u
"vectorselection"_s;
51void QgsFilterByGeometryAlgorithm::initAlgorithm(
const QVariantMap & )
66 addOutput(
new QgsProcessingOutputNumber( u
"NO_GEOMETRY_COUNT"_s, QObject::tr(
"Total count of features without geometry" ) ) );
69QString QgsFilterByGeometryAlgorithm::shortHelpString()
const
72 "This algorithm filters features by their geometry type. Incoming features will be directed to different "
73 "outputs based on whether they have a point, line or polygon geometry."
77QString QgsFilterByGeometryAlgorithm::shortDescription()
const
79 return QObject::tr(
"Filters features by geometry type." );
82QgsFilterByGeometryAlgorithm *QgsFilterByGeometryAlgorithm::createInstance()
const
84 return new QgsFilterByGeometryAlgorithm();
89 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, u
"INPUT"_s, context ) );
113 std::unique_ptr<QgsFeatureSink> pointSink( parameterAsSink( parameters, u
"POINTS"_s, context, pointSinkId, source->fields(), pointType, source->sourceCrs() ) );
114 if ( parameters.value( u
"POINTS"_s, QVariant() ).isValid() && !pointSink )
118 std::unique_ptr<QgsFeatureSink> lineSink( parameterAsSink( parameters, u
"LINES"_s, context, lineSinkId, source->fields(), lineType, source->sourceCrs() ) );
119 if ( parameters.value( u
"LINES"_s, QVariant() ).isValid() && !lineSink )
122 QString polygonSinkId;
123 std::unique_ptr<QgsFeatureSink> polygonSink( parameterAsSink( parameters, u
"POLYGONS"_s, context, polygonSinkId, source->fields(), polygonType, source->sourceCrs() ) );
124 if ( parameters.value( u
"POLYGONS"_s, QVariant() ).isValid() && !polygonSink )
127 QString noGeomSinkId;
128 std::unique_ptr<QgsFeatureSink> noGeomSink( parameterAsSink( parameters, u
"NO_GEOMETRY"_s, context, noGeomSinkId, source->fields(),
Qgis::WkbType::NoGeometry ) );
129 if ( parameters.value( u
"NO_GEOMETRY"_s, QVariant() ).isValid() && !noGeomSink )
132 const long count = source->featureCount();
133 long long pointCount = 0;
134 long long lineCount = 0;
135 long long polygonCount = 0;
136 long long nullCount = 0;
138 const double step = count > 0 ? 100.0 / count : 1;
209 pointSink->finalize();
211 outputs.insert( u
"POINTS"_s, pointSinkId );
215 lineSink->finalize();
217 outputs.insert( u
"LINES"_s, lineSinkId );
221 polygonSink->finalize();
223 outputs.insert( u
"POLYGONS"_s, polygonSinkId );
228 noGeomSink->finalize();
229 outputs.insert( u
"NO_GEOMETRY"_s, noGeomSinkId );
232 outputs.insert( u
"POINT_COUNT"_s, pointCount );
233 outputs.insert( u
"LINE_COUNT"_s, lineCount );
234 outputs.insert( u
"POLYGON_COUNT"_s, polygonCount );
235 outputs.insert( u
"NO_GEOMETRY_COUNT"_s, nullCount );
245QString QgsFilterByLayerTypeAlgorithm::name()
const
247 return u
"filterlayersbytype"_s;
250QString QgsFilterByLayerTypeAlgorithm::displayName()
const
252 return QObject::tr(
"Filter layers by type" );
255QStringList QgsFilterByLayerTypeAlgorithm::tags()
const
257 return QObject::tr(
"filter,vector,raster,select" ).split(
',' );
260QString QgsFilterByLayerTypeAlgorithm::group()
const
262 return QObject::tr(
"Modeler tools" );
265QString QgsFilterByLayerTypeAlgorithm::groupId()
const
267 return u
"modelertools"_s;
277void QgsFilterByLayerTypeAlgorithm::initAlgorithm(
const QVariantMap & )
286QString QgsFilterByLayerTypeAlgorithm::shortHelpString()
const
289 "This algorithm filters layer by their type. Incoming layers will be directed to different "
290 "outputs based on whether they are a vector or raster layer."
294QString QgsFilterByLayerTypeAlgorithm::shortDescription()
const
296 return QObject::tr(
"Filters layers by type." );
299QgsFilterByLayerTypeAlgorithm *QgsFilterByLayerTypeAlgorithm::createInstance()
const
301 return new QgsFilterByLayerTypeAlgorithm();
306 const QgsMapLayer *layer = parameterAsLayer( parameters, u
"INPUT"_s, context );
312 switch ( layer->
type() )
315 outputs.insert( u
"VECTOR"_s, parameters.value( u
"INPUT"_s ) );
319 outputs.insert( u
"RASTER"_s, parameters.value( u
"INPUT"_s ) );
@ 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.
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ HideFromToolbox
Algorithm should be hidden from the toolbox.
@ PruneModelBranchesBasedOnAlgorithmResults
Algorithm results will cause remaining model branches to be pruned based on the results of running th...
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.
@ 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.
Base class for all map layer types.
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
void featureAddedToSink(const QString &output)
Reports that a feature was added to the the sink associated with the specified algorithm output.
void featureSinkFinalized(const QString &output)
Reports that a feature sink has been finalized.
A numeric output for processing algorithms.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A map layer parameter for processing algorithms.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
A vector layer destination parameter, for specifying the destination path for a vector layer created ...
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static Qgis::WkbType addZ(Qgis::WkbType type)
Adds the z dimension to a WKB type and returns the new type.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static Q_INVOKABLE bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.