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 QGS_MARK_ALGORITHM_SOURCE
91 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, u
"INPUT"_s, context ) );
115 std::unique_ptr<QgsFeatureSink> pointSink( parameterAsSink( parameters, u
"POINTS"_s, context, pointSinkId, source->fields(), pointType, source->sourceCrs() ) );
116 if ( parameters.value( u
"POINTS"_s, QVariant() ).isValid() && !pointSink )
120 std::unique_ptr<QgsFeatureSink> lineSink( parameterAsSink( parameters, u
"LINES"_s, context, lineSinkId, source->fields(), lineType, source->sourceCrs() ) );
121 if ( parameters.value( u
"LINES"_s, QVariant() ).isValid() && !lineSink )
124 QString polygonSinkId;
125 std::unique_ptr<QgsFeatureSink> polygonSink( parameterAsSink( parameters, u
"POLYGONS"_s, context, polygonSinkId, source->fields(), polygonType, source->sourceCrs() ) );
126 if ( parameters.value( u
"POLYGONS"_s, QVariant() ).isValid() && !polygonSink )
129 QString noGeomSinkId;
130 std::unique_ptr<QgsFeatureSink> noGeomSink( parameterAsSink( parameters, u
"NO_GEOMETRY"_s, context, noGeomSinkId, source->fields(),
Qgis::WkbType::NoGeometry ) );
131 if ( parameters.value( u
"NO_GEOMETRY"_s, QVariant() ).isValid() && !noGeomSink )
134 const long count = source->featureCount();
135 long long pointCount = 0;
136 long long lineCount = 0;
137 long long polygonCount = 0;
138 long long nullCount = 0;
140 const double step = count > 0 ? 100.0 / count : 1;
211 pointSink->finalize();
213 outputs.insert( u
"POINTS"_s, pointSinkId );
217 lineSink->finalize();
219 outputs.insert( u
"LINES"_s, lineSinkId );
223 polygonSink->finalize();
225 outputs.insert( u
"POLYGONS"_s, polygonSinkId );
230 noGeomSink->finalize();
231 outputs.insert( u
"NO_GEOMETRY"_s, noGeomSinkId );
234 outputs.insert( u
"POINT_COUNT"_s, pointCount );
235 outputs.insert( u
"LINE_COUNT"_s, lineCount );
236 outputs.insert( u
"POLYGON_COUNT"_s, polygonCount );
237 outputs.insert( u
"NO_GEOMETRY_COUNT"_s, nullCount );
247QString QgsFilterByLayerTypeAlgorithm::name()
const
249 return u
"filterlayersbytype"_s;
252QString QgsFilterByLayerTypeAlgorithm::displayName()
const
254 return QObject::tr(
"Filter layers by type" );
257QStringList QgsFilterByLayerTypeAlgorithm::tags()
const
259 return QObject::tr(
"filter,vector,raster,select" ).split(
',' );
262QString QgsFilterByLayerTypeAlgorithm::group()
const
264 return QObject::tr(
"Modeler tools" );
267QString QgsFilterByLayerTypeAlgorithm::groupId()
const
269 return u
"modelertools"_s;
279void QgsFilterByLayerTypeAlgorithm::initAlgorithm(
const QVariantMap & )
288QString QgsFilterByLayerTypeAlgorithm::shortHelpString()
const
291 "This algorithm filters layer by their type. Incoming layers will be directed to different "
292 "outputs based on whether they are a vector or raster layer."
296QString QgsFilterByLayerTypeAlgorithm::shortDescription()
const
298 return QObject::tr(
"Filters layers by type." );
301QgsFilterByLayerTypeAlgorithm *QgsFilterByLayerTypeAlgorithm::createInstance()
const
303 return new QgsFilterByLayerTypeAlgorithm();
308 const QgsMapLayer *layer = parameterAsLayer( parameters, u
"INPUT"_s, context );
314 switch ( layer->
type() )
317 outputs.insert( u
"VECTOR"_s, parameters.value( u
"INPUT"_s ) );
321 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.