QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #include "qgscoordinatetransform.h"
26 
38 class CORE_EXPORT QgsRemappingSinkDefinition
39 {
40  public:
41 
52  QMap< QString, QgsProperty > fieldMap() const { return mFieldMap; }
53 
64  void setFieldMap( const QMap< QString, QgsProperty > &map ) { mFieldMap = map; }
65 
75  void addMappedField( const QString &destinationField, const QgsProperty &property ) { mFieldMap.insert( destinationField, property ); }
76 
82  QgsCoordinateReferenceSystem sourceCrs() const { return mSourceCrs; }
83 
89  void setSourceCrs( const QgsCoordinateReferenceSystem &source ) { mSourceCrs = source; }
90 
96  QgsCoordinateReferenceSystem destinationCrs() const { return mDestinationCrs; }
97 
103  void setDestinationCrs( const QgsCoordinateReferenceSystem &destination ) { mDestinationCrs = destination; }
104 
110  QgsWkbTypes::Type destinationWkbType() const { return mDestinationWkbType; }
111 
117  void setDestinationWkbType( QgsWkbTypes::Type type ) { mDestinationWkbType = type; }
118 
124  QgsFields destinationFields() const { return mDestinationFields; }
125 
131  void setDestinationFields( const QgsFields &fields ) { mDestinationFields = fields; }
132 
138  QVariant toVariant() const;
139 
145  bool loadVariant( const QVariantMap &map );
146 
147  // TODO c++20 - replace with = default
148  bool operator==( const QgsRemappingSinkDefinition &other ) const;
149  bool operator!=( const QgsRemappingSinkDefinition &other ) const;
150 
151  private:
152 
153  QMap< QString, QgsProperty > mFieldMap;
154 
155  QgsCoordinateReferenceSystem mSourceCrs;
156  QgsCoordinateReferenceSystem mDestinationCrs;
157 
158  QgsWkbTypes::Type mDestinationWkbType = QgsWkbTypes::Unknown;
159 
160  QgsFields mDestinationFields;
161 
162 };
163 
165 
166 
167 
168 
181 {
182  public:
183 
184 #ifndef SIP_RUN
185 
194  QgsRemappingProxyFeatureSink( const QgsRemappingSinkDefinition &mappingDefinition, QgsFeatureSink *sink, bool ownsSink = false );
195 #else
196 
202 #endif
203 
204  ~QgsRemappingProxyFeatureSink() override;
205 
209  void setExpressionContext( const QgsExpressionContext &context ) const;
210 
214  void setTransformContext( const QgsCoordinateTransformContext &context );
215 
219  QgsFeatureList remapFeature( const QgsFeature &feature ) const;
220 
221  bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
222  bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
223  bool addFeatures( QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
224  QString lastError() const override;
225 
229  QgsFeatureSink *destinationSink() { return mSink; }
230 
231  private:
232 
233  QgsRemappingSinkDefinition mDefinition;
234  QgsCoordinateTransform mTransform;
235  QgsFeatureSink *mSink = nullptr;
236  mutable QgsExpressionContext mContext;
237  bool mOwnsSink = false;
238 };
239 
240 #endif // QGSREMAPPINGPROXYFEATURESINK_H
241 
242 
243 
244 
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsRemappingProxyFeatureSink::destinationSink
QgsFeatureSink * destinationSink()
Returns the destination QgsFeatureSink which the proxy will forward features to.
Definition: qgsremappingproxyfeaturesink.h:229
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsRemappingSinkDefinition::setDestinationWkbType
void setDestinationWkbType(QgsWkbTypes::Type type)
Sets the WKB geometry type for the destination.
Definition: qgsremappingproxyfeaturesink.h:117
QgsProperty
A store for object properties.
Definition: qgsproperty.h:230
QgsRemappingSinkDefinition::setDestinationCrs
void setDestinationCrs(const QgsCoordinateReferenceSystem &destination)
Sets the destination crs used for reprojecting incoming features to the sink's destination CRS.
Definition: qgsremappingproxyfeaturesink.h:103
QgsRemappingSinkDefinition
Defines the parameters used to remap features when creating a QgsRemappingProxyFeatureSink.
Definition: qgsremappingproxyfeaturesink.h:38
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:425
QgsRemappingSinkDefinition::destinationCrs
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination CRS used for reprojecting incoming features to the sink's destination CRS.
Definition: qgsremappingproxyfeaturesink.h:96
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
qgsfeaturesink.h
QgsRemappingSinkDefinition::destinationWkbType
QgsWkbTypes::Type destinationWkbType() const
Returns the WKB geometry type for the destination.
Definition: qgsremappingproxyfeaturesink.h:110
qgis.h
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsRemappingSinkDefinition::fieldMap
QMap< QString, QgsProperty > fieldMap() const
Returns the field mapping, which defines how to map the values from incoming features to destination ...
Definition: qgsremappingproxyfeaturesink.h:52
operator!=
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:430
QgsRemappingSinkDefinition::setSourceCrs
void setSourceCrs(const QgsCoordinateReferenceSystem &source)
Sets the source crs used for reprojecting incoming features to the sink's destination CRS.
Definition: qgsremappingproxyfeaturesink.h:89
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:71
QgsRemappingSinkDefinition::setDestinationFields
void setDestinationFields(const QgsFields &fields)
Sets the fields for the destination sink.
Definition: qgsremappingproxyfeaturesink.h:131
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:882
QgsRemappingSinkDefinition::addMappedField
void addMappedField(const QString &destinationField, const QgsProperty &property)
Adds a mapping for a destination field.
Definition: qgsremappingproxyfeaturesink.h:75
qgscoordinatetransform.h
QgsRemappingSinkDefinition::destinationFields
QgsFields destinationFields() const
Returns the fields for the destination sink.
Definition: qgsremappingproxyfeaturesink.h:124
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsRemappingProxyFeatureSink
A QgsFeatureSink which proxies incoming features to a destination feature sink, after applying transf...
Definition: qgsremappingproxyfeaturesink.h:180
QgsRemappingSinkDefinition::setFieldMap
void setFieldMap(const QMap< QString, QgsProperty > &map)
Sets the field mapping, which defines how to map the values from incoming features to destination fie...
Definition: qgsremappingproxyfeaturesink.h:64
qgsproperty.h
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsRemappingSinkDefinition::sourceCrs
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source CRS used for reprojecting incoming features to the sink's destination CRS.
Definition: qgsremappingproxyfeaturesink.h:82
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:57
QgsFeatureIterator
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:289
QgsFeatureSink
An interface for objects which accept features via addFeature(s) methods.
Definition: qgsfeaturesink.h:33