QGIS API Documentation 3.99.0-Master (09f76ad7019)
Loading...
Searching...
No Matches
qgsalgorithmswapxy.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmswapxy.cpp
3 ------------------------
4 begin : April 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 "qgsalgorithmswapxy.h"
19
20#include "qgsvectorlayer.h"
21
22#include <QString>
23
24using namespace Qt::StringLiterals;
25
27
28QString QgsSwapXYAlgorithm::name() const
29{
30 return u"swapxy"_s;
31}
32
33QString QgsSwapXYAlgorithm::displayName() const
34{
35 return QObject::tr( "Swap X and Y coordinates" );
36}
37
38QStringList QgsSwapXYAlgorithm::tags() const
39{
40 return QObject::tr( "invert,flip,swap,switch,latitude,longitude" ).split( ',' );
41}
42
43QString QgsSwapXYAlgorithm::group() const
44{
45 return QObject::tr( "Vector geometry" );
46}
47
48QString QgsSwapXYAlgorithm::groupId() const
49{
50 return u"vectorgeometry"_s;
51}
52
53QString QgsSwapXYAlgorithm::outputName() const
54{
55 return QObject::tr( "Swapped" );
56}
57
58QString QgsSwapXYAlgorithm::shortHelpString() const
59{
60 return QObject::tr( "This algorithm swaps the X and Y coordinate values in input geometries. It can be used to repair geometries "
61 "which have accidentally had their latitude and longitude values reversed." );
62}
63
64QString QgsSwapXYAlgorithm::shortDescription() const
65{
66 return QObject::tr( "Swaps the X and Y coordinate values in input geometries." );
67}
68
69QgsSwapXYAlgorithm *QgsSwapXYAlgorithm::createInstance() const
70{
71 return new QgsSwapXYAlgorithm();
72}
73
74bool QgsSwapXYAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
75{
76 const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( l );
77 if ( !layer )
78 return false;
79
81 return false;
82
83 return layer->isSpatial();
84}
85
86Qgis::ProcessingFeatureSourceFlags QgsSwapXYAlgorithm::sourceFlags() const
87{
88 // this algorithm doesn't care about invalid geometries
90}
91
92QgsFeatureList QgsSwapXYAlgorithm::processFeature( const QgsFeature &f, QgsProcessingContext &, QgsProcessingFeedback * )
93{
94 QgsFeatureList list;
95 QgsFeature feature = f;
96 if ( feature.hasGeometry() )
97 {
98 const QgsGeometry geom = feature.geometry();
99 std::unique_ptr<QgsAbstractGeometry> swappedGeom( geom.constGet()->clone() );
100 swappedGeom->swapXy();
101 feature.setGeometry( QgsGeometry( std::move( swappedGeom ) ) );
102 list << feature;
103 }
104 else
105 {
106 list << feature;
107 }
108 return list;
109}
110
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition qgis.h:3782
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3793
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
QgsGeometry geometry
Definition qgsfeature.h:71
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Base class for all map layer types.
Definition qgsmaplayer.h:83
Contains information about the context in which a processing algorithm is executed.
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
Base class for providing feedback from a processing algorithm.
Represents a vector layer which manages a vector based dataset.
bool isSpatial() const final
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
QList< QgsFeature > QgsFeatureList