API breaks and cleanups for QgsCoordinateTransform

- 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
This commit is contained in:
Nyall Dawson 2016-07-16 16:31:05 +10:00
parent 353ed54f1f
commit ffa9b9b676
20 changed files with 238 additions and 180 deletions

View File

@ -26,6 +26,15 @@ not slots. The invalidTransformInput() signal has been removed.</li>
<li>QgsCoordinateTransform::clone() has been removed. Just use direct copies instead.</li>
<li>sourceCrs() and destCrs() now return a copy instead of a reference to the CRS. This has no effect on PyQGIS code, but c++
plugins calling these methods will need to be updated.</li>
<li>isInitialised() has been renamed to isValid()</li>
<li>theCRS parameter in setSourceCrs has been renamed to 'crs'</li>
<li>setDestCRS() has been renamed to setDestinationCrs() for consistency</li>
<li>destCRS() has been renamed to destinationCrs() for consistency</li>
<li>theSource, theDest, theSourceSrsId, theDestSrsId, theSourceWkt, theDestWkt, theSourceCRSType parameters in the QgsCoordinateTransform constructors have been renamed to source, destination, sourceSrsId, destinationSrsId, sourceWkt, destinationWkt, sourceCrsType respectively</li>
<li>'p' argument in transform() has been renamed to 'point', 'theRect' to 'rectangle', 'poly' to 'polygon'</li>
<li>setDestCRSID has been removed, use setDestinationCrs() instead</li>
<li>'theNode', 'theDoc' parameters in readXML and writeXML have been renamed to 'node' and 'document' respectively</li>
<li>readXML() and writeXML() have been renamed to readXml() and writeXml() for consistency</li>
</ul>
\subsection qgis_api_break_3_0_DataProviders Data Providers

View File

@ -33,69 +33,79 @@ class QgsCoordinateTransform
QgsCoordinateTransform();
/** Constructs a QgsCoordinateTransform using QgsCoordinateReferenceSystem objects.
* @param theSource CRS, typically of the layer's coordinate system
* @param theDest CRS, typically of the map canvas coordinate system
* @param source source CRS, typically of the layer's coordinate system
* @param destination CRS, typically of the map canvas coordinate system
*/
QgsCoordinateTransform( const QgsCoordinateReferenceSystem& theSource,
const QgsCoordinateReferenceSystem& theDest );
QgsCoordinateTransform( const QgsCoordinateReferenceSystem& source,
const QgsCoordinateReferenceSystem& destination );
/** Constructs a QgsCoordinateTransform using CRS ID of source and destination CRS */
QgsCoordinateTransform( long theSourceSrsId, long theDestSrsId );
QgsCoordinateTransform( long sourceSrsId, long destinationSrsId );
/*!
* Constructs a QgsCoordinateTransform using the Well Known Text representation
* of the layer and map canvas coordinate systems
* @param theSourceWkt Wkt, typically of the layer's coordinate system
* @param theDestWkt Wkt, typically of the map canvas coordinate system
* @param sourceWkt WKT, typically of the layer's coordinate system
* @param destinationWkt WKT, typically of the map canvas coordinate system
*/
QgsCoordinateTransform( const QString& theSourceWkt, const QString& theDestWkt );
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 theSourceSrid Spatial Ref Id of the layer's coordinate system
* @param theDestWkt Wkt of the map canvas coordinate system
* @param theSourceCRSType On of the enum members defined in QgsCoordinateReferenceSystem::CrsType
* @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 theSourceSrid,
const QString& theDestWkt,
QgsCoordinateReferenceSystem::CrsType theSourceCRSType = QgsCoordinateReferenceSystem::PostgisCrsId );
//! destructor
~QgsCoordinateTransform();
QgsCoordinateTransform( long sourceSrid,
const QString& destinationWkt,
QgsCoordinateReferenceSystem::CrsType sourceCRSType = QgsCoordinateReferenceSystem::PostgisCrsId );
/*!
* Set the source (layer) QgsCoordinateReferenceSystem
* @param theCRS QgsCoordinateReferenceSystem representation of the layer's coordinate system
* 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
*/
void setSourceCrs( const QgsCoordinateReferenceSystem& theCRS );
bool isValid() const;
/*!
* Mutator for dest QgsCoordinateReferenceSystem
* @param theCRS of the destination coordinate system
* Sets the source coordinate reference system.
* @param crs CRS to transform coordinates from
* @see sourceCrs()
* @see setDestinationCrs()
*/
void setDestCRS( const QgsCoordinateReferenceSystem& theCRS );
void setSourceCrs( const QgsCoordinateReferenceSystem& crs );
/*!
* Get the QgsCoordinateReferenceSystem representation of the layer's coordinate system
* @return QgsCoordinateReferenceSystem of the layer's coordinate system
* 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;
/*!
* Get the QgsCoordinateReferenceSystem representation of the map canvas coordinate system
* @return QgsCoordinateReferenceSystem of the map canvas coordinate system
/** Returns the destination coordinate reference system, which the transform will
* transform coordinates to.
* @see setDestinationCrs()
* @see sourceCrs()
*/
QgsCoordinateReferenceSystem destCRS() const;
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 p Point to transform
* @param point Point to transform
* @param direction TransformDirection (defaults to ForwardTransform)
* @return QgsPoint in Destination Coordinate System
*/
QgsPoint transform( const QgsPoint &p, TransformDirection direction = ForwardTransform ) const throw (QgsCsException);
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,
@ -107,19 +117,19 @@ class QgsCoordinateTransform
*/
QgsPoint transform( const double x, const double y, TransformDirection direction = ForwardTransform ) const throw (QgsCsException);
/** Transform a QgsRectangle to the dest Coordinate system
/** 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 theRect rect to transform
* @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 &theRect, TransformDirection direction = ForwardTransform, const bool handle180Crossover = false ) const throw (QgsCsException);
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
@ -138,16 +148,16 @@ class QgsCoordinateTransform
// void transformInPlace( QVector<double>& x, QVector<double>& y, QVector<double>& z,
// TransformDirection direction = ForwardTransform ) const;
void transformPolygon( QPolygonF& poly, 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 theRect rect to transform
* @param rectangle rect to transform
* @param direction TransformDirection (defaults to ForwardTransform)
* @return QgsRectangle in Destination Coordinate System
*/
QgsRectangle transform( const QgsRectangle &theRect, TransformDirection direction = ForwardTransform ) const throw (QgsCsException);
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,
@ -161,28 +171,10 @@ class QgsCoordinateTransform
*/
void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const throw (QgsCsException);
/*!
* Flag to indicate whether the coordinate systems have been initialized
* @return true if initialized, otherwise false
*/
bool isInitialised() const;
/** See if the transform short circuits because src and dest are equivalent
* @return bool True if it short circuits
/** Returns true if the transform short circuits because the source and destination are equivalent.
*/
bool isShortCircuited() const;
/** Change the destination coordinate system by passing it a qgis srsid
* A QGIS srsid is a unique key value to an entry on the tbl_srs in the
* srs.db sqlite database.
* @note This slot will usually be called if the
* project properties change and a different coordinate system is
* selected.
* @note This coord transform will be reinitialized when this slot is called
* to check if short circuiting is needed or not etc.
* @param theCRSID - A long representing the srsid of the srs to be used */
void setDestCRSID( long theCRSID );
/** Returns list of datum transformations for the given src and dest CRS
* @note not available in python bindings
*/
@ -201,16 +193,18 @@ class QgsCoordinateTransform
void initialise();
/** Restores state from the given Dom node.
* @param theNode The node from which state will be restored
* @param node The node from which state will be restored
* @return bool True on success, False on failure
* @see writeXml()
*/
bool readXML( const QDomNode & theNode );
bool readXml( const QDomNode& node );
/** Stores state to the given Dom node in the given document
* @param theNode The node in which state will be restored
* @param theDoc The document in which state will be stored
* @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 & theNode, QDomDocument & theDoc ) const;
bool writeXml( QDomNode & node, QDomDocument & document ) const;
};

View File

@ -140,11 +140,11 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
ct.setSourceCrs( vl->crs() );
if ( builder->coordinateTransformationEnabled() )
{
ct.setDestCRS( builder->destinationCrs() );
ct.setDestinationCrs( builder->destinationCrs() );
}
else
{
ct.setDestCRS( vl->crs() );
ct.setDestinationCrs( vl->crs() );
}
tiedPoint = QVector< QgsPoint >( additionalPoints.size(), QgsPoint( 0.0, 0.0 ) );

View File

@ -2404,7 +2404,7 @@ int QgsComposerMapGrid::crsGridParams( QgsRectangle& crsRect, QgsCoordinateTrans
}
inverseTransform.setSourceCrs( mCRS );
inverseTransform.setDestCRS( mComposerMap->composition()->mapSettings().destinationCrs() );
inverseTransform.setDestinationCrs( mComposerMap->composition()->mapSettings().destinationCrs() );
}
catch ( QgsCsException & cse )
{

View File

@ -80,7 +80,7 @@ void QgsCoordinateTransform::setSourceCrs( const QgsCoordinateReferenceSystem& c
d->mSourceCRS = crs;
d->initialise();
}
void QgsCoordinateTransform::setDestCRS( const QgsCoordinateReferenceSystem& crs )
void QgsCoordinateTransform::setDestinationCrs( const QgsCoordinateReferenceSystem& crs )
{
d.detach();
d->mDestCRS = crs;
@ -92,20 +92,11 @@ QgsCoordinateReferenceSystem QgsCoordinateTransform::sourceCrs() const
return d->mSourceCRS;
}
QgsCoordinateReferenceSystem QgsCoordinateTransform::destCRS() const
QgsCoordinateReferenceSystem QgsCoordinateTransform::destinationCrs() const
{
return d->mDestCRS;
}
void QgsCoordinateTransform::setDestCRSID( long crsId )
{
//!todo Add some logic here to determine if the srsid is a system or user one
d.detach();
d->mDestCRS = QgsCRSCache::instance()->crsBySrsId( crsId );
d->initialise();
}
QgsPoint QgsCoordinateTransform::transform( const QgsPoint &thePoint, TransformDirection direction ) const
{
if ( !d->mIsValid || d->mShortCircuit )
@ -574,17 +565,17 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
#endif
}
bool QgsCoordinateTransform::isInitialised() const
bool QgsCoordinateTransform::isValid() const
{
return d->mIsValid;
}
bool QgsCoordinateTransform::isShortCircuited() const
{
return d->mShortCircuit;
return !d->mIsValid || d->mShortCircuit;
}
bool QgsCoordinateTransform::readXML( const QDomNode & theNode )
bool QgsCoordinateTransform::readXml( const QDomNode & theNode )
{
d.detach();
@ -602,7 +593,7 @@ bool QgsCoordinateTransform::readXML( const QDomNode & theNode )
return d->initialise();
}
bool QgsCoordinateTransform::writeXML( QDomNode & theNode, QDomDocument & theDoc ) const
bool QgsCoordinateTransform::writeXml( QDomNode & theNode, QDomDocument & theDoc ) const
{
QDomElement myNodeElement = theNode.toElement();
QDomElement myTransformElement = theDoc.createElement( "coordinatetransform" );

View File

@ -57,66 +57,80 @@ class CORE_EXPORT QgsCoordinateTransform
QgsCoordinateTransform();
/** Constructs a QgsCoordinateTransform using QgsCoordinateReferenceSystem objects.
* @param theSource CRS, typically of the layer's coordinate system
* @param theDest CRS, typically of the map canvas coordinate system
* @param source source CRS, typically of the layer's coordinate system
* @param destination CRS, typically of the map canvas coordinate system
*/
QgsCoordinateTransform( const QgsCoordinateReferenceSystem& theSource,
const QgsCoordinateReferenceSystem& theDest );
QgsCoordinateTransform( const QgsCoordinateReferenceSystem& source,
const QgsCoordinateReferenceSystem& destination );
/** Constructs a QgsCoordinateTransform using CRS ID of source and destination CRS */
QgsCoordinateTransform( long theSourceSrsId, long theDestSrsId );
QgsCoordinateTransform( long sourceSrsId, long destinationSrsId );
/*!
* Constructs a QgsCoordinateTransform using the Well Known Text representation
* of the layer and map canvas coordinate systems
* @param theSourceWkt Wkt, typically of the layer's coordinate system
* @param theDestWkt Wkt, typically of the map canvas coordinate system
* @param sourceWkt WKT, typically of the layer's coordinate system
* @param destinationWkt WKT, typically of the map canvas coordinate system
*/
QgsCoordinateTransform( const QString& theSourceWkt, const QString& theDestWkt );
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 theSourceSrid Spatial Ref Id of the layer's coordinate system
* @param theDestWkt Wkt of the map canvas coordinate system
* @param theSourceCRSType On of the enum members defined in QgsCoordinateReferenceSystem::CrsType
* @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 theSourceSrid,
const QString& theDestWkt,
QgsCoordinateReferenceSystem::CrsType theSourceCRSType = QgsCoordinateReferenceSystem::PostgisCrsId );
QgsCoordinateTransform( long sourceSrid,
const QString& destinationWkt,
QgsCoordinateReferenceSystem::CrsType sourceCrsType = QgsCoordinateReferenceSystem::PostgisCrsId );
/*!
* Set the source (layer) QgsCoordinateReferenceSystem
* @param theCRS QgsCoordinateReferenceSystem representation of the layer's coordinate system
* 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
*/
void setSourceCrs( const QgsCoordinateReferenceSystem& theCRS );
bool isValid() const;
/*!
* Mutator for dest QgsCoordinateReferenceSystem
* @param theCRS of the destination coordinate system
* Sets the source coordinate reference system.
* @param crs CRS to transform coordinates from
* @see sourceCrs()
* @see setDestinationCrs()
*/
void setDestCRS( const QgsCoordinateReferenceSystem& theCRS );
void setSourceCrs( const QgsCoordinateReferenceSystem& crs );
/*!
* Get the QgsCoordinateReferenceSystem representation of the layer's coordinate system
* @return QgsCoordinateReferenceSystem of the layer's coordinate system
* 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;
/*!
* Get the QgsCoordinateReferenceSystem representation of the map canvas coordinate system
* @return QgsCoordinateReferenceSystem of the map canvas coordinate system
/** Returns the destination coordinate reference system, which the transform will
* transform coordinates to.
* @see setDestinationCrs()
* @see sourceCrs()
*/
QgsCoordinateReferenceSystem destCRS() const;
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 p Point to transform
* @param point Point to transform
* @param direction TransformDirection (defaults to ForwardTransform)
* @return QgsPoint in Destination Coordinate System
*/
QgsPoint transform( const QgsPoint &p, TransformDirection direction = ForwardTransform ) const;
QgsPoint transform( const QgsPoint& point, TransformDirection direction = ForwardTransform ) const;
/** 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,
@ -128,19 +142,19 @@ class CORE_EXPORT QgsCoordinateTransform
*/
QgsPoint transform( const double x, const double y, TransformDirection direction = ForwardTransform ) const;
/** Transform a QgsRectangle to the dest Coordinate system
/** Transforms a QgsRectangle to the desttination 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 theRect rect to transform
* @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 &theRect, TransformDirection direction = ForwardTransform, const bool handle180Crossover = false ) const;
QgsRectangle transformBoundingBox( const QgsRectangle& rectangle, TransformDirection direction = ForwardTransform, const bool handle180Crossover = false ) const;
// Same as for the other transform() functions, but alters the x
// and y variables in place. The second one works with good old-fashioned
@ -159,16 +173,16 @@ class CORE_EXPORT QgsCoordinateTransform
void transformInPlace( QVector<double>& x, QVector<double>& y, QVector<double>& z,
TransformDirection direction = ForwardTransform ) const;
void transformPolygon( QPolygonF& poly, 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 theRect rect to transform
* @param rectangle rectangle to transform
* @param direction TransformDirection (defaults to ForwardTransform)
* @return QgsRectangle in Destination Coordinate System
*/
QgsRectangle transform( const QgsRectangle &theRect, TransformDirection direction = ForwardTransform ) const;
QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const;
/** 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,
@ -182,32 +196,14 @@ class CORE_EXPORT QgsCoordinateTransform
*/
void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
/*!
* Flag to indicate whether the coordinate systems have been initialized
* @return true if initialized, otherwise false
*/
bool isInitialised() const;
/** See if the transform short circuits because src and dest are equivalent
* @return bool True if it short circuits
/** Returns true if the transform short circuits because the source and destination are equivalent.
*/
bool isShortCircuited() const;
/** Change the destination coordinate system by passing it a qgis srsid
* A QGIS srsid is a unique key value to an entry on the tbl_srs in the
* srs.db sqlite database.
* @note This slot will usually be called if the
* project properties change and a different coordinate system is
* selected.
* @note This coord transform will be reinitialized when this slot is called
* to check if short circuiting is needed or not etc.
* @param theCRSID - A long representing the srsid of the srs to be used */
void setDestCRSID( long theCRSID );
/** 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 QList< QList< int > > datumTransformations( const QgsCoordinateReferenceSystem& srcCRS, const QgsCoordinateReferenceSystem& destinationCrs );
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)*/
@ -222,17 +218,19 @@ class CORE_EXPORT QgsCoordinateTransform
void initialise();
/** Restores state from the given Dom node.
* @param theNode The node from which state will be restored
* @param node The node from which state will be restored
* @return bool True on success, False on failure
* @see writeXml()
*/
bool readXML( const QDomNode& theNode );
bool readXml( const QDomNode& node );
/** Stores state to the given Dom node in the given document
* @param theNode The node in which state will be restored
* @param theDoc The document in which state will be stored
* @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 & theNode, QDomDocument & theDoc ) const;
bool writeXml( QDomNode & node, QDomDocument & document ) const;
private:
@ -247,13 +245,13 @@ inline std::ostream& operator << ( std::ostream& os, const QgsCoordinateTransfor
QString mySummary( "\n%%%%%%%%%%%%%%%%%%%%%%%%\nCoordinate Transform def begins:" );
mySummary += "\n\tInitialised? : ";
//prevent warnings
if ( r.isInitialised() )
if ( r.isValid() )
{
//do nothing this is a dummy
}
#if 0
if ( r.isInitialised() )
if ( r.isValid() )
{
mySummary += "Yes";
}

View File

@ -54,7 +54,7 @@ QgsDiagramLayerSettings::QgsDiagramLayerSettings( const QgsDiagramLayerSettings&
, obstacle( rh.obstacle )
, dist( rh.dist )
, renderer( rh.renderer ? rh.renderer->clone() : nullptr )
, ct( rh.ct ? new QgsCoordinateTransform( *rh.ct ): nullptr )
, ct( rh.ct ? new QgsCoordinateTransform( *rh.ct ) : nullptr )
, xform( rh.xform )
, fields( rh.fields )
, xPosColumn( rh.xPosColumn )

View File

@ -91,7 +91,7 @@ void QgsDistanceArea::_copy( const QgsDistanceArea & origDA )
// Alternatively we could copy the temp vars?
computeAreaInit();
delete mCoordTransform;
mCoordTransform = new QgsCoordinateTransform( origDA.mCoordTransform->sourceCrs(), origDA.mCoordTransform->destCRS() );
mCoordTransform = new QgsCoordinateTransform( origDA.mCoordTransform->sourceCrs(), origDA.mCoordTransform->destinationCrs() );
}
void QgsDistanceArea::setEllipsoidalMode( bool flag )
@ -241,7 +241,7 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )
//
// set transformation from project CRS to ellipsoid coordinates
mCoordTransform->setDestCRS( destCRS );
mCoordTransform->setDestinationCrs( destCRS );
mEllipsoid = ellipsoid;
@ -509,7 +509,7 @@ double QgsDistanceArea::measureLine( const QgsPoint& p1, const QgsPoint& p2, QGi
units = QGis::Meters;
QgsDebugMsgLevel( QString( "Ellipsoidal calculations is enabled, using ellipsoid %1" ).arg( mEllipsoid ), 4 );
QgsDebugMsgLevel( QString( "From proj4 : %1" ).arg( mCoordTransform->sourceCrs().toProj4() ), 4 );
QgsDebugMsgLevel( QString( "To proj4 : %1" ).arg( mCoordTransform->destCRS().toProj4() ), 4 );
QgsDebugMsgLevel( QString( "To proj4 : %1" ).arg( mCoordTransform->destinationCrs().toProj4() ), 4 );
pp1 = mCoordTransform->transform( p1 );
pp2 = mCoordTransform->transform( p2 );
QgsDebugMsgLevel( QString( "New points are %1 and %2, calculating..." ).arg( pp1.toString( 4 ), pp2.toString( 4 ) ), 4 );

View File

@ -34,7 +34,7 @@ QgsJSONExporter::QgsJSONExporter( const QgsVectorLayer* vectorLayer, int precisi
mCrs = vectorLayer->crs();
mTransform.setSourceCrs( mCrs );
}
mTransform.setDestCRS( QgsCoordinateReferenceSystem( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ) );
mTransform.setDestinationCrs( QgsCoordinateReferenceSystem( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ) );
}
void QgsJSONExporter::setVectorLayer( const QgsVectorLayer* vectorLayer )

View File

@ -818,7 +818,7 @@ QgsRectangle QgsMapRenderer::outputExtentToLayerExtent( QgsMapLayer* theLayer, Q
#if QGISDEBUG
const QgsCoordinateTransform *transform = transformation( theLayer );
QgsDebugMsg( QString( "layer sourceCrs = " + ( transform ? transform->sourceCrs().authid() : "none" ) ) );
QgsDebugMsg( QString( "layer destCRS = " + ( transform ? transform->destCRS().authid() : "none" ) ) );
QgsDebugMsg( QString( "layer destCRS = " + ( transform ? transform->destinationCrs().authid() : "none" ) ) );
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
#endif
if ( hasCrsTransformEnabled() )

View File

@ -82,7 +82,7 @@ bool QgsMapRendererJob::reprojectToLayerExtent( const QgsMapLayer *ml, const Qgs
if ( ml->crs().geographicFlag() )
{
if ( ml->type() == QgsMapLayer::VectorLayer && !ct->destCRS().geographicFlag() )
if ( ml->type() == QgsMapLayer::VectorLayer && !ct->destinationCrs().geographicFlag() )
{
// if we transform from a projected coordinate system check
// check if transforming back roughly returns the input
@ -143,7 +143,7 @@ bool QgsMapRendererJob::reprojectToLayerExtent( const QgsMapLayer *ml, const Qgs
}
else // can't cross 180
{
if ( ct->destCRS().geographicFlag() &&
if ( ct->destinationCrs().geographicFlag() &&
( extent.xMinimum() <= -180 || extent.xMaximum() >= 180 ||
extent.yMinimum() <= -90 || extent.yMaximum() >= 90 ) )
// Use unlimited rectangle because otherwise we may end up transforming wrong coordinates.

View File

@ -398,7 +398,7 @@ QgsRectangle QgsMapSettings::layerExtentToOutputExtent( QgsMapLayer* theLayer, Q
if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
{
QgsDebugMsg( QString( "sourceCrs = " + ct->sourceCrs().authid() ) );
QgsDebugMsg( QString( "destCRS = " + ct->destCRS().authid() ) );
QgsDebugMsg( QString( "destCRS = " + ct->destinationCrs().authid() ) );
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
extent = ct->transformBoundingBox( extent );
}
@ -424,7 +424,7 @@ QgsRectangle QgsMapSettings::outputExtentToLayerExtent( QgsMapLayer* theLayer, Q
if ( const QgsCoordinateTransform* ct = layerTransform( theLayer ) )
{
QgsDebugMsg( QString( "sourceCrs = " + ct->sourceCrs().authid() ) );
QgsDebugMsg( QString( "destCRS = " + ct->destCRS().authid() ) );
QgsDebugMsg( QString( "destCRS = " + ct->destinationCrs().authid() ) );
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
extent = ct->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
}

View File

@ -641,7 +641,7 @@ QgsPointLocator::~QgsPointLocator()
QgsCoordinateReferenceSystem QgsPointLocator::destCRS() const
{
return mTransform ? mTransform->destCRS() : QgsCoordinateReferenceSystem();
return mTransform ? mTransform->destinationCrs() : QgsCoordinateReferenceSystem();
}
void QgsPointLocator::setExtent( const QgsRectangle* extent )

View File

@ -2161,7 +2161,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
if ( ct )
{
// This means we should transform
outputCRS = ct->destCRS();
outputCRS = ct->destinationCrs();
shallTransform = true;
}
else
@ -2319,7 +2319,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe
QGis::UnitType mapUnits = layer->crs().mapUnits();
if ( ct )
{
mapUnits = ct->destCRS().mapUnits();
mapUnits = ct->destinationCrs().mapUnits();
}
writer->startRender( layer );
@ -2601,7 +2601,7 @@ void QgsVectorFileWriter::createSymbolLayerTable( QgsVectorLayer* vl, const Qgs
QGis::UnitType mapUnits = vl->crs().mapUnits();
if ( ct )
{
mapUnits = ct->destCRS().mapUnits();
mapUnits = ct->destinationCrs().mapUnits();
}
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1700
@ -2652,7 +2652,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::exportFeaturesSymbolLevels
QGis::UnitType mapUnits = layer->crs().mapUnits();
if ( ct )
{
mapUnits = ct->destCRS().mapUnits();
mapUnits = ct->destinationCrs().mapUnits();
}
startRender( layer );

View File

@ -106,7 +106,7 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer* layer, QgsRender
if ( rendererContext.coordinateTransform() )
{
mRasterViewPort->mSrcCRS = layer->crs();
mRasterViewPort->mDestCRS = rendererContext.coordinateTransform()->destCRS();
mRasterViewPort->mDestCRS = rendererContext.coordinateTransform()->destinationCrs();
mRasterViewPort->mSrcDatumTransform = rendererContext.coordinateTransform()->sourceDatumTransform();
mRasterViewPort->mDestDatumTransform = rendererContext.coordinateTransform()->destinationDatumTransform();
}

View File

@ -97,7 +97,7 @@ void CoordinateCapture::initGui()
connect( mQGisIface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
setSourceCrs(); //set up the source CRS
mTransform.setDestCRS( mCrs ); // set the CRS in the transform
mTransform.setDestinationCrs( mCrs ); // set the CRS in the transform
mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 5 : 3; // precision depends on CRS units
//create the dock widget
@ -190,7 +190,7 @@ void CoordinateCapture::setCRS()
if ( mySelector.exec() )
{
mCrs.createFromSrsId( mySelector.selectedCrsId() );
mTransform.setDestCRS( mCrs );
mTransform.setDestinationCrs( mCrs );
mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 5 : 3; //precision depends on CRS units
}
}

View File

@ -930,7 +930,7 @@ void QgsGrassPlugin::setTransform()
QgsDebugMsg( "srcCrs: " + mCrs.toWkt() );
QgsDebugMsg( "destCrs " + mCanvas->mapSettings().destinationCrs().toWkt() );
mCoordinateTransform.setSourceCrs( mCrs );
mCoordinateTransform.setDestCRS( mCanvas->mapSettings().destinationCrs() );
mCoordinateTransform.setDestinationCrs( mCanvas->mapSettings().destinationCrs() );
}
}

View File

@ -113,7 +113,7 @@ void QgsGrassRegionEdit::calcSrcRegion()
{
QgsCoordinateTransform coordinateTransform;
coordinateTransform.setSourceCrs( mCanvas->mapSettings().destinationCrs() );
coordinateTransform.setDestCRS( mCrs );
coordinateTransform.setDestinationCrs( mCrs );
mSrcRectangle = coordinateTransform.transformBoundingBox( mSrcRectangle );
}
}
@ -123,7 +123,7 @@ void QgsGrassRegionEdit::setTransform()
if ( mCrs.isValid() && canvas()->mapSettings().destinationCrs().isValid() )
{
mCoordinateTransform.setSourceCrs( mCrs );
mCoordinateTransform.setDestCRS( canvas()->mapSettings().destinationCrs() );
mCoordinateTransform.setDestinationCrs( canvas()->mapSettings().destinationCrs() );
}
}

View File

@ -572,7 +572,7 @@ bool QgsGrassVectorImport::import()
if ( providerCrs.isValid() && mapsetCrs.isValid() && providerCrs != mapsetCrs )
{
coordinateTransform.setSourceCrs( providerCrs );
coordinateTransform.setDestCRS( mapsetCrs );
coordinateTransform.setDestinationCrs( mapsetCrs );
doTransform = true;
}

View File

@ -30,6 +30,8 @@ class TestQgsCoordinateTransform: public QObject
void transformBoundingBox();
void copy();
void assignment();
void isValid();
void isShortCircuited();
private:
@ -52,7 +54,7 @@ void TestQgsCoordinateTransform::copy()
{
QgsCoordinateTransform uninitialized;
QgsCoordinateTransform uninitializedCopy( uninitialized );
QVERIFY( !uninitializedCopy.isInitialised() );
QVERIFY( !uninitializedCopy.isValid() );
QgsCoordinateReferenceSystem source;
source.createFromId( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
@ -60,20 +62,20 @@ void TestQgsCoordinateTransform::copy()
destination.createFromId( 4326, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateTransform original( source, destination );
QVERIFY( original.isInitialised() );
QVERIFY( original.isValid() );
QgsCoordinateTransform copy( original );
QVERIFY( copy.isInitialised() );
QVERIFY( copy.isValid() );
QCOMPARE( copy.sourceCrs().authid(), original.sourceCrs().authid() );
QCOMPARE( copy.destCRS().authid(), original.destCRS().authid() );
QCOMPARE( copy.destinationCrs().authid(), original.destinationCrs().authid() );
// force detachement of copy
QgsCoordinateReferenceSystem newDest;
newDest.createFromId( 3857, QgsCoordinateReferenceSystem::EpsgCrsId );
copy.setDestCRS( newDest );
QVERIFY( copy.isInitialised() );
QCOMPARE( copy.destCRS().authid(), QString( "EPSG:3857" ) );
QCOMPARE( original.destCRS().authid(), QString( "EPSG:4326" ) );
copy.setDestinationCrs( newDest );
QVERIFY( copy.isValid() );
QCOMPARE( copy.destinationCrs().authid(), QString( "EPSG:3857" ) );
QCOMPARE( original.destinationCrs().authid(), QString( "EPSG:4326" ) );
}
void TestQgsCoordinateTransform::assignment()
@ -81,7 +83,7 @@ void TestQgsCoordinateTransform::assignment()
QgsCoordinateTransform uninitialized;
QgsCoordinateTransform uninitializedCopy;
uninitializedCopy = uninitialized;
QVERIFY( !uninitializedCopy.isInitialised() );
QVERIFY( !uninitializedCopy.isValid() );
QgsCoordinateReferenceSystem source;
source.createFromId( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
@ -89,26 +91,90 @@ void TestQgsCoordinateTransform::assignment()
destination.createFromId( 4326, QgsCoordinateReferenceSystem::EpsgCrsId );
QgsCoordinateTransform original( source, destination );
QVERIFY( original.isInitialised() );
QVERIFY( original.isValid() );
QgsCoordinateTransform copy;
copy = original;
QVERIFY( copy.isInitialised() );
QVERIFY( copy.isValid() );
QCOMPARE( copy.sourceCrs().authid(), original.sourceCrs().authid() );
QCOMPARE( copy.destCRS().authid(), original.destCRS().authid() );
QCOMPARE( copy.destinationCrs().authid(), original.destinationCrs().authid() );
// force detachement of copy
QgsCoordinateReferenceSystem newDest;
newDest.createFromId( 3857, QgsCoordinateReferenceSystem::EpsgCrsId );
copy.setDestCRS( newDest );
QVERIFY( copy.isInitialised() );
QCOMPARE( copy.destCRS().authid(), QString( "EPSG:3857" ) );
QCOMPARE( original.destCRS().authid(), QString( "EPSG:4326" ) );
copy.setDestinationCrs( newDest );
QVERIFY( copy.isValid() );
QCOMPARE( copy.destinationCrs().authid(), QString( "EPSG:3857" ) );
QCOMPARE( original.destinationCrs().authid(), QString( "EPSG:4326" ) );
// test assigning back to invalid
copy = uninitialized;
QVERIFY( !copy.isInitialised() );
QVERIFY( original.isInitialised() );
QVERIFY( !copy.isValid() );
QVERIFY( original.isValid() );
}
void TestQgsCoordinateTransform::isValid()
{
QgsCoordinateTransform tr;
QVERIFY( !tr.isValid() );
QgsCoordinateReferenceSystem srs1;
srs1.createFromSrid( 3994 );
QgsCoordinateReferenceSystem srs2;
srs2.createFromSrid( 4326 );
// valid source, invalid destination
QgsCoordinateTransform tr2( srs1, QgsCoordinateReferenceSystem() );
QVERIFY( !tr2.isValid() );
// invalid source, valid destination
QgsCoordinateTransform tr3( QgsCoordinateReferenceSystem(), srs2 );
QVERIFY( !tr3.isValid() );
// valid source, valid destination
QgsCoordinateTransform tr4( srs1, srs2 );
QVERIFY( tr4.isValid() );
// try to invalidate by setting source as invalid
tr4.setSourceCrs( QgsCoordinateReferenceSystem() );
QVERIFY( !tr4.isValid() );
QgsCoordinateTransform tr5( srs1, srs2 );
// try to invalidate by setting destination as invalid
tr5.setDestinationCrs( QgsCoordinateReferenceSystem() );
QVERIFY( !tr5.isValid() );
}
void TestQgsCoordinateTransform::isShortCircuited()
{
QgsCoordinateTransform tr;
//invalid transform shortcircuits
QVERIFY( tr.isShortCircuited() );
QgsCoordinateReferenceSystem srs1;
srs1.createFromSrid( 3994 );
QgsCoordinateReferenceSystem srs2;
srs2.createFromSrid( 4326 );
// valid source, invalid destination
QgsCoordinateTransform tr2( srs1, QgsCoordinateReferenceSystem() );
QVERIFY( tr2.isShortCircuited() );
// invalid source, valid destination
QgsCoordinateTransform tr3( QgsCoordinateReferenceSystem(), srs2 );
QVERIFY( tr3.isShortCircuited() );
// equal, valid source and destination
QgsCoordinateTransform tr4( srs1, srs1 );
QVERIFY( tr4.isShortCircuited() );
// valid but different source and destination
QgsCoordinateTransform tr5( srs1, srs2 );
QVERIFY( !tr5.isShortCircuited() );
// try to short circuit by changing dest
tr5.setDestinationCrs( srs1 );
QVERIFY( tr5.isShortCircuited() );
}