QGIS API Documentation  3.17.0-Master (8af46bc54f)
qgsremappingproxyfeaturesink.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsremappingproxyfeaturesink.h
3  ----------------------
4  begin : April 2020
5  copyright : (C) 2020 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 #ifndef QGSREMAPPINGPROXYFEATURESINK_H
19 #define QGSREMAPPINGPROXYFEATURESINK_H
20 
21 #include "qgis_core.h"
22 #include "qgis.h"
23 #include "qgsfeaturesink.h"
24 #include "qgsproperty.h"
25 
37 class CORE_EXPORT QgsRemappingSinkDefinition
38 {
39  public:
40 
51  QMap< QString, QgsProperty > fieldMap() const { return mFieldMap; }
52 
63  void setFieldMap( const QMap< QString, QgsProperty > &map ) { mFieldMap = map; }
64 
74  void addMappedField( const QString &destinationField, const QgsProperty &property ) { mFieldMap.insert( destinationField, property ); }
75 
81  QgsCoordinateReferenceSystem sourceCrs() const { return mSourceCrs; }
82 
88  void setSourceCrs( const QgsCoordinateReferenceSystem &source ) { mSourceCrs = source; }
89 
95  QgsCoordinateReferenceSystem destinationCrs() const { return mDestinationCrs; }
96 
102  void setDestinationCrs( const QgsCoordinateReferenceSystem &destination ) { mDestinationCrs = destination; }
103 
109  QgsWkbTypes::Type destinationWkbType() const { return mDestinationWkbType; }
110 
116  void setDestinationWkbType( QgsWkbTypes::Type type ) { mDestinationWkbType = type; }
117 
123  QgsFields destinationFields() const { return mDestinationFields; }
124 
130  void setDestinationFields( const QgsFields &fields ) { mDestinationFields = fields; }
131 
137  QVariant toVariant() const;
138 
144  bool loadVariant( const QVariantMap &map );
145 
146  bool operator==( const QgsRemappingSinkDefinition &other ) const;
147  bool operator!=( const QgsRemappingSinkDefinition &other ) const;
148 
149  private:
150 
151  QMap< QString, QgsProperty > mFieldMap;
152 
153  QgsCoordinateReferenceSystem mSourceCrs;
154  QgsCoordinateReferenceSystem mDestinationCrs;
155 
156  QgsWkbTypes::Type mDestinationWkbType = QgsWkbTypes::Unknown;
157 
158  QgsFields mDestinationFields;
159 
160 };
161 
163 
164 
165 
166 
179 {
180  public:
181 
182 #ifndef SIP_RUN
183 
192  QgsRemappingProxyFeatureSink( const QgsRemappingSinkDefinition &mappingDefinition, QgsFeatureSink *sink, bool ownsSink = false );
193 #else
194 
200 #endif
201 
202  ~QgsRemappingProxyFeatureSink() override;
203 
207  void setExpressionContext( const QgsExpressionContext &context );
208 
212  void setTransformContext( const QgsCoordinateTransformContext &context );
213 
217  QgsFeatureList remapFeature( const QgsFeature &feature ) const;
218 
219  bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
220  bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
221  bool addFeatures( QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
222  QString lastError() const override;
223 
227  QgsFeatureSink *destinationSink() { return mSink; }
228 
229  private:
230 
231  QgsRemappingSinkDefinition mDefinition;
232  QgsCoordinateTransform mTransform;
233  QgsFeatureSink *mSink = nullptr;
234  mutable QgsExpressionContext mContext;
235  bool mOwnsSink = false;
236 };
237 
238 #endif // QGSREMAPPINGPROXYFEATURESINK_H
239 
240 
241 
242 
Wrapper for iterator of features from vector data provider or vector layer.
void setSourceCrs(const QgsCoordinateReferenceSystem &source)
Sets the source crs used for reprojecting incoming features to the sink&#39;s destination CRS...
A QgsFeatureSink which proxies incoming features to a destination feature sink, after applying transf...
QgsWkbTypes::Type destinationWkbType() const
Returns the WKB geometry type for the destination.
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:583
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
void setDestinationWkbType(QgsWkbTypes::Type type)
Sets the WKB geometry type for the destination.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source CRS used for reprojecting incoming features to the sink&#39;s destination CRS...
An interface for objects which accept features via addFeature(s) methods.
Container of fields for a vector layer.
Definition: qgsfields.h:44
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
QMap< QString, QgsProperty > fieldMap() const
Returns the field mapping, which defines how to map the values from incoming features to destination ...
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
void setDestinationFields(const QgsFields &fields)
Sets the fields for the destination sink.
QgsFeatureSink * destinationSink()
Returns the destination QgsFeatureSink which the proxy will forward features to.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
Contains information about the context in which a coordinate transform is executed.
A store for object properties.
Definition: qgsproperty.h:231
void setDestinationCrs(const QgsCoordinateReferenceSystem &destination)
Sets the destination crs used for reprojecting incoming features to the sink&#39;s destination CRS...
Defines the parameters used to remap features when creating a QgsRemappingProxyFeatureSink.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination CRS used for reprojecting incoming features to the sink&#39;s destination CRS...
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
void addMappedField(const QString &destinationField, const QgsProperty &property)
Adds a mapping for a destination field.
void setFieldMap(const QMap< QString, QgsProperty > &map)
Sets the field mapping, which defines how to map the values from incoming features to destination fie...
QgsFields destinationFields() const
Returns the fields for the destination sink.