QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsgcpgeometrytransformer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgcpgeometrytransformer.cpp
3  ----------------------
4  begin : February 2021
5  copyright : (C) 2021 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 
19 #include "qgsgeometry.h"
20 
22  : mGcpTransformer( gcpTransformer )
23 {
24 
25 }
26 
27 QgsGcpGeometryTransformer::QgsGcpGeometryTransformer( QgsGcpTransformerInterface::TransformMethod method, const QVector<QgsPointXY> &sourceCoordinates, const QVector<QgsPointXY> &destinationCoordinates )
28  : mGcpTransformer( QgsGcpTransformerInterface::createFromParameters( method, sourceCoordinates, destinationCoordinates ) )
29 {
30 
31 }
32 
34 
35 bool QgsGcpGeometryTransformer::transformPoint( double &x, double &y, double &, double & )
36 {
37  if ( !mGcpTransformer )
38  return false;
39 
40  return mGcpTransformer->transform( x, y );
41 }
42 
44 {
45  ok = false;
46  if ( geometry.isNull() )
47  {
48  ok = true;
49  return QgsGeometry();
50  }
51 
52  std::unique_ptr< QgsAbstractGeometry > res( geometry.constGet()->clone() );
53 
54  ok = res->transform( this, feedback );
55 
56  return QgsGeometry( std::move( res ) );
57 }
58 
60 {
61  return mGcpTransformer.get();
62 }
63 
65 {
66  mGcpTransformer.reset( gcpTransformer );
67 }
qgsgcpgeometrytransformer.h
QgsGcpGeometryTransformer::~QgsGcpGeometryTransformer
~QgsGcpGeometryTransformer() override
QgsGcpGeometryTransformer::transformPoint
bool transformPoint(double &x, double &y, double &z, double &m) override
Transforms the point defined by the coordinates (x, y, z) and the specified m value.
Definition: qgsgcpgeometrytransformer.cpp:35
QgsGcpGeometryTransformer::gcpTransformer
QgsGcpTransformerInterface * gcpTransformer() const
Returns the underlying GCP transformer used to transform geometries.
Definition: qgsgcpgeometrytransformer.cpp:59
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsAbstractGeometry::clone
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
QgsGeometry::isNull
bool isNull
Definition: qgsgeometry.h:127
QgsGcpGeometryTransformer::QgsGcpGeometryTransformer
QgsGcpGeometryTransformer(QgsGcpTransformerInterface *gcpTransformer)
Constructor for QgsGcpGeometryTransformer, which uses the specified gcpTransformer to modify geometri...
Definition: qgsgcpgeometrytransformer.cpp:21
QgsGeometry::constGet
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Definition: qgsgeometry.cpp:136
qgsgeometry.h
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsGcpGeometryTransformer::setGcpTransformer
void setGcpTransformer(QgsGcpTransformerInterface *transformer)
Sets the underlying GCP transformer used to transform geometries.
Definition: qgsgcpgeometrytransformer.cpp:64
QgsGcpTransformerInterface::TransformMethod
TransformMethod
Available transformation methods.
Definition: qgsgcptransformer.h:55
QgsGcpGeometryTransformer::transform
QgsGeometry transform(const QgsGeometry &geometry, bool &ok, QgsFeedback *feedback=nullptr)
Transforms the specified input geometry using the GCP based transform.
Definition: qgsgcpgeometrytransformer.cpp:43
QgsGcpTransformerInterface
An interface for Ground Control Points (GCP) based transformations.
Definition: qgsgcptransformer.h:33