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 & )
64 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"POINT_COUNT" ), QObject::tr(
"Total count of point features" ) ) );
65 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"LINE_COUNT" ), QObject::tr(
"Total count of line features" ) ) );
66 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"POLYGON_COUNT" ), QObject::tr(
"Total count of polygon features" ) ) );
67 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"NO_GEOMETRY_COUNT" ), QObject::tr(
"Total count of features without geometry" ) ) );
70QString QgsFilterByGeometryAlgorithm::shortHelpString()
const
72 return QObject::tr(
"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." );
76QString QgsFilterByGeometryAlgorithm::shortDescription()
const
78 return QObject::tr(
"Filters features by geometry type" );
81QgsFilterByGeometryAlgorithm *QgsFilterByGeometryAlgorithm::createInstance()
const
83 return new QgsFilterByGeometryAlgorithm();
88 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
112 std::unique_ptr< QgsFeatureSink > pointSink( parameterAsSink( parameters, QStringLiteral(
"POINTS" ), context, pointSinkId, source->fields(),
113 pointType, source->sourceCrs() ) );
114 if ( parameters.value( QStringLiteral(
"POINTS" ), QVariant() ).isValid() && !pointSink )
118 std::unique_ptr< QgsFeatureSink > lineSink( parameterAsSink( parameters, QStringLiteral(
"LINES" ), context, lineSinkId, source->fields(),
119 lineType, source->sourceCrs() ) );
120 if ( parameters.value( QStringLiteral(
"LINES" ), QVariant() ).isValid() && !lineSink )
123 QString polygonSinkId;
124 std::unique_ptr< QgsFeatureSink > polygonSink( parameterAsSink( parameters, QStringLiteral(
"POLYGONS" ), context, polygonSinkId, source->fields(),
125 polygonType, source->sourceCrs() ) );
126 if ( parameters.value( QStringLiteral(
"POLYGONS" ), QVariant() ).isValid() && !polygonSink )
129 QString noGeomSinkId;
130 std::unique_ptr< QgsFeatureSink > noGeomSink( parameterAsSink( parameters, QStringLiteral(
"NO_GEOMETRY" ), context, noGeomSinkId, source->fields(),
132 if ( parameters.value( QStringLiteral(
"NO_GEOMETRY" ), QVariant() ).isValid() && !noGeomSink )
135 const long count = source->featureCount();
136 long long pointCount = 0;
137 long long lineCount = 0;
138 long long polygonCount = 0;
139 long long nullCount = 0;
141 const double step = count > 0 ? 100.0 / count : 1;
161 throw QgsProcessingException( writeFeatureError( pointSink.get(), parameters, QStringLiteral(
"POINTS" ) ) );
169 throw QgsProcessingException( writeFeatureError( lineSink.get(), parameters, QStringLiteral(
"LINES" ) ) );
177 throw QgsProcessingException( writeFeatureError( polygonSink.get(), parameters, QStringLiteral(
"POLYGONS" ) ) );
191 throw QgsProcessingException( writeFeatureError( noGeomSink.get(), parameters, QStringLiteral(
"NO_GEOMETRY" ) ) );
203 outputs.insert( QStringLiteral(
"POINTS" ), pointSinkId );
205 outputs.insert( QStringLiteral(
"LINES" ), lineSinkId );
207 outputs.insert( QStringLiteral(
"POLYGONS" ), polygonSinkId );
209 outputs.insert( QStringLiteral(
"NO_GEOMETRY" ), noGeomSinkId );
211 outputs.insert( QStringLiteral(
"POINT_COUNT" ), pointCount );
212 outputs.insert( QStringLiteral(
"LINE_COUNT" ), lineCount );
213 outputs.insert( QStringLiteral(
"POLYGON_COUNT" ), polygonCount );
214 outputs.insert( QStringLiteral(
"NO_GEOMETRY_COUNT" ), nullCount );
225QString QgsFilterByLayerTypeAlgorithm::name()
const
227 return QStringLiteral(
"filterlayersbytype" );
230QString QgsFilterByLayerTypeAlgorithm::displayName()
const
232 return QObject::tr(
"Filter layers by type" );
235QStringList QgsFilterByLayerTypeAlgorithm::tags()
const
237 return QObject::tr(
"filter,vector,raster,select" ).split(
',' );
240QString QgsFilterByLayerTypeAlgorithm::group()
const
242 return QObject::tr(
"Modeler tools" );
245QString QgsFilterByLayerTypeAlgorithm::groupId()
const
247 return QStringLiteral(
"modelertools" );
250QgsProcessingAlgorithm::Flags QgsFilterByLayerTypeAlgorithm::flags()
const
253 f |= FlagHideFromToolbox | FlagPruneModelBranchesBasedOnAlgorithmResults;
257void QgsFilterByLayerTypeAlgorithm::initAlgorithm(
const QVariantMap & )
267QString QgsFilterByLayerTypeAlgorithm::shortHelpString()
const
269 return QObject::tr(
"This algorithm filters layer by their type. Incoming layers will be directed to different "
270 "outputs based on whether they are a vector or raster layer." );
273QString QgsFilterByLayerTypeAlgorithm::shortDescription()
const
275 return QObject::tr(
"Filters layers by type" );
278QgsFilterByLayerTypeAlgorithm *QgsFilterByLayerTypeAlgorithm::createInstance()
const
280 return new QgsFilterByLayerTypeAlgorithm();
285 const QgsMapLayer *layer = parameterAsLayer( parameters, QStringLiteral(
"INPUT" ), context );
291 switch ( layer->
type() )
294 outputs.insert( QStringLiteral(
"VECTOR" ), parameters.value( QStringLiteral(
"INPUT" ) ) );
298 outputs.insert( QStringLiteral(
"RASTER" ), parameters.value( QStringLiteral(
"INPUT" ) ) );
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
@ 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 SIP_HOLDGIL
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
QgsWkbTypes::GeometryType type
Base class for all map layer types.
virtual Flags 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 ...
@ TypeVectorLine
Vector line layers.
@ TypeVectorPolygon
Vector polygon layers.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ TypeVectorPoint
Vector point layers.
@ TypeVectorAnyGeometry
Any vector layer with geometry.
static bool hasM(Type type) SIP_HOLDGIL
Tests whether a WKB type contains m values.
Type
The WKB type describes the number of dimensions a geometry has.
static Type addZ(Type type) SIP_HOLDGIL
Adds the z dimension to a WKB type and returns the new type.
static bool hasZ(Type type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
static Type addM(Type type) SIP_HOLDGIL
Adds the m dimension to a WKB type and returns the new type.
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
@ VectorLayer
Vector layer.
@ RasterLayer
Raster layer.
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ PluginLayer
Plugin based layer.