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

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :                          qgsalgorithmremoveduplicatevertices.cpp
       3                 :            :                          ---------------------
       4                 :            :     begin                : November 2017
       5                 :            :     copyright            : (C) 2017 by Nyall Dawson
       6                 :            :     email                : nyall dot dawson at gmail dot com
       7                 :            :  ***************************************************************************/
       8                 :            : 
       9                 :            : /***************************************************************************
      10                 :            :  *                                                                         *
      11                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      12                 :            :  *   it under the terms of the GNU General Public License as published by  *
      13                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      14                 :            :  *   (at your option) any later version.                                   *
      15                 :            :  *                                                                         *
      16                 :            :  ***************************************************************************/
      17                 :            : 
      18                 :            : #include "qgsalgorithmremoveduplicatevertices.h"
      19                 :            : 
      20                 :            : ///@cond PRIVATE
      21                 :            : 
      22                 :          0 : QString QgsAlgorithmRemoveDuplicateVertices::name() const
      23                 :            : {
      24                 :          0 :   return QStringLiteral( "removeduplicatevertices" );
      25                 :            : }
      26                 :            : 
      27                 :          0 : QString QgsAlgorithmRemoveDuplicateVertices::displayName() const
      28                 :            : {
      29                 :          0 :   return QObject::tr( "Remove duplicate vertices" );
      30                 :            : }
      31                 :            : 
      32                 :          0 : QStringList QgsAlgorithmRemoveDuplicateVertices::tags() const
      33                 :            : {
      34                 :          0 :   return QObject::tr( "points,valid,overlapping,vertex,nodes" ).split( ',' );
      35                 :          0 : }
      36                 :            : 
      37                 :          0 : QString QgsAlgorithmRemoveDuplicateVertices::group() const
      38                 :            : {
      39                 :          0 :   return QObject::tr( "Vector geometry" );
      40                 :            : }
      41                 :            : 
      42                 :          0 : QString QgsAlgorithmRemoveDuplicateVertices::groupId() const
      43                 :            : {
      44                 :          0 :   return QStringLiteral( "vectorgeometry" );
      45                 :            : }
      46                 :            : 
      47                 :          0 : QString QgsAlgorithmRemoveDuplicateVertices::outputName() const
      48                 :            : {
      49                 :          0 :   return QObject::tr( "Cleaned" );
      50                 :            : }
      51                 :            : 
      52                 :          0 : QString QgsAlgorithmRemoveDuplicateVertices::shortHelpString() const
      53                 :            : {
      54                 :          0 :   return QObject::tr( "This algorithm removes duplicate vertices from features, wherever removing the vertices does "
      55                 :            :                       "not result in a degenerate geometry.\n\n"
      56                 :            :                       "The tolerance parameter specifies the tolerance for coordinates when determining whether "
      57                 :            :                       "vertices are identical.\n\n"
      58                 :            :                       "By default, z values are not considered when detecting duplicate vertices. E.g. two vertices "
      59                 :            :                       "with the same x and y coordinate but different z values will still be considered "
      60                 :            :                       "duplicate and one will be removed. If the Use Z Value parameter is true, then the z values are "
      61                 :            :                       "also tested and vertices with the same x and y but different z will be maintained.\n\n"
      62                 :            :                       "Note that duplicate vertices are not tested between different parts of a multipart geometry. E.g. "
      63                 :            :                       "a multipoint geometry with overlapping points will not be changed by this method." );
      64                 :            : }
      65                 :            : 
      66                 :          0 : QgsAlgorithmRemoveDuplicateVertices *QgsAlgorithmRemoveDuplicateVertices::createInstance() const
      67                 :            : {
      68                 :          0 :   return new QgsAlgorithmRemoveDuplicateVertices();
      69                 :          0 : }
      70                 :            : 
      71                 :          0 : void QgsAlgorithmRemoveDuplicateVertices::initParameters( const QVariantMap & )
      72                 :            : {
      73                 :          0 :   std::unique_ptr< QgsProcessingParameterDistance> tolerance = std::make_unique< QgsProcessingParameterDistance >( QStringLiteral( "TOLERANCE" ),
      74                 :          0 :       QObject::tr( "Tolerance" ), 0.000001, QStringLiteral( "INPUT" ), false, 0, 10000000.0 );
      75                 :          0 :   tolerance->setIsDynamic( true );
      76                 :          0 :   tolerance->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "Tolerance" ), QObject::tr( "Tolerance distance" ), QgsPropertyDefinition::DoublePositive ) );
      77                 :          0 :   tolerance->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
      78                 :          0 :   addParameter( tolerance.release() );
      79                 :            : 
      80                 :          0 :   std::unique_ptr< QgsProcessingParameterBoolean > useZ = std::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( "USE_Z_VALUE" ),
      81                 :          0 :       QObject::tr( "Use Z Value" ), false );
      82                 :          0 :   useZ->setIsDynamic( true );
      83                 :          0 :   useZ->setDynamicPropertyDefinition( QgsPropertyDefinition( QStringLiteral( "UseZ" ), QObject::tr( "Use Z Value" ), QgsPropertyDefinition::Boolean ) );
      84                 :          0 :   useZ->setDynamicLayerParameterName( QStringLiteral( "INPUT" ) );
      85                 :          0 :   addParameter( useZ.release() );
      86                 :          0 : }
      87                 :            : 
      88                 :          0 : QgsProcessingFeatureSource::Flag QgsAlgorithmRemoveDuplicateVertices::sourceFlags() const
      89                 :            : {
      90                 :            :   // skip geometry checks - this algorithm can be used to repair geometries
      91                 :          0 :   return QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks;
      92                 :            : }
      93                 :            : 
      94                 :          0 : bool QgsAlgorithmRemoveDuplicateVertices::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
      95                 :            : {
      96                 :          0 :   mTolerance = parameterAsDouble( parameters, QStringLiteral( "TOLERANCE" ), context );
      97                 :          0 :   mDynamicTolerance = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "TOLERANCE" ) );
      98                 :          0 :   if ( mDynamicTolerance )
      99                 :          0 :     mToleranceProperty = parameters.value( QStringLiteral( "TOLERANCE" ) ).value< QgsProperty >();
     100                 :            : 
     101                 :          0 :   mUseZValues = parameterAsBoolean( parameters, QStringLiteral( "USE_Z_VALUE" ), context );
     102                 :          0 :   mDynamicUseZ = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "USE_Z_VALUE" ) );
     103                 :          0 :   if ( mDynamicUseZ )
     104                 :          0 :     mUseZProperty = parameters.value( QStringLiteral( "USE_Z_VALUE" ) ).value< QgsProperty >();
     105                 :            : 
     106                 :          0 :   return true;
     107                 :          0 : }
     108                 :            : 
     109                 :          0 : QgsFeatureList QgsAlgorithmRemoveDuplicateVertices::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback * )
     110                 :            : {
     111                 :          0 :   QgsFeature f = feature;
     112                 :          0 :   if ( f.hasGeometry() )
     113                 :            :   {
     114                 :          0 :     QgsGeometry geometry = f.geometry();
     115                 :          0 :     double tolerance = mTolerance;
     116                 :          0 :     if ( mDynamicTolerance )
     117                 :          0 :       tolerance = mToleranceProperty.valueAsDouble( context.expressionContext(), tolerance );
     118                 :            : 
     119                 :          0 :     bool useZValue = mUseZValues;
     120                 :          0 :     if ( mDynamicUseZ )
     121                 :          0 :       useZValue = mUseZProperty.valueAsBool( context.expressionContext(), useZValue );
     122                 :            : 
     123                 :          0 :     geometry.removeDuplicateNodes( tolerance, useZValue );
     124                 :          0 :     f.setGeometry( geometry );
     125                 :          0 :   }
     126                 :          0 :   return QgsFeatureList() << f;
     127                 :          0 : }
     128                 :            : 
     129                 :            : ///@endcond
     130                 :            : 
     131                 :            : 

Generated by: LCOV version 1.14