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
71 return QObject::tr(
"This algorithm filters features by their geometry type. Incoming features will be directed to different "
72 "outputs based on whether they have a point, line or polygon geometry." );
75QString QgsFilterByGeometryAlgorithm::shortDescription()
const
77 return QObject::tr(
"Filters features by geometry type." );
80QgsFilterByGeometryAlgorithm *QgsFilterByGeometryAlgorithm::createInstance()
const
82 return new QgsFilterByGeometryAlgorithm();
87 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, u
"INPUT"_s, context ) );
111 std::unique_ptr<QgsFeatureSink> pointSink( parameterAsSink( parameters, u
"POINTS"_s, context, pointSinkId, source->fields(), pointType, source->sourceCrs() ) );
112 if ( parameters.value( u
"POINTS"_s, QVariant() ).isValid() && !pointSink )
116 std::unique_ptr<QgsFeatureSink> lineSink( parameterAsSink( parameters, u
"LINES"_s, context, lineSinkId, source->fields(), lineType, source->sourceCrs() ) );
117 if ( parameters.value( u
"LINES"_s, QVariant() ).isValid() && !lineSink )
120 QString polygonSinkId;
121 std::unique_ptr<QgsFeatureSink> polygonSink( parameterAsSink( parameters, u
"POLYGONS"_s, context, polygonSinkId, source->fields(), polygonType, source->sourceCrs() ) );
122 if ( parameters.value( u
"POLYGONS"_s, QVariant() ).isValid() && !polygonSink )
125 QString noGeomSinkId;
126 std::unique_ptr<QgsFeatureSink> noGeomSink( parameterAsSink( parameters, u
"NO_GEOMETRY"_s, context, noGeomSinkId, source->fields(),
Qgis::WkbType::NoGeometry ) );
127 if ( parameters.value( u
"NO_GEOMETRY"_s, QVariant() ).isValid() && !noGeomSink )
130 const long count = source->featureCount();
131 long long pointCount = 0;
132 long long lineCount = 0;
133 long long polygonCount = 0;
134 long long nullCount = 0;
136 const double step = count > 0 ? 100.0 / count : 1;
199 pointSink->finalize();
200 outputs.insert( u
"POINTS"_s, pointSinkId );
204 lineSink->finalize();
205 outputs.insert( u
"LINES"_s, lineSinkId );
209 polygonSink->finalize();
210 outputs.insert( u
"POLYGONS"_s, polygonSinkId );
214 noGeomSink->finalize();
215 outputs.insert( u
"NO_GEOMETRY"_s, noGeomSinkId );
218 outputs.insert( u
"POINT_COUNT"_s, pointCount );
219 outputs.insert( u
"LINE_COUNT"_s, lineCount );
220 outputs.insert( u
"POLYGON_COUNT"_s, polygonCount );
221 outputs.insert( u
"NO_GEOMETRY_COUNT"_s, nullCount );
231QString QgsFilterByLayerTypeAlgorithm::name()
const
233 return u
"filterlayersbytype"_s;
236QString QgsFilterByLayerTypeAlgorithm::displayName()
const
238 return QObject::tr(
"Filter layers by type" );
241QStringList QgsFilterByLayerTypeAlgorithm::tags()
const
243 return QObject::tr(
"filter,vector,raster,select" ).split(
',' );
246QString QgsFilterByLayerTypeAlgorithm::group()
const
248 return QObject::tr(
"Modeler tools" );
251QString QgsFilterByLayerTypeAlgorithm::groupId()
const
253 return u
"modelertools"_s;
263void QgsFilterByLayerTypeAlgorithm::initAlgorithm(
const QVariantMap & )
272QString QgsFilterByLayerTypeAlgorithm::shortHelpString()
const
274 return QObject::tr(
"This algorithm filters layer by their type. Incoming layers will be directed to different "
275 "outputs based on whether they are a vector or raster layer." );
278QString QgsFilterByLayerTypeAlgorithm::shortDescription()
const
280 return QObject::tr(
"Filters layers by type." );
283QgsFilterByLayerTypeAlgorithm *QgsFilterByLayerTypeAlgorithm::createInstance()
const
285 return new QgsFilterByLayerTypeAlgorithm();
290 const QgsMapLayer *layer = parameterAsLayer( parameters, u
"INPUT"_s, context );
296 switch ( layer->
type() )
299 outputs.insert( u
"VECTOR"_s, parameters.value( u
"INPUT"_s ) );
303 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.