25QString QgsIntersectionAlgorithm::name()
const
27 return QStringLiteral(
"intersection" );
30QString QgsIntersectionAlgorithm::displayName()
const
32 return QObject::tr(
"Intersection" );
35QString QgsIntersectionAlgorithm::group()
const
37 return QObject::tr(
"Vector overlay" );
40QString QgsIntersectionAlgorithm::groupId()
const
42 return QStringLiteral(
"vectoroverlay" );
45QString QgsIntersectionAlgorithm::shortHelpString()
const
47 return QObject::tr(
"This algorithm extracts the overlapping portions of features in the Input and Overlay layers. "
48 "Features in the output Intersection layer are assigned the attributes of the overlapping features "
49 "from both the Input and Overlay layers." );
54 return new QgsIntersectionAlgorithm();
57void QgsIntersectionAlgorithm::initAlgorithm(
const QVariantMap & )
63 QStringLiteral(
"INPUT_FIELDS" ),
64 QObject::tr(
"Input fields to keep (leave empty to keep all fields)" ), QVariant(),
67 QStringLiteral(
"OVERLAY_FIELDS" ),
68 QObject::tr(
"Overlay fields to keep (leave empty to keep all fields)" ), QVariant(),
71 std::unique_ptr< QgsProcessingParameterString > prefix = std::make_unique< QgsProcessingParameterString >( QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), QObject::tr(
"Overlay fields prefix" ), QString(),
false,
true );
73 addParameter( prefix.release() );
77 std::unique_ptr< QgsProcessingParameterNumber > gridSize = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"GRID_SIZE" ),
80 addParameter( gridSize.release() );
86 std::unique_ptr< QgsFeatureSource > sourceA( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
90 std::unique_ptr< QgsFeatureSource > sourceB( parameterAsSource( parameters, QStringLiteral(
"OVERLAY" ), context ) );
96 const QStringList fieldsA = parameterAsStrings( parameters, QStringLiteral(
"INPUT_FIELDS" ), context );
97 const QStringList fieldsB = parameterAsStrings( parameters, QStringLiteral(
"OVERLAY_FIELDS" ), context );
102 const QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral(
"OVERLAY_FIELDS_PREFIX" ), context );
106 overlayFieldsPrefix );
109 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, outputFields, geomType, sourceA->sourceCrs(),
QgsFeatureSink::RegeneratePrimaryKey ) );
114 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
117 const long total = sourceA->featureCount();
120 if ( parameters.value( QStringLiteral(
"GRID_SIZE" ) ).isValid() )
122 geometryParameters.
setGridSize( parameterAsDouble( parameters, QStringLiteral(
"GRID_SIZE" ), context ) );
125 QgsOverlayUtils::intersection( *sourceA, *sourceB, *sink, context, feedback, count, total, fieldIndicesA, fieldIndicesB, geometryParameters );
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.
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.