22 QString QgsRemoveNullGeometryAlgorithm::name()
const
24 return QStringLiteral(
"removenullgeometries" );
27 QString QgsRemoveNullGeometryAlgorithm::displayName()
const
29 return QObject::tr(
"Remove null geometries" );
32 QStringList QgsRemoveNullGeometryAlgorithm::tags()
const
34 return QObject::tr(
"remove,drop,delete,empty,geometry" ).split(
',' );
37 QString QgsRemoveNullGeometryAlgorithm::group()
const
39 return QObject::tr(
"Vector geometry" );
42 QString QgsRemoveNullGeometryAlgorithm::groupId()
const
44 return QStringLiteral(
"vectorgeometry" );
47 void QgsRemoveNullGeometryAlgorithm::initAlgorithm(
const QVariantMap & )
57 addParameter( nullOutput );
60 QString QgsRemoveNullGeometryAlgorithm::shortHelpString()
const
62 return QObject::tr(
"This algorithm removes any features which do not have a geometry from a vector layer. "
63 "All other features will be copied unchanged.\n\n"
64 "Optionally, the features with null geometries can be saved to a separate output.\n\n"
65 "If 'Also remove empty geometries' is checked, the algorithm removes features whose geometries "
66 "have no coordinates, i.e., geometries that are empty. In that case, also the null "
67 "output will reflect this option, containing both null and empty geometries." );
70 QgsRemoveNullGeometryAlgorithm *QgsRemoveNullGeometryAlgorithm::createInstance()
const
72 return new QgsRemoveNullGeometryAlgorithm();
77 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
81 const bool removeEmpty = parameterAsBoolean( parameters, QStringLiteral(
"REMOVE_EMPTY" ), context );
83 QString nonNullSinkId;
84 std::unique_ptr< QgsFeatureSink > nonNullSink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, nonNullSinkId, source->fields(),
85 source->wkbType(), source->sourceCrs() ) );
88 std::unique_ptr< QgsFeatureSink > nullSink( parameterAsSink( parameters, QStringLiteral(
"NULL_OUTPUT" ), context, nullSinkId, source->fields() ) );
90 const long count = source->featureCount();
92 const double step = count > 0 ? 100.0 / count : 1;
107 throw QgsProcessingException( writeFeatureError( nonNullSink.get(), parameters, QStringLiteral(
"OUTPUT" ) ) );
112 throw QgsProcessingException( writeFeatureError( nullSink.get(), parameters, QStringLiteral(
"NULL_OUTPUT" ) ) );
121 outputs.insert( QStringLiteral(
"OUTPUT" ), nonNullSinkId );
123 outputs.insert( QStringLiteral(
"NULL_OUTPUT" ), nullSinkId );