22QString QgsFilterByGeometryAlgorithm::name()
const
24 return QStringLiteral(
"filterbygeometry" );
27QString QgsFilterByGeometryAlgorithm::displayName()
const
29 return QObject::tr(
"Filter by geometry type" );
32QStringList QgsFilterByGeometryAlgorithm::tags()
const
34 return QObject::tr(
"extract,filter,geometry,linestring,point,polygon" ).split(
',' );
37QString QgsFilterByGeometryAlgorithm::group()
const
39 return QObject::tr(
"Vector selection" );
42QString QgsFilterByGeometryAlgorithm::groupId()
const
44 return QStringLiteral(
"vectorselection" );
47void QgsFilterByGeometryAlgorithm::initAlgorithm(
const QVariantMap & )
59 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"POINT_COUNT" ), QObject::tr(
"Total count of point features" ) ) );
60 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"LINE_COUNT" ), QObject::tr(
"Total count of line features" ) ) );
61 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"POLYGON_COUNT" ), QObject::tr(
"Total count of polygon features" ) ) );
62 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"NO_GEOMETRY_COUNT" ), QObject::tr(
"Total count of features without geometry" ) ) );
65QString QgsFilterByGeometryAlgorithm::shortHelpString()
const
67 return QObject::tr(
"This algorithm filters features by their geometry type. Incoming features will be directed to different "
68 "outputs based on whether they have a point, line or polygon geometry." );
71QString QgsFilterByGeometryAlgorithm::shortDescription()
const
73 return QObject::tr(
"Filters features by geometry type" );
76QgsFilterByGeometryAlgorithm *QgsFilterByGeometryAlgorithm::createInstance()
const
78 return new QgsFilterByGeometryAlgorithm();
83 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
107 std::unique_ptr<QgsFeatureSink> pointSink( parameterAsSink( parameters, QStringLiteral(
"POINTS" ), context, pointSinkId, source->fields(), pointType, source->sourceCrs() ) );
108 if ( parameters.value( QStringLiteral(
"POINTS" ), QVariant() ).isValid() && !pointSink )
112 std::unique_ptr<QgsFeatureSink> lineSink( parameterAsSink( parameters, QStringLiteral(
"LINES" ), context, lineSinkId, source->fields(), lineType, source->sourceCrs() ) );
113 if ( parameters.value( QStringLiteral(
"LINES" ), QVariant() ).isValid() && !lineSink )
116 QString polygonSinkId;
117 std::unique_ptr<QgsFeatureSink> polygonSink( parameterAsSink( parameters, QStringLiteral(
"POLYGONS" ), context, polygonSinkId, source->fields(), polygonType, source->sourceCrs() ) );
118 if ( parameters.value( QStringLiteral(
"POLYGONS" ), QVariant() ).isValid() && !polygonSink )
121 QString noGeomSinkId;
122 std::unique_ptr<QgsFeatureSink> noGeomSink( parameterAsSink( parameters, QStringLiteral(
"NO_GEOMETRY" ), context, noGeomSinkId, source->fields(),
Qgis::WkbType::NoGeometry ) );
123 if ( parameters.value( QStringLiteral(
"NO_GEOMETRY" ), QVariant() ).isValid() && !noGeomSink )
126 const long count = source->featureCount();
127 long long pointCount = 0;
128 long long lineCount = 0;
129 long long polygonCount = 0;
130 long long nullCount = 0;
132 const double step = count > 0 ? 100.0 / count : 1;
152 throw QgsProcessingException( writeFeatureError( pointSink.get(), parameters, QStringLiteral(
"POINTS" ) ) );
160 throw QgsProcessingException( writeFeatureError( lineSink.get(), parameters, QStringLiteral(
"LINES" ) ) );
168 throw QgsProcessingException( writeFeatureError( polygonSink.get(), parameters, QStringLiteral(
"POLYGONS" ) ) );
182 throw QgsProcessingException( writeFeatureError( noGeomSink.get(), parameters, QStringLiteral(
"NO_GEOMETRY" ) ) );
195 pointSink->finalize();
196 outputs.insert( QStringLiteral(
"POINTS" ), pointSinkId );
200 lineSink->finalize();
201 outputs.insert( QStringLiteral(
"LINES" ), lineSinkId );
205 polygonSink->finalize();
206 outputs.insert( QStringLiteral(
"POLYGONS" ), polygonSinkId );
210 noGeomSink->finalize();
211 outputs.insert( QStringLiteral(
"NO_GEOMETRY" ), noGeomSinkId );
214 outputs.insert( QStringLiteral(
"POINT_COUNT" ), pointCount );
215 outputs.insert( QStringLiteral(
"LINE_COUNT" ), lineCount );
216 outputs.insert( QStringLiteral(
"POLYGON_COUNT" ), polygonCount );
217 outputs.insert( QStringLiteral(
"NO_GEOMETRY_COUNT" ), nullCount );
227QString QgsFilterByLayerTypeAlgorithm::name()
const
229 return QStringLiteral(
"filterlayersbytype" );
232QString QgsFilterByLayerTypeAlgorithm::displayName()
const
234 return QObject::tr(
"Filter layers by type" );
237QStringList QgsFilterByLayerTypeAlgorithm::tags()
const
239 return QObject::tr(
"filter,vector,raster,select" ).split(
',' );
242QString QgsFilterByLayerTypeAlgorithm::group()
const
244 return QObject::tr(
"Modeler tools" );
247QString QgsFilterByLayerTypeAlgorithm::groupId()
const
249 return QStringLiteral(
"modelertools" );
259void QgsFilterByLayerTypeAlgorithm::initAlgorithm(
const QVariantMap & )
268QString QgsFilterByLayerTypeAlgorithm::shortHelpString()
const
270 return QObject::tr(
"This algorithm filters layer by their type. Incoming layers will be directed to different "
271 "outputs based on whether they are a vector or raster layer." );
274QString QgsFilterByLayerTypeAlgorithm::shortDescription()
const
276 return QObject::tr(
"Filters layers by type" );
279QgsFilterByLayerTypeAlgorithm *QgsFilterByLayerTypeAlgorithm::createInstance()
const
281 return new QgsFilterByLayerTypeAlgorithm();
286 const QgsMapLayer *layer = parameterAsLayer( parameters, QStringLiteral(
"INPUT" ), context );
292 switch ( layer->
type() )
295 outputs.insert( QStringLiteral(
"VECTOR" ), parameters.value( QStringLiteral(
"INPUT" ) ) );
299 outputs.insert( QStringLiteral(
"RASTER" ), parameters.value( QStringLiteral(
"INPUT" ) ) );
@ 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 bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.