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