Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[processing] Port reverse line direction alg to c++
- Loading branch information
1 parent
e4e7b2a
commit 6554843
Showing
7 changed files
with
170 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 0 additions & 70 deletions
70
python/plugins/processing/algs/qgis/ReverseLineDirection.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/analysis/processing/qgsalgorithmreverselinedirection.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
60 changes: 60 additions & 0 deletions
60
src/analysis/processing/qgsalgorithmreverselinedirection.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters