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

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :                          qgsalgorithmpointtolayer.cpp
       3                 :            :                          ---------------------
       4                 :            :     begin                : May 2019
       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 "qgsalgorithmpointtolayer.h"
      19                 :            : 
      20                 :            : ///@cond PRIVATE
      21                 :            : 
      22                 :          0 : QString QgsPointToLayerAlgorithm::name() const
      23                 :            : {
      24                 :          0 :   return QStringLiteral( "pointtolayer" );
      25                 :            : }
      26                 :            : 
      27                 :          0 : void QgsPointToLayerAlgorithm::initAlgorithm( const QVariantMap & )
      28                 :            : {
      29                 :          0 :   addParameter( new QgsProcessingParameterPoint( QStringLiteral( "INPUT" ), QObject::tr( "Point" ) ) );
      30                 :          0 :   addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Point" ), QgsProcessing::TypeVectorPoint ) );
      31                 :          0 : }
      32                 :            : 
      33                 :          0 : QString QgsPointToLayerAlgorithm::shortHelpString() const
      34                 :            : {
      35                 :          0 :   return QObject::tr( "This algorithm creates a new vector layer that contains a single feature with geometry matching a point parameter.\n\n"
      36                 :            :                       "It can be used in models to convert a point into a layer which can be used for other algorithms which require "
      37                 :            :                       "a layer based input." );
      38                 :            : }
      39                 :            : 
      40                 :          0 : QgsPointToLayerAlgorithm *QgsPointToLayerAlgorithm::createInstance() const
      41                 :            : {
      42                 :          0 :   return new QgsPointToLayerAlgorithm();
      43                 :            : }
      44                 :            : 
      45                 :          0 : QVariantMap QgsPointToLayerAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
      46                 :            : {
      47                 :          0 :   QgsCoordinateReferenceSystem crs = parameterAsPointCrs( parameters, QStringLiteral( "INPUT" ), context );
      48                 :          0 :   QgsGeometry geom = QgsGeometry::fromPointXY( parameterAsPoint( 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::Point, 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