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;
201 pointSink->finalize();
202 outputs.insert( u
"POINTS"_s, pointSinkId );
206 lineSink->finalize();
207 outputs.insert( u
"LINES"_s, lineSinkId );
211 polygonSink->finalize();
212 outputs.insert( u
"POLYGONS"_s, polygonSinkId );
216 noGeomSink->finalize();
217 outputs.insert( u
"NO_GEOMETRY"_s, noGeomSinkId );
220 outputs.insert( u
"POINT_COUNT"_s, pointCount );
221 outputs.insert( u
"LINE_COUNT"_s, lineCount );
222 outputs.insert( u
"POLYGON_COUNT"_s, polygonCount );
223 outputs.insert( u
"NO_GEOMETRY_COUNT"_s, nullCount );
233QString QgsFilterByLayerTypeAlgorithm::name()
const
235 return u
"filterlayersbytype"_s;
238QString QgsFilterByLayerTypeAlgorithm::displayName()
const
240 return QObject::tr(
"Filter layers by type" );
243QStringList QgsFilterByLayerTypeAlgorithm::tags()
const
245 return QObject::tr(
"filter,vector,raster,select" ).split(
',' );
248QString QgsFilterByLayerTypeAlgorithm::group()
const
250 return QObject::tr(
"Modeler tools" );
253QString QgsFilterByLayerTypeAlgorithm::groupId()
const
255 return u
"modelertools"_s;
265void QgsFilterByLayerTypeAlgorithm::initAlgorithm(
const QVariantMap & )
274QString QgsFilterByLayerTypeAlgorithm::shortHelpString()
const
277 "This algorithm filters layer by their type. Incoming layers will be directed to different "
278 "outputs based on whether they are a vector or raster layer."
282QString QgsFilterByLayerTypeAlgorithm::shortDescription()
const
284 return QObject::tr(
"Filters layers by type." );
287QgsFilterByLayerTypeAlgorithm *QgsFilterByLayerTypeAlgorithm::createInstance()
const
289 return new QgsFilterByLayerTypeAlgorithm();
294 const QgsMapLayer *layer = parameterAsLayer( parameters, u
"INPUT"_s, context );
300 switch ( layer->
type() )
303 outputs.insert( u
"VECTOR"_s, parameters.value( u
"INPUT"_s ) );
307 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.
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.