LCOV - code coverage report
Current view: top level - analysis/processing - qgsalgorithmsymmetricaldifference.cpp (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 45 0.0 %
Date: 2021-03-26 12:19:53 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :   qgsalgorithmsymmetricaldifference.cpp
       3                 :            :   ---------------------
       4                 :            :   Date                 : April 2018
       5                 :            :   Copyright            : (C) 2018 by Martin Dobias
       6                 :            :   Email                : wonder dot sk at gmail dot com
       7                 :            :  ***************************************************************************
       8                 :            :  *                                                                         *
       9                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      10                 :            :  *   it under the terms of the GNU General Public License as published by  *
      11                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      12                 :            :  *   (at your option) any later version.                                   *
      13                 :            :  *                                                                         *
      14                 :            :  ***************************************************************************/
      15                 :            : 
      16                 :            : #include "qgsalgorithmsymmetricaldifference.h"
      17                 :            : 
      18                 :            : #include "qgsoverlayutils.h"
      19                 :            : 
      20                 :            : ///@cond PRIVATE
      21                 :            : 
      22                 :          0 : QString QgsSymmetricalDifferenceAlgorithm::name() const
      23                 :            : {
      24                 :          0 :   return QStringLiteral( "symmetricaldifference" );
      25                 :            : }
      26                 :            : 
      27                 :          0 : QString QgsSymmetricalDifferenceAlgorithm::displayName() const
      28                 :            : {
      29                 :          0 :   return QObject::tr( "Symmetrical difference" );
      30                 :            : }
      31                 :            : 
      32                 :          0 : QStringList QgsSymmetricalDifferenceAlgorithm::tags() const
      33                 :            : {
      34                 :          0 :   return QObject::tr( "difference,symdiff,not overlap" ).split( ',' );
      35                 :          0 : }
      36                 :            : 
      37                 :          0 : QString QgsSymmetricalDifferenceAlgorithm::group() const
      38                 :            : {
      39                 :          0 :   return QObject::tr( "Vector overlay" );
      40                 :            : }
      41                 :            : 
      42                 :          0 : QString QgsSymmetricalDifferenceAlgorithm::groupId() const
      43                 :            : {
      44                 :          0 :   return QStringLiteral( "vectoroverlay" );
      45                 :            : }
      46                 :            : 
      47                 :          0 : QString QgsSymmetricalDifferenceAlgorithm::shortHelpString() const
      48                 :            : {
      49                 :          0 :   return QObject::tr( "This algorithm extracts the portions of features from both the Input and Overlay layers that do not overlap. "
      50                 :            :                       "Overlapping areas between the two layers are removed. The attribute table of the Symmetrical Difference layer "
      51                 :            :                       "contains original attributes from both the Input and Difference layers." );
      52                 :            : }
      53                 :            : 
      54                 :          0 : QgsProcessingAlgorithm *QgsSymmetricalDifferenceAlgorithm::createInstance() const
      55                 :            : {
      56                 :          0 :   return new QgsSymmetricalDifferenceAlgorithm();
      57                 :            : }
      58                 :            : 
      59                 :          0 : void QgsSymmetricalDifferenceAlgorithm::initAlgorithm( const QVariantMap & )
      60                 :            : {
      61                 :          0 :   addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
      62                 :          0 :   addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "OVERLAY" ), QObject::tr( "Overlay layer" ) ) );
      63                 :            : 
      64                 :          0 :   std::unique_ptr< QgsProcessingParameterString > prefix = std::make_unique< QgsProcessingParameterString >( QStringLiteral( "OVERLAY_FIELDS_PREFIX" ), QObject::tr( "Overlay fields prefix" ), QString(), false, true );
      65                 :          0 :   prefix->setFlags( prefix->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
      66                 :          0 :   addParameter( prefix.release() );
      67                 :            : 
      68                 :          0 :   addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Symmetrical difference" ) ) );
      69                 :          0 : }
      70                 :            : 
      71                 :            : 
      72                 :          0 : QVariantMap QgsSymmetricalDifferenceAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
      73                 :            : {
      74                 :          0 :   std::unique_ptr< QgsFeatureSource > sourceA( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
      75                 :          0 :   if ( !sourceA )
      76                 :          0 :     throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "INPUT" ) ) );
      77                 :            : 
      78                 :          0 :   std::unique_ptr< QgsFeatureSource > sourceB( parameterAsSource( parameters, QStringLiteral( "OVERLAY" ), context ) );
      79                 :          0 :   if ( !sourceB )
      80                 :          0 :     throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "OVERLAY" ) ) );
      81                 :            : 
      82                 :          0 :   QgsWkbTypes::Type geomType = QgsWkbTypes::multiType( sourceA->wkbType() );
      83                 :            : 
      84                 :          0 :   QString overlayFieldsPrefix = parameterAsString( parameters, QStringLiteral( "OVERLAY_FIELDS_PREFIX" ), context );
      85                 :          0 :   QgsFields fields = QgsProcessingUtils::combineFields( sourceA->fields(), sourceB->fields(), overlayFieldsPrefix );
      86                 :            : 
      87                 :          0 :   QString dest;
      88                 :          0 :   std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields, geomType, sourceA->sourceCrs(), QgsFeatureSink::RegeneratePrimaryKey ) );
      89                 :          0 :   if ( !sink )
      90                 :          0 :     throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
      91                 :            : 
      92                 :          0 :   QVariantMap outputs;
      93                 :          0 :   outputs.insert( QStringLiteral( "OUTPUT" ), dest );
      94                 :            : 
      95                 :          0 :   int count = 0;
      96                 :          0 :   int total = sourceA->featureCount() + sourceB->featureCount();
      97                 :            : 
      98                 :          0 :   QgsOverlayUtils::difference( *sourceA, *sourceB, *sink, context, feedback, count, total, QgsOverlayUtils::OutputAB );
      99                 :            : 
     100                 :          0 :   QgsOverlayUtils::difference( *sourceB, *sourceA, *sink, context, feedback, count, total, QgsOverlayUtils::OutputBA );
     101                 :            : 
     102                 :          0 :   return outputs;
     103                 :          0 : }
     104                 :            : 
     105                 :            : ///@endcond PRIVATE

Generated by: LCOV version 1.14