QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
29 , mDestinationCrs( destinationCrs )
39 QVector<QgsPointXY> sourcePoints;
40 sourcePoints.reserve( mPoints.size() );
41 QVector<QgsPointXY> destinationPoints;
42 destinationPoints.reserve( mPoints.size() );
45 sourcePoints << gcpPoint.sourcePoint();
46 destinationPoints << gcpPoint.transformedDestinationPoint( mDestinationCrs, context );
82 mError = QObject::tr(
"An error occurred while transforming a feature" );
98 :
QgsTask( tr(
"Warping %1" ).arg( fileName ),
QgsTask::CanCancel )
101 , mDestinationCrs( destinationCrs )
102 , mDestFileName( fileName )
109 mFields = layer->
fields();
124 mFeedback = std::make_unique< QgsFeedback >();
128 const QString fileExtension = QFileInfo( mDestFileName ).completeSuffix();
131 std::unique_ptr< QgsVectorFileWriter > exporter(
QgsVectorFileWriter::create( mDestFileName, mFields, mWkbType, mDestinationCrs, mTransformContext, saveOptions ) );
132 if ( exporter->hasError() )
134 mErrorMessage = exporter->errorMessage();
143 const double newProgress = 100.0 * count / mFeatureCount;
145 if ( static_cast< int >( newProgress * 10 ) != static_cast< int >( mLastProgress * 10 ) )
147 mLastProgress = newProgress;
148 emit progressChanged( newProgress );
153 const bool res = warper.transformFeatures( iterator, exporter.get(), mTransformContext, mFeedback.get() );
156 mErrorMessage = warper.error();
157 mResult = Result::Error;
160 mResult = mFeedback->isCanceled() ? Result::Canceled : Result::Success;
162 return mResult == Result::Success;
bool transformFeatures(QgsFeatureIterator &iterator, QgsFeatureSink *sink, const QgsCoordinateTransformContext &context, QgsFeedback *feedback=nullptr) const
Transforms the features from iterator and adds the results to the specified sink.
static QgsVectorFileWriter * create(const QString &fileName, const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &srs, const QgsCoordinateTransformContext &transformContext, const QgsVectorFileWriter::SaveVectorOptions &options, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), QString *newFilename=nullptr, QString *newLayer=nullptr)
Create a new vector file writer.
Contains information about the context in which a coordinate transform is executed.
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Options to pass to writeAsVectorFormat()
Contains properties of a ground control point (GCP).
QgsVectorWarperTask(QgsGcpTransformerInterface::TransformMethod method, const QList< QgsGcpPoint > &points, const QgsCoordinateReferenceSystem &destinationCrs, QgsVectorLayer *layer, const QString &fileName)
Constructor for QgsVectorWarperTask.
void setProcessedCount(unsigned long long processedCount)
Sets the current processed objects count for the feedback object.
long long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
void processedCountChanged(unsigned long long processedCount)
Emitted when the feedback object reports a change in the number of processed objects.
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
Adds a single feature to the sink.
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
QgsVectorWarper(QgsGcpTransformerInterface::TransformMethod method, const QList< QgsGcpPoint > &points, const QgsCoordinateReferenceSystem &destinationCrs)
Constructor for QgsVectorWarper.
virtual void cancel()
Notifies the task that it should terminate.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Vector layer warper which warps vector layers based on a list of source and destination GCPs.
static QString driverForExtension(const QString &extension)
Returns the OGR driver name for a specified file extension.
This class represents a coordinate reference system (CRS).
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
void cancel() override
Notifies the task that it should terminate.
bool nextFeature(QgsFeature &f)
virtual QString lastError() const
Returns the most recent error encountered by the sink, e.g.
A geometry is the spatial representation of a feature.
Represents a vector layer which manages a vector based data sets.
Partial snapshot of vector layer's state (only the members necessary for access to features)
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool run() override
Performs the task's operation.
QString driverName
OGR driver to use.
Wrapper for iterator of features from vector data provider or vector layer.
An interface for objects which accept features via addFeature(s) methods.
@ Error
An error occurred while warping.
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
Abstract base class for long running background tasks. Tasks can be controlled directly,...