LCOV - code coverage report
Current view: top level - analysis/processing - qgsalgorithmdifference.cpp (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 52 0.0 %
Date: 2021-04-10 08:29:14 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :   qgsalgorithmdifference.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 "qgsalgorithmdifference.h"
      17                 :            : 
      18                 :            : #include "qgsoverlayutils.h"
      19                 :            : #include "qgsvectorlayer.h"
      20                 :            : 
      21                 :            : ///@cond PRIVATE
      22                 :            : 
      23                 :            : 
      24                 :          0 : QString QgsDifferenceAlgorithm::name() const
      25                 :            : {
      26                 :          0 :   return QStringLiteral( "difference" );
      27                 :            : }
      28                 :            : 
      29                 :          0 : QString QgsDifferenceAlgorithm::displayName() const
      30                 :            : {
      31                 :          0 :   return QObject::tr( "Difference" );
      32                 :            : }
      33                 :            : 
      34                 :          0 : QStringList QgsDifferenceAlgorithm::tags() const
      35                 :            : {
      36                 :          0 :   return QObject::tr( "difference,erase,not overlap" ).split( ',' );
      37                 :          0 : }
      38                 :            : 
      39                 :          0 : QString QgsDifferenceAlgorithm::group() const
      40                 :            : {
      41                 :          0 :   return QObject::tr( "Vector overlay" );
      42                 :            : }
      43                 :            : 
      44                 :          0 : QString QgsDifferenceAlgorithm::groupId() const
      45                 :            : {
      46                 :          0 :   return QStringLiteral( "vectoroverlay" );
      47                 :            : }
      48                 :            : 
      49                 :          0 : QString QgsDifferenceAlgorithm::shortHelpString() const
      50                 :            : {
      51                 :          0 :   return QObject::tr( "This algorithm extracts features from the Input layer that fall outside, or partially overlap, features in the Overlay layer. "
      52                 :            :                       "Input layer features that partially overlap feature(s) in the Overlay layer are split along those features' boundary "
      53                 :            :                       "and only the portions outside the Overlay layer features are retained." )
      54                 :          0 :          + QStringLiteral( "\n\n" )
      55                 :          0 :          + QObject::tr( "Attributes are not modified, although properties such as area or length of the features will "
      56                 :            :                         "be modified by the difference operation. If such properties are stored as attributes, those attributes will have to "
      57                 :            :                         "be manually updated." );
      58                 :          0 : }
      59                 :            : 
      60                 :          0 : bool QgsDifferenceAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
      61                 :            : {
      62                 :          0 :   const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
      63                 :          0 :   if ( !layer )
      64                 :          0 :     return false;
      65                 :            : 
      66                 :          0 :   return layer->isSpatial();
      67                 :          0 : }
      68                 :            : 
      69                 :          0 : QgsProcessingAlgorithm::Flags QgsDifferenceAlgorithm::flags() const
      70                 :            : {
      71                 :          0 :   Flags f = QgsProcessingAlgorithm::flags();
      72                 :          0 :   f |= QgsProcessingAlgorithm::FlagSupportsInPlaceEdits;
      73                 :          0 :   return f;
      74                 :            : }
      75                 :            : 
      76                 :          0 : QgsProcessingAlgorithm *QgsDifferenceAlgorithm::createInstance() const
      77                 :            : {
      78                 :          0 :   return new QgsDifferenceAlgorithm();
      79                 :            : }
      80                 :            : 
      81                 :          0 : void QgsDifferenceAlgorithm::initAlgorithm( const QVariantMap & )
      82                 :            : {
      83                 :          0 :   addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
      84                 :          0 :   addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "OVERLAY" ), QObject::tr( "Overlay layer" ) ) );
      85                 :          0 :   addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Difference" ) ) );
      86                 :          0 : }
      87                 :            : 
      88                 :            : 
      89                 :          0 : QVariantMap QgsDifferenceAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
      90                 :            : {
      91                 :          0 :   std::unique_ptr< QgsFeatureSource > sourceA( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
      92                 :          0 :   if ( !sourceA )
      93                 :          0 :     throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "INPUT" ) ) );
      94                 :            : 
      95                 :          0 :   std::unique_ptr< QgsFeatureSource > sourceB( parameterAsSource( parameters, QStringLiteral( "OVERLAY" ), context ) );
      96                 :          0 :   if ( !sourceB )
      97                 :          0 :     throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "OVERLAY" ) ) );
      98                 :            : 
      99                 :          0 :   QgsWkbTypes::Type geomType = QgsWkbTypes::multiType( sourceA->wkbType() );
     100                 :            : 
     101                 :          0 :   QString dest;
     102                 :          0 :   std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, sourceA->fields(), geomType, sourceA->sourceCrs() ) );
     103                 :          0 :   if ( !sink )
     104                 :          0 :     throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
     105                 :            : 
     106                 :          0 :   QVariantMap outputs;
     107                 :          0 :   outputs.insert( QStringLiteral( "OUTPUT" ), dest );
     108                 :            : 
     109                 :          0 :   int count = 0;
     110                 :          0 :   int total = sourceA->featureCount();
     111                 :          0 :   QgsOverlayUtils::difference( *sourceA, *sourceB, *sink, context, feedback, count, total, QgsOverlayUtils::OutputA );
     112                 :            : 
     113                 :          0 :   return outputs;
     114                 :          0 : }
     115                 :            : 
     116                 :            : ///@endcond PRIVATE

Generated by: LCOV version 1.14