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 const 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 const double step = count > 0 ? 100.0 / count : 1;
168 throw QgsProcessingException( writeFeatureError( pointSink.get(), parameters, QStringLiteral(
"POINTS" ) ) );
176 throw QgsProcessingException( writeFeatureError( lineSink.get(), parameters, QStringLiteral(
"LINES" ) ) );
184 throw QgsProcessingException( writeFeatureError( polygonSink.get(), parameters, QStringLiteral(
"POLYGONS" ) ) );
198 throw QgsProcessingException( writeFeatureError( noGeomSink.get(), parameters, QStringLiteral(
"NO_GEOMETRY" ) ) );
210 outputs.insert( QStringLiteral(
"POINTS" ), pointSinkId );
212 outputs.insert( QStringLiteral(
"LINES" ), lineSinkId );
214 outputs.insert( QStringLiteral(
"POLYGONS" ), polygonSinkId );
216 outputs.insert( QStringLiteral(
"NO_GEOMETRY" ), noGeomSinkId );
218 outputs.insert( QStringLiteral(
"POINT_COUNT" ), pointCount );
219 outputs.insert( QStringLiteral(
"LINE_COUNT" ), lineCount );
220 outputs.insert( QStringLiteral(
"POLYGON_COUNT" ), polygonCount );
221 outputs.insert( QStringLiteral(
"NO_GEOMETRY_COUNT" ), nullCount );
232 QString QgsFilterByLayerTypeAlgorithm::name()
const
234 return QStringLiteral(
"filterlayersbytype" );
237 QString QgsFilterByLayerTypeAlgorithm::displayName()
const
239 return QObject::tr(
"Filter layers by type" );
242 QStringList QgsFilterByLayerTypeAlgorithm::tags()
const
244 return QObject::tr(
"filter,vector,raster,select" ).split(
',' );
247 QString QgsFilterByLayerTypeAlgorithm::group()
const
249 return QObject::tr(
"Modeler tools" );
252 QString QgsFilterByLayerTypeAlgorithm::groupId()
const
254 return QStringLiteral(
"modelertools" );
257 QgsProcessingAlgorithm::Flags QgsFilterByLayerTypeAlgorithm::flags()
const
260 f |= FlagHideFromToolbox | FlagPruneModelBranchesBasedOnAlgorithmResults;
264 void QgsFilterByLayerTypeAlgorithm::initAlgorithm(
const QVariantMap & )
274 QString QgsFilterByLayerTypeAlgorithm::shortHelpString()
const
276 return QObject::tr(
"This algorithm filters layer by their type. Incoming layers will be directed to different "
277 "outputs based on whether they are a vector or raster layer." );
280 QString QgsFilterByLayerTypeAlgorithm::shortDescription()
const
282 return QObject::tr(
"Filters layers by type" );
285 QgsFilterByLayerTypeAlgorithm *QgsFilterByLayerTypeAlgorithm::createInstance()
const
287 return new QgsFilterByLayerTypeAlgorithm();
292 const QgsMapLayer *layer = parameterAsLayer( parameters, QStringLiteral(
"INPUT" ), context );
298 switch ( layer->
type() )
301 outputs.insert( QStringLiteral(
"VECTOR" ), parameters.value( QStringLiteral(
"INPUT" ) ) );
305 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
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.