24using namespace Qt::StringLiterals;
29QString QgsIntersectionAlgorithm::name()
const
31 return u
"intersection"_s;
34QString QgsIntersectionAlgorithm::displayName()
const
36 return QObject::tr(
"Intersection" );
39QStringList QgsIntersectionAlgorithm::tags()
const
41 return QObject::tr(
"intersect,intersection,overlap" ).split(
',' );
44QString QgsIntersectionAlgorithm::group()
const
46 return QObject::tr(
"Vector overlay" );
49QString QgsIntersectionAlgorithm::groupId()
const
51 return u
"vectoroverlay"_s;
54QString QgsIntersectionAlgorithm::shortHelpString()
const
57 "This algorithm extracts the overlapping portions of features in the Input and Overlay layers. "
58 "Features in the output Intersection layer are assigned the attributes of the overlapping features "
59 "from both the Input and Overlay layers."
63QString QgsIntersectionAlgorithm::shortDescription()
const
65 return QObject::tr(
"Extracts overlapping portions of features between two layers." );
75 return new QgsIntersectionAlgorithm();
78void QgsIntersectionAlgorithm::initAlgorithm(
const QVariantMap & )
90 auto prefix = std::make_unique<QgsProcessingParameterString>( u
"OVERLAY_FIELDS_PREFIX"_s, QObject::tr(
"Overlay fields prefix" ), QString(),
false,
true );
92 addParameter( prefix.release() );
98 addParameter( gridSize.release() );
104 QGS_MARK_ALGORITHM_SOURCE
106 std::unique_ptr<QgsFeatureSource> sourceA( parameterAsSource( parameters, u
"INPUT"_s, context ) );
110 std::unique_ptr<QgsFeatureSource> sourceB( parameterAsSource( parameters, u
"OVERLAY"_s, context ) );
116 const QStringList fieldsA = parameterAsStrings( parameters, u
"INPUT_FIELDS"_s, context );
117 const QStringList fieldsB = parameterAsStrings( parameters, u
"OVERLAY_FIELDS"_s, context );
122 const QString overlayFieldsPrefix = parameterAsString( parameters, u
"OVERLAY_FIELDS_PREFIX"_s, context );
127 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, u
"OUTPUT"_s, context, dest, outputFields, geomType, sourceA->sourceCrs(),
QgsFeatureSink::RegeneratePrimaryKey ) );
132 outputs.insert( u
"OUTPUT"_s, dest );
135 const long total = sourceA->featureCount();
138 if ( parameters.value( u
"GRID_SIZE"_s ).isValid() )
140 geometryParameters.
setGridSize( parameterAsDouble( parameters, u
"GRID_SIZE"_s, context ) );
143 QgsOverlayUtils::intersection( *sourceA, *sourceB, *sink, u
"OUTPUT"_s, context, feedback, count, total, fieldIndicesA, fieldIndicesB, geometryParameters );
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
@ Double
Double/float values.
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
Container of fields for a vector layer.
Encapsulates parameters under which a geometry operation is performed.
void setGridSize(double size)
Sets the grid size which will be used to snap vertices of a geometry.
Abstract base class for processing algorithms.
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.
void featureSinkFinalized(const QString &output)
Reports that a feature sink has been finalized.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A vector layer or feature source field parameter for processing algorithms.
static QgsFields indicesToFields(const QList< int > &indices, const QgsFields &fields)
Returns a subset of fields based on the indices of desired fields.
static QList< int > fieldNamesToIndices(const QStringList &fieldNames, const QgsFields &fields)
Returns a list of field indices parsed from the given list of field names.
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix=QString())
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
static Qgis::WkbType multiType(Qgis::WkbType type)
Returns the multi type for a WKB type.