22 QString QgsFilterByGeometryAlgorithm::name()
const
24 return QStringLiteral(
"filterbygeometry" );
27 QString QgsFilterByGeometryAlgorithm::displayName()
const
29 return QObject::tr(
"Filter by geometry type" );
32 QStringList QgsFilterByGeometryAlgorithm::tags()
const
34 return QObject::tr(
"extract,filter,geometry,linestring,point,polygon" ).split(
',' );
37 QString QgsFilterByGeometryAlgorithm::group()
const
39 return QObject::tr(
"Modeler tools" );
42 QString QgsFilterByGeometryAlgorithm::groupId()
const
44 return QStringLiteral(
"modelertools" );
47 QgsProcessingAlgorithm::Flags QgsFilterByGeometryAlgorithm::flags()
const
54 void QgsFilterByGeometryAlgorithm::initAlgorithm(
const QVariantMap & )
71 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"POINT_COUNT" ), QObject::tr(
"Total count of point features" ) ) );
72 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"LINE_COUNT" ), QObject::tr(
"Total count of line features" ) ) );
73 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"POLYGON_COUNT" ), QObject::tr(
"Total count of polygon features" ) ) );
74 addOutput(
new QgsProcessingOutputNumber( QStringLiteral(
"NO_GEOMETRY_COUNT" ), QObject::tr(
"Total count of features without geometry" ) ) );
77 QString QgsFilterByGeometryAlgorithm::shortHelpString()
const
79 return QObject::tr(
"This algorithm filters features by their geometry type. Incoming features will be directed to different "
80 "outputs based on whether they have a point, line or polygon geometry." );
83 QString QgsFilterByGeometryAlgorithm::shortDescription()
const
85 return QObject::tr(
"Filters features by geometry type" );
88 QgsFilterByGeometryAlgorithm *QgsFilterByGeometryAlgorithm::createInstance()
const
90 return new QgsFilterByGeometryAlgorithm();
95 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
119 std::unique_ptr< QgsFeatureSink > pointSink( parameterAsSink( parameters, QStringLiteral(
"POINTS" ), context, pointSinkId, source->fields(),
120 pointType, source->sourceCrs() ) );
121 if ( parameters.value( QStringLiteral(
"POINTS" ), QVariant() ).isValid() && !pointSink )
125 std::unique_ptr< QgsFeatureSink > lineSink( parameterAsSink( parameters, QStringLiteral(
"LINES" ), context, lineSinkId, source->fields(),
126 lineType, source->sourceCrs() ) );
127 if ( parameters.value( QStringLiteral(
"LINES" ), QVariant() ).isValid() && !lineSink )
130 QString polygonSinkId;
131 std::unique_ptr< QgsFeatureSink > polygonSink( parameterAsSink( parameters, QStringLiteral(
"POLYGONS" ), context, polygonSinkId, source->fields(),
132 polygonType, source->sourceCrs() ) );
133 if ( parameters.value( QStringLiteral(
"POLYGONS" ), QVariant() ).isValid() && !polygonSink )
136 QString noGeomSinkId;
137 std::unique_ptr< QgsFeatureSink > noGeomSink( parameterAsSink( parameters, QStringLiteral(
"NO_GEOMETRY" ), context, noGeomSinkId, source->fields(),
139 if ( parameters.value( QStringLiteral(
"NO_GEOMETRY" ), QVariant() ).isValid() && !noGeomSink )
142 long count = source->featureCount();
143 long long pointCount = 0;
144 long long lineCount = 0;
145 long long polygonCount = 0;
146 long long nullCount = 0;
148 double step = count > 0 ? 100.0 / count : 1;
206 outputs.insert( QStringLiteral(
"POINTS" ), pointSinkId );
208 outputs.insert( QStringLiteral(
"LINES" ), lineSinkId );
210 outputs.insert( QStringLiteral(
"POLYGONS" ), polygonSinkId );
212 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 );
228 QString QgsFilterByLayerTypeAlgorithm::name()
const
230 return QStringLiteral(
"filterlayersbytype" );
233 QString QgsFilterByLayerTypeAlgorithm::displayName()
const
235 return QObject::tr(
"Filter layers by type" );
238 QStringList QgsFilterByLayerTypeAlgorithm::tags()
const
240 return QObject::tr(
"filter,vector,raster,select" ).split(
',' );
243 QString QgsFilterByLayerTypeAlgorithm::group()
const
245 return QObject::tr(
"Modeler tools" );
248 QString QgsFilterByLayerTypeAlgorithm::groupId()
const
250 return QStringLiteral(
"modelertools" );
253 QgsProcessingAlgorithm::Flags QgsFilterByLayerTypeAlgorithm::flags()
const
256 f |= FlagHideFromToolbox | FlagPruneModelBranchesBasedOnAlgorithmResults;
260 void QgsFilterByLayerTypeAlgorithm::initAlgorithm(
const QVariantMap & )
270 QString QgsFilterByLayerTypeAlgorithm::shortHelpString()
const
272 return QObject::tr(
"This algorithm filters layer by their type. Incoming layers will be directed to different "
273 "outputs based on whether they are a vector or raster layer." );
276 QString QgsFilterByLayerTypeAlgorithm::shortDescription()
const
278 return QObject::tr(
"Filters layers by type" );
281 QgsFilterByLayerTypeAlgorithm *QgsFilterByLayerTypeAlgorithm::createInstance()
const
283 return new QgsFilterByLayerTypeAlgorithm();
288 const QgsMapLayer *layer = parameterAsLayer( parameters, QStringLiteral(
"INPUT" ), context );
294 switch ( layer->
type() )
297 outputs.insert( QStringLiteral(
"VECTOR" ), parameters.value( QStringLiteral(
"INPUT" ) ) );
301 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.
@ FlagHideFromToolbox
Algorithm should be hidden from the toolbox.
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
Added in 3.18.
@ VectorTileLayer
Added in 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.