Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
170 additions
and 73 deletions.
- +0 −2 python/plugins/processing/algs/qgis/QgisAlgorithmProvider.py
- +0 −70 python/plugins/processing/algs/qgis/ReverseLineDirection.py
- +1 −1 python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
- +1 −0 src/analysis/CMakeLists.txt
- +106 −0 src/analysis/processing/qgsalgorithmreverselinedirection.cpp
- +60 −0 src/analysis/processing/qgsalgorithmreverselinedirection.h
- +2 −0 src/analysis/processing/qgsnativealgorithms.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 | ||
|
||
|