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

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :                          qgsalgorithmextenttolayer.cpp
       3                 :            :                          ---------------------
       4                 :            :     begin                : April 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 "qgsalgorithmextenttolayer.h"
      19                 :            : 
      20                 :            : ///@cond PRIVATE
      21                 :            : 
      22                 :          0 : QString QgsExtentToLayerAlgorithm::name() const
      23                 :            : {
      24                 :          0 :   return QStringLiteral( "extenttolayer" );
      25                 :            : }
      26                 :            : 
      27                 :          0 : void QgsExtentToLayerAlgorithm::initAlgorithm( const QVariantMap & )
      28                 :            : {
      29                 :          0 :   addParameter( new QgsProcessingParameterExtent( QStringLiteral( "INPUT" ), QObject::tr( "Extent" ) ) );
      30                 :          0 :   addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Extent" ), QgsProcessing::TypeVectorPolygon ) );
      31                 :          0 : }
      32                 :            : 
      33                 :          0 : QString QgsExtentToLayerAlgorithm::shortHelpString() const
      34                 :            : {
      35                 :          0 :   return QObject::tr( "This algorithm creates a new vector layer that contains a single feature with geometry matching an extent parameter.\n\n"
      36                 :            :                       "It can be used in models to convert an extent into a layer which can be used for other algorithms which require "
      37                 :            :                       "a layer based input." );
      38                 :            : }
      39                 :            : 
      40                 :          0 : QgsExtentToLayerAlgorithm *QgsExtentToLayerAlgorithm::createInstance() const
      41                 :            : {
      42                 :          0 :   return new QgsExtentToLayerAlgorithm();
      43                 :            : }
      44                 :            : 
      45                 :          0 : QVariantMap QgsExtentToLayerAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
      46                 :            : {
      47                 :          0 :   QgsCoordinateReferenceSystem crs = parameterAsExtentCrs( parameters, QStringLiteral( "INPUT" ), context );
      48                 :          0 :   QgsGeometry geom = parameterAsExtentGeometry( parameters, QStringLiteral( "INPUT" ), context );
      49                 :            : 
      50                 :          0 :   QgsFields fields;
      51                 :          0 :   fields.append( QgsField( QStringLiteral( "id" ), QVariant::Int ) );
      52                 :            : 
      53                 :          0 :   QString dest;
      54                 :          0 :   std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, fields, QgsWkbTypes::Polygon, crs ) );
      55                 :          0 :   if ( !sink )
      56                 :          0 :     throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
      57                 :            : 
      58                 :          0 :   QgsFeature f;
      59                 :          0 :   f.setAttributes( QgsAttributes() << 1 );
      60                 :          0 :   f.setGeometry( geom );
      61                 :          0 :   sink->addFeature( f, QgsFeatureSink::FastInsert );
      62                 :            : 
      63                 :          0 :   feedback->setProgress( 100 );
      64                 :            : 
      65                 :          0 :   QVariantMap outputs;
      66                 :          0 :   outputs.insert( QStringLiteral( "OUTPUT" ), dest );
      67                 :          0 :   return outputs;
      68                 :          0 : }
      69                 :            : 
      70                 :            : ///@endcond
      71                 :            : 

Generated by: LCOV version 1.14