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(
"Vector selection" );
42 QString QgsFilterByGeometryAlgorithm::groupId()
const
44 return QStringLiteral(
"vectorselection" );
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(
"Layer tools" );
248 QString QgsFilterByLayerTypeAlgorithm::groupId()
const
250 return QStringLiteral(
"layertools" );
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" ) ) );