28 QString QgsMultiIntersectionAlgorithm::name()
const
30 return QStringLiteral(
"multiintersection" );
33 QString QgsMultiIntersectionAlgorithm::displayName()
const
35 return QObject::tr(
"Intersection (multiple)" );
38 QStringList QgsMultiIntersectionAlgorithm::tags()
const
40 return QObject::tr(
"intersection,extract,overlap" ).split(
',' );
43 QString QgsMultiIntersectionAlgorithm::group()
const
45 return QObject::tr(
"Vector overlay" );
48 QString QgsMultiIntersectionAlgorithm::groupId()
const
50 return QStringLiteral(
"vectoroverlay" );
53 QString QgsMultiIntersectionAlgorithm::shortHelpString()
const
55 return QObject::tr(
"This algorithm extracts the overlapping portions of features in the Input and all Overlay layers. "
56 "Features in the output layer are assigned the attributes of the overlapping features "
57 "from both the Input and Overlay layers." );
62 return new QgsMultiIntersectionAlgorithm();
65 void QgsMultiIntersectionAlgorithm::initAlgorithm(
const QVariantMap & )
70 std::unique_ptr< QgsProcessingParameterString > prefix = std::make_unique< QgsProcessingParameterString >( QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), QObject::tr(
"Overlay fields prefix" ), QString(),
false,
true );
72 addParameter( prefix.release() );
79 std::unique_ptr< QgsFeatureSource > sourceA( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
83 const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral(
"OVERLAYS" ), context );
86 long totalLayerCount = 0;
101 const QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), context );
105 std::unique_ptr< QgsFeatureSink > sink;
109 QList<int> fieldIndicesA, fieldIndicesB;
112 if ( totalLayerCount == 1 )
114 QgsVectorLayer *overlayLayer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
122 overlayFieldsPrefix );
129 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
131 const long total = sourceA->featureCount();
132 QgsOverlayUtils::intersection( *sourceA, *overlayLayer, *sink, context, feedback, count, total, fieldIndicesA, fieldIndicesB );
145 multiStepFeedback.setCurrentStep( i );
150 QgsVectorLayer *overlayLayer = qobject_cast< QgsVectorLayer * >( layer );
163 overlayFieldsPrefix );
165 QString
id = QStringLiteral(
"memory:" );
167 QgsOverlayUtils::intersection( *sourceA, *overlayLayer, *sink, context, &multiStepFeedback, count, sourceA->featureCount(), fieldIndicesA, fieldIndicesB );
171 else if ( i == totalLayerCount - 1 )
179 overlayFieldsPrefix );
182 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, outputFields, geometryType,
crs ) );
186 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
188 QgsOverlayUtils::intersection( *intersectionLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, intersectionLayer->
featureCount(), fieldIndicesA, fieldIndicesB );
198 overlayFieldsPrefix );
200 QString
id = QStringLiteral(
"memory:" );
202 QgsOverlayUtils::intersection( *intersectionLayer, *overlayLayer, *sink, context, &multiStepFeedback, count, intersectionLayer->
featureCount(), fieldIndicesA, fieldIndicesB );