-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reintroduce datum transforms (were disabled during transition to MTR)
- Loading branch information
Showing
15 changed files
with
344 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @brief The QgsDatumTransformStore class keeps track of datum transformations | ||
* as chosen by the user. | ||
* | ||
* @note added in 2.4 | ||
*/ | ||
class QgsDatumTransformStore | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsdatumtransformstore.h> | ||
%End | ||
|
||
public: | ||
explicit QgsDatumTransformStore( const QgsCoordinateReferenceSystem& destCrs ); | ||
|
||
void clear(); | ||
|
||
void setDestinationCrs( const QgsCoordinateReferenceSystem& destCrs ); | ||
|
||
void addEntry( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform ); | ||
|
||
bool hasEntryForLayer( QgsMapLayer* layer ) const; | ||
|
||
/** will return transform from layer's CRS to current destination CRS. | ||
* Will emit datumTransformInfoRequested signal if the layer has no entry. | ||
* Returns an instance from QgsCoordinateTransformCache | ||
*/ | ||
const QgsCoordinateTransform* transformation( QgsMapLayer* layer ) const; | ||
|
||
void readXML( const QDomNode& parentNode ); | ||
|
||
void writeXML( QDomNode& parentNode, QDomDocument& theDoc ) const; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/*************************************************************************** | ||
qgsdatumtransformstore.cpp | ||
--------------------- | ||
begin : June 2014 | ||
copyright : (C) 2014 by Martin Dobias | ||
email : wonder dot sk at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsdatumtransformstore.h" | ||
|
||
#include "qgscrscache.h" | ||
#include "qgslogger.h" | ||
#include "qgsmaplayer.h" | ||
|
||
QgsDatumTransformStore::QgsDatumTransformStore( const QgsCoordinateReferenceSystem& destCrs ) | ||
: mDestCRS( destCrs ) | ||
{ | ||
|
||
} | ||
|
||
void QgsDatumTransformStore::clear() | ||
{ | ||
mEntries.clear(); | ||
} | ||
|
||
void QgsDatumTransformStore::setDestinationCrs( const QgsCoordinateReferenceSystem& destCrs ) | ||
{ | ||
mDestCRS = destCrs; | ||
clear(); | ||
} | ||
|
||
void QgsDatumTransformStore::addEntry( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform ) | ||
{ | ||
Entry lt; | ||
lt.srcAuthId = srcAuthId; | ||
lt.destAuthId = destAuthId; | ||
lt.srcDatumTransform = srcDatumTransform; | ||
lt.destDatumTransform = destDatumTransform; | ||
mEntries.insert( layerId, lt ); | ||
} | ||
|
||
bool QgsDatumTransformStore::hasEntryForLayer( QgsMapLayer* layer ) const | ||
{ | ||
return mEntries.contains( layer->id() ); | ||
} | ||
|
||
const QgsCoordinateTransform* QgsDatumTransformStore::transformation( QgsMapLayer* layer ) const | ||
{ | ||
QString srcAuthId = layer->crs().authid(); | ||
QString dstAuthId = mDestCRS.authid(); | ||
|
||
if ( !layer || srcAuthId == dstAuthId ) | ||
{ | ||
return 0; | ||
} | ||
|
||
QHash< QString, Entry >::const_iterator ctIt = mEntries.find( layer->id() ); | ||
if ( ctIt != mEntries.constEnd() && ctIt->srcAuthId == srcAuthId && ctIt->destAuthId == dstAuthId ) | ||
{ | ||
return QgsCoordinateTransformCache::instance()->transform( ctIt->srcAuthId, ctIt->destAuthId, ctIt->srcDatumTransform, ctIt->destDatumTransform ); | ||
} | ||
else | ||
{ | ||
return QgsCoordinateTransformCache::instance()->transform( srcAuthId, dstAuthId, -1, -1 ); | ||
} | ||
} | ||
|
||
void QgsDatumTransformStore::readXML( const QDomNode& parentNode ) | ||
{ | ||
clear(); | ||
|
||
QDomElement layerCoordTransformInfoElem = parentNode.firstChildElement( "layer_coordinate_transform_info" ); | ||
if ( !layerCoordTransformInfoElem.isNull() ) | ||
{ | ||
QDomNodeList layerCoordinateTransformList = layerCoordTransformInfoElem.elementsByTagName( "layer_coordinate_transform" ); | ||
QDomElement layerCoordTransformElem; | ||
for ( int i = 0; i < layerCoordinateTransformList.size(); ++i ) | ||
{ | ||
layerCoordTransformElem = layerCoordinateTransformList.at( i ).toElement(); | ||
QString layerId = layerCoordTransformElem.attribute( "layerid" ); | ||
if ( layerId.isEmpty() ) | ||
{ | ||
continue; | ||
} | ||
|
||
Entry lct; | ||
lct.srcAuthId = layerCoordTransformElem.attribute( "srcAuthId" ); | ||
lct.destAuthId = layerCoordTransformElem.attribute( "destAuthId" ); | ||
lct.srcDatumTransform = layerCoordTransformElem.attribute( "srcDatumTransform", "-1" ).toInt(); | ||
lct.destDatumTransform = layerCoordTransformElem.attribute( "destDatumTransform", "-1" ).toInt(); | ||
mEntries.insert( layerId, lct ); | ||
} | ||
} | ||
} | ||
|
||
void QgsDatumTransformStore::writeXML( QDomNode& parentNode, QDomDocument& theDoc ) const | ||
{ | ||
// layer coordinate transform infos | ||
QDomElement layerCoordTransformInfo = theDoc.createElement( "layer_coordinate_transform_info" ); | ||
|
||
for ( QHash< QString, Entry >::const_iterator coordIt = mEntries.constBegin(); coordIt != mEntries.constEnd(); ++coordIt ) | ||
{ | ||
QDomElement layerCoordTransformElem = theDoc.createElement( "layer_coordinate_transform" ); | ||
layerCoordTransformElem.setAttribute( "layerid", coordIt.key() ); | ||
layerCoordTransformElem.setAttribute( "srcAuthId", coordIt->srcAuthId ); | ||
layerCoordTransformElem.setAttribute( "destAuthId", coordIt->destAuthId ); | ||
layerCoordTransformElem.setAttribute( "srcDatumTransform", QString::number( coordIt->srcDatumTransform ) ); | ||
layerCoordTransformElem.setAttribute( "destDatumTransform", QString::number( coordIt->destDatumTransform ) ); | ||
layerCoordTransformInfo.appendChild( layerCoordTransformElem ); | ||
} | ||
parentNode.appendChild( layerCoordTransformInfo ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*************************************************************************** | ||
qgsdatumtransformstore.h | ||
--------------------- | ||
begin : June 2014 | ||
copyright : (C) 2014 by Martin Dobias | ||
email : wonder dot sk at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSDATUMTRANSFORMSTORE_H | ||
#define QGSDATUMTRANSFORMSTORE_H | ||
|
||
#include "qgscoordinatereferencesystem.h" | ||
|
||
class QgsCoordinateTransform; | ||
class QgsMapLayer; | ||
|
||
class QDomElement; | ||
|
||
|
||
/** | ||
* @brief The QgsDatumTransformStore class keeps track of datum transformations | ||
* as chosen by the user. | ||
* | ||
* @note added in 2.4 | ||
*/ | ||
class CORE_EXPORT QgsDatumTransformStore | ||
{ | ||
public: | ||
explicit QgsDatumTransformStore( const QgsCoordinateReferenceSystem& destCrs ); | ||
|
||
void clear(); | ||
|
||
void setDestinationCrs( const QgsCoordinateReferenceSystem& destCrs ); | ||
|
||
void addEntry( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform ); | ||
|
||
bool hasEntryForLayer( QgsMapLayer* layer ) const; | ||
|
||
/** will return transform from layer's CRS to current destination CRS. | ||
* Will emit datumTransformInfoRequested signal if the layer has no entry. | ||
* Returns an instance from QgsCoordinateTransformCache | ||
*/ | ||
const QgsCoordinateTransform* transformation( QgsMapLayer* layer ) const; | ||
|
||
void readXML( const QDomNode& parentNode ); | ||
|
||
void writeXML( QDomNode& parentNode, QDomDocument& theDoc ) const; | ||
|
||
struct Entry | ||
{ | ||
QString srcAuthId; | ||
QString destAuthId; | ||
int srcDatumTransform; //-1 if unknown or not specified | ||
int destDatumTransform; | ||
}; | ||
|
||
protected: | ||
QgsCoordinateReferenceSystem mDestCRS; | ||
|
||
//! key = layer ID | ||
QHash< QString, Entry > mEntries; | ||
}; | ||
|
||
#endif // QGSDATUMTRANSFORMSTORE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.