mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Add a QgsCoordinateTransformContext member to QgsProject
This commit is contained in:
parent
1013c0bdd9
commit
76ebfdf2f6
@ -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.
|
||||
|
@ -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() );
|
||||
@ -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() )
|
||||
{
|
||||
@ -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 );
|
||||
|
||||
|
@ -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 @@ import qgis # NOQA
|
||||
|
||||
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 @@ class TestQgsCoordinateTransformContext(unittest.TestCase):
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user