Skip to content
Permalink
Browse files

[processing] Port reverse line direction alg to c++

  • Loading branch information
nyalldawson committed Jul 21, 2018
1 parent e4e7b2a commit 65548436ad6380962a59602cc26d2ccd539cf06d
@@ -117,7 +117,6 @@
from .RectanglesOvalsDiamondsVariable import RectanglesOvalsDiamondsVariable
from .RegularPoints import RegularPoints
from .Relief import Relief
from .ReverseLineDirection import ReverseLineDirection
from .Ruggedness import Ruggedness
from .SelectByAttribute import SelectByAttribute
from .SelectByExpression import SelectByExpression
@@ -233,7 +232,6 @@ def getAlgs(self):
RectanglesOvalsDiamondsVariable(),
RegularPoints(),
Relief(),
ReverseLineDirection(),
Ruggedness(),
SelectByAttribute(),
SelectByExpression(),

This file was deleted.

@@ -959,7 +959,7 @@ tests:
name: expected/point_on_line.gml
type: vector

- algorithm: qgis:reverselinedirection
- algorithm: native:reverselinedirection
name: Reverse line direction
params:
INPUT:
@@ -68,6 +68,7 @@ SET(QGIS_ANALYSIS_SRCS
processing/qgsalgorithmremoveholes.cpp
processing/qgsalgorithmremovenullgeometry.cpp
processing/qgsalgorithmrenamelayer.cpp
processing/qgsalgorithmreverselinedirection.cpp
processing/qgsalgorithmrotate.cpp
processing/qgsalgorithmsaveselectedfeatures.cpp
processing/qgsalgorithmsegmentize.cpp
@@ -0,0 +1,106 @@
/***************************************************************************
qgsalgorithmreverselinedirection.cpp
------------------------------------
begin : July 2018
copyright : (C) 2018 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsalgorithmreverselinedirection.h"
#include "qgscurve.h"

///@cond PRIVATE

QString QgsReverseLineDirectionAlgorithm ::name() const
{
return QStringLiteral( "reverselinedirection" );
}

QString QgsReverseLineDirectionAlgorithm ::displayName() const
{
return QObject::tr( "Reverse line direction" );
}

QStringList QgsReverseLineDirectionAlgorithm ::tags() const
{
return QObject::tr( "swap,reverse,switch,flip,linestring,orientation" ).split( ',' );
}

QString QgsReverseLineDirectionAlgorithm ::group() const
{
return QObject::tr( "Vector geometry" );
}

QString QgsReverseLineDirectionAlgorithm ::groupId() const
{
return QStringLiteral( "vectorgeometry" );
}

QString QgsReverseLineDirectionAlgorithm ::outputName() const
{
return QObject::tr( "Reversed" );
}

QString QgsReverseLineDirectionAlgorithm ::shortHelpString() const
{
return QObject::tr( "This algorithm reverses the direction of curve or LineString geometries." );
}

QString QgsReverseLineDirectionAlgorithm::shortDescription() const
{
return QObject::tr( "Reverses the direction of curve or LineString geometries." );
}

QgsReverseLineDirectionAlgorithm *QgsReverseLineDirectionAlgorithm ::createInstance() const
{
return new QgsReverseLineDirectionAlgorithm();
}

QgsProcessing::SourceType QgsReverseLineDirectionAlgorithm::outputLayerType() const
{
return QgsProcessing::TypeVectorLine;
}

QList<int> QgsReverseLineDirectionAlgorithm::inputLayerTypes() const
{
return QList<int>() << QgsProcessing::TypeVectorLine;
}

QgsProcessingFeatureSource::Flag QgsReverseLineDirectionAlgorithm ::sourceFlags() const
{
// this algorithm doesn't care about invalid geometries
return QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks;
}

QgsFeatureList QgsReverseLineDirectionAlgorithm ::processFeature( const QgsFeature &f, QgsProcessingContext &, QgsProcessingFeedback * )
{
QgsFeature feature = f;
if ( feature.hasGeometry() )
{
const QgsGeometry geom = feature.geometry();
const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( geom.constGet() );
if ( curve )
{
std::unique_ptr< QgsCurve > reversed( curve->reversed() );
if ( !reversed )
{
// can this even happen?
throw QgsProcessingException( QObject::tr( "Error reversing line" ) );
}
const QgsGeometry outGeom( std::move( reversed ) );
feature.setGeometry( outGeom );
}
}
return QgsFeatureList() << feature;
}

///@endcond
@@ -0,0 +1,60 @@
/***************************************************************************
qgsalgorithmreverselinedirection.h
----------------------------------
begin : July 2018
copyright : (C) 2018 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSALGORITHMREVERSELINEDIRECTION_H
#define QGSALGORITHMREVERSELINEDIRECTION_H

#define SIP_NO_FILE

#include "qgis.h"
#include "qgsprocessingalgorithm.h"

///@cond PRIVATE

/**
* Native reverse line direction algorithm.
*/
class QgsReverseLineDirectionAlgorithm : public QgsProcessingFeatureBasedAlgorithm
{

public:

QgsReverseLineDirectionAlgorithm() = default;
QString name() const override;
QString displayName() const override;
QStringList tags() const override;
QString group() const override;
QString groupId() const override;
QString shortHelpString() const override;
QString shortDescription() const override;
QgsReverseLineDirectionAlgorithm *createInstance() const override SIP_FACTORY;
QgsProcessing::SourceType outputLayerType() const override;
QList<int> inputLayerTypes() const override;

protected:

QString outputName() const override;
QgsProcessingFeatureSource::Flag sourceFlags() const override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;

};

///@endcond PRIVATE

#endif // QGSALGORITHMREVERSELINEDIRECTION_H


@@ -65,6 +65,7 @@
#include "qgsalgorithmremoveholes.h"
#include "qgsalgorithmremovenullgeometry.h"
#include "qgsalgorithmrenamelayer.h"
#include "qgsalgorithmreverselinedirection.h"
#include "qgsalgorithmrotate.h"
#include "qgsalgorithmsaveselectedfeatures.h"
#include "qgsalgorithmsegmentize.h"
@@ -177,6 +178,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
addAlgorithm( new QgsRemoveHolesAlgorithm() );
addAlgorithm( new QgsRemoveNullGeometryAlgorithm() );
addAlgorithm( new QgsRenameLayerAlgorithm() );
addAlgorithm( new QgsReverseLineDirectionAlgorithm() );
addAlgorithm( new QgsRotateFeaturesAlgorithm() );
addAlgorithm( new QgsSaveSelectedFeatures() );
addAlgorithm( new QgsSegmentizeByMaximumAngleAlgorithm() );

0 comments on commit 6554843

Please sign in to comment.
You can’t perform that action at this time.