1 /***************************************************************************
2 qgsalgorithmforcerhr.cpp
3 ---------------------
4 begin : November 2018
5 copyright : (C) 2018 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 "qgsalgorithmforcerhr.h"
19 #include "qgsvectorlayer.h"
20 #include "qgsgeometrycollection.h"
21 #include "qgscurvepolygon.h"
22
23 ///@cond PRIVATE
24
name() const25 QString QgsForceRHRAlgorithm::name() const
26 {
27 return QStringLiteral( "forcerhr" );
28 }
29
displayName() const30 QString QgsForceRHRAlgorithm::displayName() const
31 {
32 return QObject::tr( "Force right-hand-rule" );
33 }
34
tags() const35 QStringList QgsForceRHRAlgorithm::tags() const
36 {
37 return QObject::tr( "clockwise,counter,orientation,ring,repair,invalid,geometry,make,valid" ).split( ',' );
38 }
39
group() const40 QString QgsForceRHRAlgorithm::group() const
41 {
42 return QObject::tr( "Vector geometry" );
43 }
44
groupId() const45 QString QgsForceRHRAlgorithm::groupId() const
46 {
47 return QStringLiteral( "vectorgeometry" );
48 }
49
sourceFlags() const50 QgsProcessingFeatureSource::Flag QgsForceRHRAlgorithm::sourceFlags() const
51 {
52 return QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks;
53 }
54
outputName() const55 QString QgsForceRHRAlgorithm::outputName() const
56 {
57 return QObject::tr( "Reoriented" );
58 }
59
shortHelpString() const60 QString QgsForceRHRAlgorithm::shortHelpString() const
61 {
62 return QObject::tr( "This algorithm forces polygon geometries to respect the Right-Hand-Rule, in which the area that is bounded by a polygon "
63 "is to the right of the boundary. In particular, the exterior ring is oriented in a clockwise direction and the interior "
64 "rings in a counter-clockwise direction." );
65 }
66
shortDescription() const67 QString QgsForceRHRAlgorithm::shortDescription() const
68 {
69 return QObject::tr( "Forces polygon geometries to respect the Right-Hand-Rule." );
70 }
71
inputLayerTypes() const72 QList<int> QgsForceRHRAlgorithm::inputLayerTypes() const
73 {
74 return QList<int>() << QgsProcessing::TypeVectorPolygon;
75 }
76
createInstance() const77 QgsForceRHRAlgorithm *QgsForceRHRAlgorithm::createInstance() const
78 {
79 return new QgsForceRHRAlgorithm();
80 }
81
processFeature(const QgsFeature & feature,QgsProcessingContext &,QgsProcessingFeedback *)82 QgsFeatureList QgsForceRHRAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback * )
83 {
84 if ( !feature.hasGeometry() )
85 return QgsFeatureList() << feature;
86
87 QgsFeature outputFeature = feature;
88 outputFeature.setGeometry( feature.geometry().forceRHR() );
89
90 return QgsFeatureList() << outputFeature;
91 }
92
93 ///@endcond
94