QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
23
24QString QgsSwapXYAlgorithm::name() const
25{
26 return QStringLiteral( "swapxy" );
27}
28
29QString QgsSwapXYAlgorithm::displayName() const
30{
31 return QObject::tr( "Swap X and Y coordinates" );
32}
33
34QStringList QgsSwapXYAlgorithm::tags() const
35{
36 return QObject::tr( "invert,flip,swap,switch,latitude,longitude" ).split( ',' );
37}
38
39QString QgsSwapXYAlgorithm::group() const
40{
41 return QObject::tr( "Vector geometry" );
42}
43
44QString QgsSwapXYAlgorithm::groupId() const
45{
46 return QStringLiteral( "vectorgeometry" );
47}
48
49QString QgsSwapXYAlgorithm::outputName() const
50{
51 return QObject::tr( "Swapped" );
52}
53
54QString QgsSwapXYAlgorithm::shortHelpString() const
55{
56 return QObject::tr( "This algorithm swaps the X and Y coordinate values in input geometries. It can be used to repair geometries "
57 "which have accidentally had their latitude and longitude values reversed." );
58}
59
60QString QgsSwapXYAlgorithm::shortDescription() const
61{
62 return QObject::tr( "Swaps the X and Y coordinate values in input geometries." );
63}
64
65QgsSwapXYAlgorithm *QgsSwapXYAlgorithm::createInstance() const
66{
67 return new QgsSwapXYAlgorithm();
68}
69
70bool QgsSwapXYAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
71{
72 const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( l );
73 if ( !layer )
74 return false;
75
77 return false;
78
79 return layer->isSpatial();
80}
81
82Qgis::ProcessingFeatureSourceFlags QgsSwapXYAlgorithm::sourceFlags() const
83{
84 // this algorithm doesn't care about invalid geometries
86}
87
88QgsFeatureList QgsSwapXYAlgorithm::processFeature( const QgsFeature &f, QgsProcessingContext &, QgsProcessingFeedback * )
89{
90 QgsFeatureList list;
91 QgsFeature feature = f;
92 if ( feature.hasGeometry() )
93 {
94 const QgsGeometry geom = feature.geometry();
95 std::unique_ptr<QgsAbstractGeometry> swappedGeom( geom.constGet()->clone() );
96 swappedGeom->swapXy();
97 feature.setGeometry( QgsGeometry( std::move( swappedGeom ) ) );
98 list << feature;
99 }
100 else
101 {
102 list << feature;
103 }
104 return list;
105}
106
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition qgis.h:3711
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3722
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:58
QgsGeometry geometry
Definition qgsfeature.h:69
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:80
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