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

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :                          qgsalgorithmruggedness.cpp
       3                 :            :                          ---------------------
       4                 :            :     begin                : November 2019
       5                 :            :     copyright            : (C) 2019 by Alexander Bruy
       6                 :            :     email                : alexander dot bruy 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 "qgsalgorithmruggedness.h"
      19                 :            : #include "qgsrasterfilewriter.h"
      20                 :            : #include "qgsruggednessfilter.h"
      21                 :            : 
      22                 :            : ///@cond PRIVATE
      23                 :            : 
      24                 :          0 : QString QgsRuggednessAlgorithm::name() const
      25                 :            : {
      26                 :          0 :   return QStringLiteral( "ruggednessindex" );
      27                 :            : }
      28                 :            : 
      29                 :          0 : QString QgsRuggednessAlgorithm::displayName() const
      30                 :            : {
      31                 :          0 :   return QObject::tr( "Ruggedness index" );
      32                 :            : }
      33                 :            : 
      34                 :          0 : QStringList QgsRuggednessAlgorithm::tags() const
      35                 :            : {
      36                 :          0 :   return QObject::tr( "dem,ruggedness,index,terrain" ).split( ',' );
      37                 :          0 : }
      38                 :            : 
      39                 :          0 : QString QgsRuggednessAlgorithm::group() const
      40                 :            : {
      41                 :          0 :   return QObject::tr( "Raster terrain analysis" );
      42                 :            : }
      43                 :            : 
      44                 :          0 : QString QgsRuggednessAlgorithm::groupId() const
      45                 :            : {
      46                 :          0 :   return QStringLiteral( "rasterterrainanalysis" );
      47                 :            : }
      48                 :            : 
      49                 :          0 : QString QgsRuggednessAlgorithm::shortHelpString() const
      50                 :            : {
      51                 :          0 :   return QObject::tr( "This algorithm calculates the quantitative measurement of terrain "
      52                 :            :                       "heterogeneity described by Riley et al. (1999)." )
      53                 :          0 :          + QStringLiteral( "\n\n" )
      54                 :          0 :          + QObject::tr( "It is calculated for every location, by summarizing the change "
      55                 :            :                         "in elevation within the 3x3 pixel grid. Each pixel contains the "
      56                 :            :                         "difference in elevation from a center cell and the 8 cells surrounding it." );
      57                 :          0 : }
      58                 :            : 
      59                 :          0 : QgsRuggednessAlgorithm *QgsRuggednessAlgorithm::createInstance() const
      60                 :            : {
      61                 :          0 :   return new QgsRuggednessAlgorithm();
      62                 :            : }
      63                 :            : 
      64                 :          0 : void QgsRuggednessAlgorithm::initAlgorithm( const QVariantMap & )
      65                 :            : {
      66                 :          0 :   addParameter( new QgsProcessingParameterRasterLayer( QStringLiteral( "INPUT" ), QObject::tr( "Elevation layer" ) ) );
      67                 :          0 :   addParameter( new QgsProcessingParameterNumber( QStringLiteral( "Z_FACTOR" ), QObject::tr( "Z factor" ),
      68                 :          0 :                 QgsProcessingParameterNumber::Double, 1, false, 0 ) );
      69                 :            : 
      70                 :          0 :   addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Ruggedness" ) ) );
      71                 :          0 : }
      72                 :            : 
      73                 :          0 : QVariantMap QgsRuggednessAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
      74                 :            : {
      75                 :          0 :   QgsRasterLayer *inputLayer = parameterAsRasterLayer( parameters, QStringLiteral( "INPUT" ), context );
      76                 :            : 
      77                 :          0 :   if ( !inputLayer )
      78                 :          0 :     throw QgsProcessingException( invalidRasterError( parameters, QStringLiteral( "INPUT" ) ) );
      79                 :            : 
      80                 :          0 :   double zFactor = parameterAsDouble( parameters, QStringLiteral( "Z_FACTOR" ), context );
      81                 :            : 
      82                 :          0 :   const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
      83                 :          0 :   QFileInfo fi( outputFile );
      84                 :          0 :   const QString outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
      85                 :            : 
      86                 :          0 :   QgsRuggednessFilter ruggedness( inputLayer->source(), outputFile, outputFormat );
      87                 :          0 :   ruggedness.setZFactor( zFactor );
      88                 :          0 :   ruggedness.processRaster( feedback );
      89                 :            : 
      90                 :          0 :   QVariantMap outputs;
      91                 :          0 :   outputs.insert( QStringLiteral( "OUTPUT" ), outputFile );
      92                 :          0 :   return outputs;
      93                 :          0 : }
      94                 :            : 
      95                 :            : ///@endcond

Generated by: LCOV version 1.14