mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
- isInitialised() has been renamed to isValid() - theCRS parameter in setSourceCrs has been renamed to 'crs' - setDestCRS() has been renamed to setDestinationCrs() for consistency - destCRS() has been renamed to destinationCrs() for consistency - theSource, theDest, theSourceSrsId, theDestSrsId, theSourceWkt, theDestWkt, theSourceCRSType parameters in the QgsCoordinateTransform constructors have been renamed to source, destination, sourceSrsId, destinationSrsId, sourceWkt, destinationWkt, sourceCrsType respectively - 'p' argument in transform() has been renamed to 'point', 'theRect' to 'rectangle', 'poly' to 'polygon' - setDestCRSID has been removed, use setDestinationCrs() instead - 'theNode', 'theDoc' parameters in readXML and writeXML have been renamed to 'node' and 'document' respectively - readXML() and writeXML() have been renamed to readXml() and writeXml() for consistency
211 lines
10 KiB
Plaintext
211 lines
10 KiB
Plaintext
|
|
/** \ingroup core
|
|
* Class for doing transforms between two map coordinate systems.
|
|
*
|
|
* This class can convert map coordinates to a different coordinate reference system.
|
|
* It is normally associated with a map layer and is used to transform between the
|
|
* layer's coordinate system and the coordinate system of the map canvas, although
|
|
* it can be used in a more general sense to transform coordinates.
|
|
*
|
|
* When used to transform between a layer and the map canvas, all references to source
|
|
* and destination coordinate systems refer to layer and map canvas respectively. All
|
|
* operations are from the perspective of the layer. For example, a forward transformation
|
|
* transforms coordinates from the layer's coordinate system to the map canvas.
|
|
* \note Since QGIS 3.0 QgsCoordinateReferenceSystem objects are implicitly shared.
|
|
*/
|
|
|
|
class QgsCoordinateTransform
|
|
{
|
|
%TypeHeaderCode
|
|
#include <qgscoordinatetransform.h>
|
|
%End
|
|
|
|
public:
|
|
|
|
//! Enum used to indicate the direction (forward or inverse) of the transform
|
|
enum TransformDirection
|
|
{
|
|
ForwardTransform, /*!< Transform from source to destination CRS. */
|
|
ReverseTransform /*!< Transform from destination to source CRS. */
|
|
};
|
|
|
|
/** Default constructor, creates an invalid QgsCoordinateTransform. */
|
|
QgsCoordinateTransform();
|
|
|
|
/** Constructs a QgsCoordinateTransform using QgsCoordinateReferenceSystem objects.
|
|
* @param source source CRS, typically of the layer's coordinate system
|
|
* @param destination CRS, typically of the map canvas coordinate system
|
|
*/
|
|
QgsCoordinateTransform( const QgsCoordinateReferenceSystem& source,
|
|
const QgsCoordinateReferenceSystem& destination );
|
|
|
|
/** Constructs a QgsCoordinateTransform using CRS ID of source and destination CRS */
|
|
QgsCoordinateTransform( long sourceSrsId, long destinationSrsId );
|
|
|
|
/*!
|
|
* Constructs a QgsCoordinateTransform using the Well Known Text representation
|
|
* of the layer and map canvas coordinate systems
|
|
* @param sourceWkt WKT, typically of the layer's coordinate system
|
|
* @param destinationWkt WKT, typically of the map canvas coordinate system
|
|
*/
|
|
QgsCoordinateTransform( const QString& sourceWkt, const QString& destinationWkt );
|
|
|
|
/*!
|
|
* Constructs a QgsCoordinateTransform using a Spatial Reference Id
|
|
* of the layer and map canvas coordinate system as Wkt
|
|
* @param sourceSrid Spatial Ref Id of the layer's coordinate system
|
|
* @param destinationWkt Wkt of the map canvas coordinate system
|
|
* @param sourceCRSType On of the enum members defined in QgsCoordinateReferenceSystem::CrsType
|
|
*/
|
|
QgsCoordinateTransform( long sourceSrid,
|
|
const QString& destinationWkt,
|
|
QgsCoordinateReferenceSystem::CrsType sourceCRSType = QgsCoordinateReferenceSystem::PostgisCrsId );
|
|
|
|
/*!
|
|
* Returns true if the coordinate transform is valid, ie both the source and destination
|
|
* CRS have been set and are valid.
|
|
* @note added in QGIS 3.0
|
|
*/
|
|
bool isValid() const;
|
|
|
|
/*!
|
|
* Sets the source coordinate reference system.
|
|
* @param crs CRS to transform coordinates from
|
|
* @see sourceCrs()
|
|
* @see setDestinationCrs()
|
|
*/
|
|
void setSourceCrs( const QgsCoordinateReferenceSystem& crs );
|
|
|
|
/*!
|
|
* Sets the destination coordinate reference system.
|
|
* @param crs CRS to transform coordinates to
|
|
* @see destinationCrs()
|
|
* @see setSourceCrs()
|
|
*/
|
|
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
|
|
|
|
/** Returns the source coordinate reference system, which the transform will
|
|
* transform coordinates from.
|
|
* @see setSourceCrs()
|
|
* @see destinationCrs()
|
|
*/
|
|
QgsCoordinateReferenceSystem sourceCrs() const;
|
|
|
|
/** Returns the destination coordinate reference system, which the transform will
|
|
* transform coordinates to.
|
|
* @see setDestinationCrs()
|
|
* @see sourceCrs()
|
|
*/
|
|
QgsCoordinateReferenceSystem destinationCrs() const;
|
|
|
|
/** Transform the point from Source Coordinate System to Destination Coordinate System
|
|
* If the direction is ForwardTransform then coordinates are transformed from layer CS --> map canvas CS,
|
|
* otherwise points are transformed from map canvas CS to layerCS.
|
|
* @param point Point to transform
|
|
* @param direction TransformDirection (defaults to ForwardTransform)
|
|
* @return QgsPoint in Destination Coordinate System
|
|
*/
|
|
QgsPoint transform( const QgsPoint &point, TransformDirection direction = ForwardTransform ) const throw (QgsCsException);
|
|
|
|
/** Transform the point specified by x,y from Source Coordinate System to Destination Coordinate System
|
|
* If the direction is ForwardTransform then coordinates are transformed from layer CS --> map canvas CS,
|
|
* otherwise points are transformed from map canvas CS to layerCS.
|
|
* @param x x cordinate of point to transform
|
|
* @param y y coordinate of point to transform
|
|
* @param direction TransformDirection (defaults to ForwardTransform)
|
|
* @return QgsPoint in Destination Coordinate System
|
|
*/
|
|
QgsPoint transform( const double x, const double y, TransformDirection direction = ForwardTransform ) const throw (QgsCsException);
|
|
|
|
/** Transforms a QgsRectangle to the dest Coordinate system
|
|
* If the direction is ForwardTransform then coordinates are transformed from layer CS --> map canvas CS,
|
|
* otherwise points are transformed from map canvas CS to layerCS.
|
|
* It assumes that rect is a bounding box, and creates a bounding box
|
|
* in the proejcted CS, so that all points in source rectangle is within
|
|
* returned rectangle.
|
|
* @param rectangle rectangle to transform
|
|
* @param direction TransformDirection (defaults to ForwardTransform)
|
|
* @param handle180Crossover set to true if destination crs is geographic and handling of extents crossing the 180 degree
|
|
* longitude line is required
|
|
* @return QgsRectangle in Destination Coordinate System
|
|
*/
|
|
QgsRectangle transformBoundingBox( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform, const bool handle180Crossover = false ) const throw (QgsCsException);
|
|
|
|
// Same as for the other transform() functions, but alters the x
|
|
// and y variables in place. The second one works with good old-fashioned
|
|
// C style arrays.
|
|
void transformInPlace( double& x, double& y, double &z, TransformDirection direction = ForwardTransform ) const throw (QgsCsException);
|
|
|
|
// @note not available in python bindings
|
|
// void transformInPlace( float& x, float& y, double &z, TransformDirection direction = ForwardTransform ) const;
|
|
// @note not available in python bindings
|
|
// void transformInPlace( float& x, float& y, float& z, TransformDirection direction = ForwardTransform ) const;
|
|
// @note not available in python bindings
|
|
// void transformInPlace( QVector<float>& x, QVector<float>& y, QVector<float>& z,
|
|
// TransformDirection direction = ForwardTransform ) const;
|
|
|
|
//! @note not available in python bindings
|
|
// void transformInPlace( QVector<double>& x, QVector<double>& y, QVector<double>& z,
|
|
// TransformDirection direction = ForwardTransform ) const;
|
|
|
|
void transformPolygon( QPolygonF& polygon, TransformDirection direction = ForwardTransform ) const;
|
|
|
|
/** Transform a QgsRectangle to the dest Coordinate system
|
|
* If the direction is ForwardTransform then coordinates are transformed from layer CS --> map canvas CS,
|
|
* otherwise points are transformed from map canvas CS to layerCS.
|
|
* @param rectangle rect to transform
|
|
* @param direction TransformDirection (defaults to ForwardTransform)
|
|
* @return QgsRectangle in Destination Coordinate System
|
|
*/
|
|
QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const throw (QgsCsException);
|
|
|
|
/** Transform an array of coordinates to a different Coordinate System
|
|
* If the direction is ForwardTransform then coordinates are transformed from layer CS --> map canvas CS,
|
|
* otherwise points are transformed from map canvas CS to layerCS.
|
|
* @param numPoint number of coordinates in arrays
|
|
* @param x array of x coordinates to transform
|
|
* @param y array of y coordinates to transform
|
|
* @param z array of z coordinates to transform
|
|
* @param direction TransformDirection (defaults to ForwardTransform)
|
|
* @return QgsRectangle in Destination Coordinate System
|
|
*/
|
|
void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const throw (QgsCsException);
|
|
|
|
/** Returns true if the transform short circuits because the source and destination are equivalent.
|
|
*/
|
|
bool isShortCircuited() const;
|
|
|
|
/** Returns list of datum transformations for the given src and dest CRS
|
|
* @note not available in python bindings
|
|
*/
|
|
// static QList< QList< int > > datumTransformations( const QgsCoordinateReferenceSystem& srcCRS, const QgsCoordinateReferenceSystem& destCRS );
|
|
static QString datumTransformString( int datumTransform );
|
|
/** Gets name of source and dest geographical CRS (to show in a tooltip)
|
|
@return epsgNr epsg code of the transformation (or 0 if not in epsg db)*/
|
|
static bool datumTransformCrsInfo( int datumTransform, int& epsgNr, QString& srcProjection, QString& dstProjection, QString &remarks, QString &scope, bool &preferred, bool &deprecated );
|
|
|
|
int sourceDatumTransform() const;
|
|
void setSourceDatumTransform( int dt );
|
|
int destinationDatumTransform() const;
|
|
void setDestinationDatumTransform( int dt );
|
|
|
|
//!initialize is used to actually create the Transformer instance
|
|
void initialise();
|
|
|
|
/** Restores state from the given Dom node.
|
|
* @param node The node from which state will be restored
|
|
* @return bool True on success, False on failure
|
|
* @see writeXml()
|
|
*/
|
|
bool readXml( const QDomNode& node );
|
|
|
|
/** Stores state to the given Dom node in the given document
|
|
* @param node The node in which state will be restored
|
|
* @param document The document in which state will be stored
|
|
* @return bool True on success, False on failure
|
|
* @see readXml()
|
|
*/
|
|
bool writeXml( QDomNode & node, QDomDocument & document ) const;
|
|
|
|
};
|