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" ) ) );