Skip to content
Permalink
Browse files

Add a QgsCoordinateTransformContext member to QgsProject

  • Loading branch information
nyalldawson committed Nov 5, 2017
1 parent b06a9b9 commit cd41d7087248649eba85b70d632088c54a8b636b
@@ -127,6 +127,18 @@ Returns the QgsProject singleton instance
.. versionadded:: 3.0
%End



QgsCoordinateTransformContext &transformContext();
%Docstring
Returns a modifiable reference to the project's coordinate transform context, which stores various
information regarding which datum transforms should be used when transforming points
from a source to destination coordinate reference system.

.. versionadded:: 3.0
:rtype: QgsCoordinateTransformContext
%End

void clear();
%Docstring
Clear the project - removes all settings and resets it back to an empty, default state.
@@ -474,6 +474,16 @@ void QgsProject::setEllipsoid( const QString &ellipsoid )
emit ellipsoidChanged( ellipsoid );
}

QgsCoordinateTransformContext QgsProject::transformContext() const
{
return mTransformContext;
}

QgsCoordinateTransformContext &QgsProject::transformContext()
{
return mTransformContext;
}

void QgsProject::clear()
{
mFile.setFileName( QString() );
@@ -893,6 +903,8 @@ bool QgsProject::readProjectFile( const QString &filename )
mCrs = projectCrs;
emit crsChanged();

mTransformContext.readXml( doc->documentElement(), *doc, context );

QDomNodeList nl = doc->elementsByTagName( QStringLiteral( "autotransaction" ) );
if ( nl.count() )
{
@@ -1423,6 +1435,8 @@ bool QgsProject::writeProjectFile( const QString &filename )

mLabelingEngineSettings->writeSettingsToProject( this );

mTransformContext.writeXml( qgisNode, *doc, context );

QDomElement annotationsElem = mAnnotationManager->writeXml( *doc, context );
qgisNode.appendChild( annotationsElem );

@@ -37,6 +37,7 @@
#include "qgsprojectversion.h"
#include "qgsexpressioncontextgenerator.h"
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatetransformcontext.h"
#include "qgsprojectproperty.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerstore.h"
@@ -178,6 +179,25 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
void setEllipsoid( const QString &ellipsoid );


/**
* Returns a copy of the project's coordinate transform context, which stores various
* information regarding which datum transforms should be used when transforming points
* from a source to destination coordinate reference system.
*
* \since QGIS 3.0
*/
QgsCoordinateTransformContext transformContext() const SIP_SKIP;

/**
* Returns a modifiable reference to the project's coordinate transform context, which stores various
* information regarding which datum transforms should be used when transforming points
* from a source to destination coordinate reference system.
*
* \since QGIS 3.0
*/
QgsCoordinateTransformContext &transformContext();

/**
* Clear the project - removes all settings and resets it back to an empty, default state.
* \since QGIS 2.4
@@ -1164,6 +1184,8 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
QgsCoordinateReferenceSystem mCrs;
bool mDirty = false; // project has been modified since it has been read or saved
bool mTrustLayerMetadata = false;

QgsCoordinateTransformContext mTransformContext;
};

/**
@@ -16,7 +16,8 @@

from qgis.core import (QgsCoordinateReferenceSystem,
QgsCoordinateTransformContext,
QgsReadWriteContext)
QgsReadWriteContext,
QgsProject)
from qgis.testing import start_app, unittest
from qgis.PyQt.QtXml import QDomDocument

@@ -214,6 +215,14 @@ def testWriteReadXml(self):
self.assertEqual(context2.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
('EPSG:28356', 'EPSG:4283'): (3, 4)})

def testProject(self):
"""
Test project's transform context
"""
project = QgsProject()
project.transformContext().addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), 1)
self.assertEqual(project.transformContext().sourceDatumTransforms(), {'EPSG:3111': 1})


if __name__ == '__main__':
unittest.main()

0 comments on commit cd41d70

Please sign in to comment.
You can’t perform that action at this time.