Skip to content

Commit

Permalink
Add a QgsCoordinateTransformContext member to QgsProject
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 15, 2017
1 parent 1013c0b commit 76ebfdf
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
12 changes: 12 additions & 0 deletions python/core/qgsproject.sip
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsproject.cpp
Expand Up @@ -471,6 +471,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() );
Expand Down Expand Up @@ -910,6 +920,8 @@ bool QgsProject::readProjectFile( const QString &filename )
}
mCrs = projectCrs;

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

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

mLabelingEngineSettings->writeSettingsToProject( this );

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

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

Expand Down
22 changes: 22 additions & 0 deletions src/core/qgsproject.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
};

/**
Expand Down
11 changes: 10 additions & 1 deletion tests/src/python/test_qgscoordinatetransformcontext.py
Expand Up @@ -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

Expand Down Expand Up @@ -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 76ebfdf

Please sign in to comment.