QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
23 QString QgsSwapXYAlgorithm::name() const
24 {
25  return QStringLiteral( "swapxy" );
26 }
27 
28 QString QgsSwapXYAlgorithm::displayName() const
29 {
30  return QObject::tr( "Swap X and Y coordinates" );
31 }
32 
33 QStringList QgsSwapXYAlgorithm::tags() const
34 {
35  return QObject::tr( "invert,flip,swap,latitude,longitude" ).split( ',' );
36 }
37 
38 QString QgsSwapXYAlgorithm::group() const
39 {
40  return QObject::tr( "Vector geometry" );
41 }
42 
43 QString QgsSwapXYAlgorithm::groupId() const
44 {
45  return QStringLiteral( "vectorgeometry" );
46 }
47 
48 QString QgsSwapXYAlgorithm::outputName() const
49 {
50  return QObject::tr( "Swapped" );
51 }
52 
53 QString 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 
59 QgsSwapXYAlgorithm *QgsSwapXYAlgorithm::createInstance() const
60 {
61  return new QgsSwapXYAlgorithm();
62 }
63 
64 bool 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 
76 QgsProcessingFeatureSource::Flag QgsSwapXYAlgorithm::sourceFlags() const
77 {
78  // this algorithm doesn't care about invalid geometries
80 }
81 
82 QgsFeatureList 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 
qgsalgorithmswapxy.h
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition: qgsprocessingfeedback.h:37
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:71
QgsVectorLayer::isSpatial
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
Definition: qgsvectorlayer.cpp:3733
QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition: qgsprocessingutils.h:584
QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
Definition: qgsprocessingalgorithm.cpp:1139
QgsFeature::setGeometry
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:170
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition: qgsprocessingcontext.h:46
QgsAbstractGeometry::clone
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:882
QgsGeometry::constGet
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Definition: qgsgeometry.cpp:136
qgsvectorlayer.h
QgsProcessingFeatureSource::Flag
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
Definition: qgsprocessingutils.h:582
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsFeature::hasGeometry
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:230
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55