QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsvectorwarper.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorwarper.h
3  --------------------------------------
4  Date : February 2022
5  Copyright : (C) 2022 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSVECTORWARPER_H
17 #define QGSVECTORWARPER_H
18 
19 #include "qgspoint.h"
20 #include "qgis_analysis.h"
21 #include "qgis_sip.h"
22 #include "qgsgcptransformer.h"
23 #include "qgsgcppoint.h"
24 #include "qgsfeatureiterator.h"
25 #include "qgsfeaturesource.h"
26 #include "qgstaskmanager.h"
27 #include "qgsvectorfilewriter.h"
29 
30 class QgsFeatureSink;
31 
38 class ANALYSIS_EXPORT QgsVectorWarper
39 {
40  public:
41 
49  explicit QgsVectorWarper( QgsGcpTransformerInterface::TransformMethod method, const QList < QgsGcpPoint > &points,
50  const QgsCoordinateReferenceSystem &destinationCrs );
51 
59  bool transformFeatures( QgsFeatureIterator &iterator, QgsFeatureSink *sink,
60  const QgsCoordinateTransformContext &context,
61  QgsFeedback *feedback = nullptr ) const;
62 
66  QString error() const { return mError; }
67 
68  private:
70  QList < QgsGcpPoint > mPoints;
71  QgsCoordinateReferenceSystem mDestinationCrs;
72 
73  mutable QString mError;
74 
75 };
76 
77 
84 class ANALYSIS_EXPORT QgsVectorWarperTask : public QgsTask
85 {
86  Q_OBJECT
87 
88  public:
89 
99  QgsVectorWarperTask( QgsGcpTransformerInterface::TransformMethod method, const QList < QgsGcpPoint > &points,
100  const QgsCoordinateReferenceSystem &destinationCrs,
101  QgsVectorLayer *layer,
102  const QString &fileName );
103 
104  void cancel() override;
105 
107  enum class Result
108  {
109  Success,
110  Canceled,
111  Error,
112  };
113 
117  Result result() const { return mResult; }
118 
122  QString errorMessage() const { return mErrorMessage; }
123 
124  protected:
125 
126  bool run() override;
127 
128  private:
129 
131  long long mFeatureCount = 0;
132  std::unique_ptr< QgsVectorLayerFeatureSource > mSource;
133  QList < QgsGcpPoint > mPoints;
134  QgsCoordinateReferenceSystem mDestinationCrs;
135 
136  QString mDestFileName;
137 
138  std::unique_ptr< QgsFeedback > mFeedback;
139 
140  QgsCoordinateTransformContext mTransformContext;
141  QgsFields mFields;
143 
144  Result mResult = Result::Success;
145  QString mErrorMessage;
146  double mLastProgress = 0;
147 };
148 
149 
150 #endif //QGSVECTORWARPER_H
QgsVectorWarperTask::result
Result result() const
Returns the result of running the task.
Definition: qgsvectorwarper.h:117
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsVectorWarperTask::errorMessage
QString errorMessage() const
Returns the descriptive error message, if an error occurred.
Definition: qgsvectorwarper.h:122
QgsVectorWarperTask
A task for warping a vector layer in a background thread.
Definition: qgsvectorwarper.h:84
qgstaskmanager.h
qgsfeatureiterator.h
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsVectorWarper::error
QString error() const
Returns the last error obtained during transformation.
Definition: qgsvectorwarper.h:66
qgspoint.h
qgsgcptransformer.h
QgsTask::cancel
virtual void cancel()
Notifies the task that it should terminate.
Definition: qgstaskmanager.cpp:91
qgsgcppoint.h
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:71
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
qgis_sip.h
qgsfeaturesource.h
qgsvectorlayerfeatureiterator.h
QgsVectorWarper
Vector layer warper which warps vector layers based on a list of source and destination GCPs.
Definition: qgsvectorwarper.h:38
QgsVectorWarperTask::Result
Result
Task results.
Definition: qgsvectorwarper.h:107
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsGcpTransformerInterface::TransformMethod
TransformMethod
Available transformation methods.
Definition: qgsgcptransformer.h:55
qgsvectorfilewriter.h
QgsGcpTransformerInterface::TransformMethod::Linear
@ Linear
Linear transform.
QgsFeatureIterator
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:289
QgsTask::run
virtual bool run()=0
Performs the task's operation.
QgsFeatureSink
An interface for objects which accept features via addFeature(s) methods.
Definition: qgsfeaturesink.h:33
QgsTask
Abstract base class for long running background tasks. Tasks can be controlled directly,...
Definition: qgstaskmanager.h:54