QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgscoordinatetransform.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscoordinatetransform.h - Coordinate Transforms
3 ------------------------
4 begin : Dec 2004
5 copyright : (C) 2004 Tim Sutton
6 email : tim at linfiniti.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#ifndef QGSCOORDINATETRANSFORM_H
18#define QGSCOORDINATETRANSFORM_H
19
20#include <QExplicitlySharedDataPointer>
21
22#include "qgsconfig.h"
23#include "qgis_core.h"
24#include "qgis_sip.h"
27
28class QgsCoordinateTransformPrivate;
29class QgsPointXY;
30class QgsRectangle;
31class QPolygonF;
32class QgsProject;
33class QgsVector3D;
34
57class CORE_EXPORT QgsCoordinateTransform
58{
59
60 public:
61
64
92 const QgsCoordinateReferenceSystem &destination,
93 const QgsCoordinateTransformContext &context,
95
122 const QgsCoordinateReferenceSystem &destination,
123 const QgsProject *project,
125
133 Q_DECL_DEPRECATED explicit QgsCoordinateTransform( const QgsCoordinateReferenceSystem &source,
134 const QgsCoordinateReferenceSystem &destination,
135 int sourceDatumTransformId,
136 int destinationDatumTransformId ) SIP_DEPRECATED;
137
139 QgsCoordinateTransform &operator=( const QgsCoordinateTransform &o );
140
142
143 bool operator==( const QgsCoordinateTransform &other ) const;
144 bool operator!=( const QgsCoordinateTransform &other ) const;
145
158 static bool isTransformationPossible( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination );
159
164 bool isValid() const;
165
172 void setSourceCrs( const QgsCoordinateReferenceSystem &crs );
173
180 void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
181
187 void setContext( const QgsCoordinateTransformContext &context );
188
195 QgsCoordinateTransformContext context() const;
196
203 QgsCoordinateReferenceSystem sourceCrs() const;
204
211 QgsCoordinateReferenceSystem destinationCrs() const;
212
223
234 QgsPointXY transform( double x, double y, Qgis::TransformDirection direction = Qgis::TransformDirection::Forward ) const SIP_THROW( QgsCsException );
235
247
262 QgsRectangle transformBoundingBox( const QgsRectangle &rectangle, Qgis::TransformDirection direction = Qgis::TransformDirection::Forward, bool handle180Crossover = false ) const SIP_THROW( QgsCsException );
263
276 void transformInPlace( double &x, double &y, double &z, Qgis::TransformDirection direction = Qgis::TransformDirection::Forward ) const SIP_THROW( QgsCsException );
277
291 void transformInPlace( float &x, float &y, double &z, Qgis::TransformDirection direction = Qgis::TransformDirection::Forward ) const SIP_SKIP;
292
306 void transformInPlace( float &x, float &y, float &z, Qgis::TransformDirection direction = Qgis::TransformDirection::Forward ) const SIP_SKIP;
307
321 void transformInPlace( QVector<float> &x, QVector<float> &y, QVector<float> &z,
323
337 void transformInPlace( QVector<double> &x, QVector<double> &y, QVector<double> &z,
339
346 void transformPolygon( QPolygonF &polygon, Qgis::TransformDirection direction = Qgis::TransformDirection::Forward ) const SIP_THROW( QgsCsException );
347
358
370 void transformCoords( int numPoint, double *x, double *y, double *z, Qgis::TransformDirection direction = Qgis::TransformDirection::Forward ) const SIP_THROW( QgsCsException );
371
375 bool isShortCircuited() const;
376
383 bool hasVerticalComponent() const;
384
401 QString coordinateOperation() const;
402
416 QgsDatumTransform::TransformDetails instantiatedCoordinateOperationDetails() const;
417
431 void setCoordinateOperation( const QString &operation ) const;
432
447 void setAllowFallbackTransforms( bool allowed );
448
460 bool allowFallbackTransforms() const;
461
493 void setBallparkTransformsAreAppropriate( bool appropriate );
494
509 void disableFallbackOperationHandler( bool disabled );
510
519 bool fallbackOperationOccurred() const;
520
534 Q_DECL_DEPRECATED int sourceDatumTransformId() const SIP_DEPRECATED;
535
549 Q_DECL_DEPRECATED void setSourceDatumTransformId( int datumId ) SIP_DEPRECATED;
550
564 Q_DECL_DEPRECATED int destinationDatumTransformId() const SIP_DEPRECATED;
565
579 Q_DECL_DEPRECATED void setDestinationDatumTransformId( int datumId ) SIP_DEPRECATED;
580
581#ifndef SIP_RUN
582
592 static void invalidateCache( bool disableCache = false );
593#else
594
601 static void invalidateCache( bool disableCache SIP_PYARGREMOVE = false );
602#endif
603
613 double scaleFactor( const QgsRectangle &referenceExtent ) const;
614
615#ifdef SIP_RUN
616 SIP_PYOBJECT __repr__();
617 % MethodCode
618 QString str = QStringLiteral( "<QgsCoordinateTransform: %1 to %2>" ).arg( sipCpp->sourceCrs().isValid() ? sipCpp->sourceCrs().authid() : QStringLiteral( "NULL" ),
619 sipCpp->destinationCrs().isValid() ? sipCpp->destinationCrs().authid() : QStringLiteral( "NULL" ) );
620 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
621 % End
622#endif
623
624#ifndef SIP_RUN
625
638 static void setCustomMissingRequiredGridHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
639 const QgsCoordinateReferenceSystem &destinationCrs,
640 const QgsDatumTransform::GridDetails &grid )> &handler );
641
658 static void setCustomMissingPreferredGridHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
659 const QgsCoordinateReferenceSystem &destinationCrs,
660 const QgsDatumTransform::TransformDetails &preferredOperation,
661 const QgsDatumTransform::TransformDetails &availableOperation )> &handler );
662
675 static void setCustomCoordinateOperationCreationErrorHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
676 const QgsCoordinateReferenceSystem &destinationCrs,
677 const QString &error )> &handler );
678
691 static void setCustomMissingGridUsedByContextHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
692 const QgsCoordinateReferenceSystem &destinationCrs,
693 const QgsDatumTransform::TransformDetails &desiredOperation )> &handler );
694
695
702 static void setFallbackOperationOccurredHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
703 const QgsCoordinateReferenceSystem &destinationCrs,
704 const QString &desiredOperation )> &handler );
705
712 static void setDynamicCrsToDynamicCrsWarningHandler( const std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
713 const QgsCoordinateReferenceSystem &destinationCrs )> &handler );
714
715#endif
716
717 private:
718
719#ifndef SIP_RUN
720 friend class QgsProjContext;
721
722 // Only meant to be called by QgsProjContext::~QgsProjContext()
723 static void removeFromCacheObjectsBelongingToCurrentThread( void *pj_context );
724#endif
725
726 mutable QExplicitlySharedDataPointer<QgsCoordinateTransformPrivate> d;
727
730
731#ifdef QGISDEBUG
732 bool mHasContext = false;
733#endif
734
735 mutable QString mLastError;
736 bool mIgnoreImpossible = false;
737 bool mBallparkTransformsAreAppropriate = false;
738 bool mDisableFallbackHandler = false;
739 mutable bool mFallbackOperationOccurred = false;
740
741 bool setFromCache( const QgsCoordinateReferenceSystem &src,
743 const QString &coordinateOperationProj, bool allowFallback );
744
745 void addToCache();
746
747 // cache
748 static QReadWriteLock sCacheLock;
749
757 static QMultiHash< QPair< QString, QString >, QgsCoordinateTransform > sTransforms;
758 static bool sDisableCache;
759
760
761 static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
762 const QgsCoordinateReferenceSystem &destinationCrs,
763 const QString &desiredOperation )> sFallbackOperationOccurredHandler;
764
765 friend class TestQgsCoordinateTransform;
766
767};
768
770#ifndef SIP_RUN
771inline std::ostream &operator << ( std::ostream &os, const QgsCoordinateTransform &r )
772{
773 QString mySummary( QStringLiteral( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" ) );
774 mySummary += QLatin1String( "\n\tInitialized? : " );
775 //prevent warnings
776 if ( r.isValid() )
777 {
778 //do nothing this is a dummy
779 }
780
781#if 0
782 if ( r.isValid() )
783 {
784 mySummary += "Yes";
785 }
786 else
787 {
788 mySummary += "No";
789 }
790 mySummary += "\n\tShort Circuit? : ";
791 if ( r.isShortCircuited() )
792 {
793 mySummary += "Yes";
794 }
795 else
796 {
797 mySummary += "No";
798 }
799
800 mySummary += "\n\tSource Spatial Ref Sys : ";
801 if ( r.sourceCrs() )
802 {
803 mySummary << r.sourceCrs();
804 }
805 else
806 {
807 mySummary += "Undefined";
808 }
809
810 mySummary += "\n\tDest Spatial Ref Sys : ";
811 if ( r.destCRS() )
812 {
813 mySummary << r.destCRS();
814 }
815 else
816 {
817 mySummary += "Undefined";
818 }
819#endif
820
821 mySummary += QLatin1String( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
822 return os << mySummary.toLocal8Bit().data() << std::endl;
823}
824#endif
825
826
827#endif // QGSCOORDINATETRANSFORM_H
QFlags< CoordinateTransformationFlag > CoordinateTransformationFlags
Coordinate transformation flags.
Definition qgis.h:2525
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition qgis.h:2502
@ Forward
Forward transform (from source to destination)
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Class for doing transforms between two map coordinate systems.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source coordinate reference system, which the transform will transform coordinates from.
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent.
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
Custom exception class for Coordinate Reference System related exceptions.
A class to represent a 2D point.
Definition qgspointxy.h:60
Used to create and store a proj context object, correctly freeing the context upon destruction.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
A rectangle specified with double values.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:31
#define str(x)
Definition qgis.cpp:39
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_PYARGREMOVE
Definition qgis_sip.h:151
#define SIP_THROW(name,...)
Definition qgis_sip.h:203
std::ostream & operator<<(std::ostream &os, const QgsCoordinateTransform &r)
Output stream operator.
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
const QgsCoordinateReferenceSystem & crs
Contains information about a projection transformation grid file.
Contains information about a coordinate transformation operation.