mirror of
https://github.com/qgis/QGIS.git
synced 2025-06-19 00:02:48 -04:00
Reintroduce datum transforms (were disabled during transition to MTR)
This commit is contained in:
parent
9019805b44
commit
a04ebf9eb0
@ -25,6 +25,7 @@
|
||||
%Include qgsdataitem.sip
|
||||
%Include qgsdataprovider.sip
|
||||
%Include qgsdatasourceuri.sip
|
||||
%Include qgsdatumtransformstore.sip
|
||||
%Include qgsdbfilterproxymodel.sip
|
||||
%Include qgsdistancearea.sip
|
||||
%Include qgseditorwidgetconfig.sip
|
||||
|
34
python/core/qgsdatumtransformstore.sip
Normal file
34
python/core/qgsdatumtransformstore.sip
Normal file
@ -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;
|
||||
|
||||
};
|
@ -80,6 +80,9 @@ class QgsMapSettings
|
||||
|
||||
// -- utility functions --
|
||||
|
||||
//const QgsDatumTransformStore& datumTransformStore() const;
|
||||
QgsDatumTransformStore& datumTransformStore();
|
||||
|
||||
const QgsMapToPixel& mapToPixel() const;
|
||||
|
||||
/**
|
||||
@ -122,6 +125,12 @@ class QgsMapSettings
|
||||
*/
|
||||
QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
|
||||
|
||||
/**
|
||||
* @brief Return coordinate transform from layer's CRS to destination CRS
|
||||
* @param layer
|
||||
* @return transform - may be null if the transform is not needed
|
||||
*/
|
||||
const QgsCoordinateTransform* layerTransfrom( QgsMapLayer *layer ) const;
|
||||
|
||||
//! returns current extent of layer set
|
||||
QgsRectangle fullExtent() const;
|
||||
|
@ -74,6 +74,7 @@ SET(QGIS_CORE_SRCS
|
||||
qgsdatadefined.cpp
|
||||
qgsdatasourceuri.cpp
|
||||
qgsdataitem.cpp
|
||||
qgsdatumtransformstore.cpp
|
||||
qgsdbfilterproxymodel.cpp
|
||||
qgsdiagramrendererv2.cpp
|
||||
qgsdistancearea.cpp
|
||||
@ -431,6 +432,7 @@ SET(QGIS_CORE_HDRS
|
||||
qgsdatadefined.h
|
||||
qgsdatasourceuri.h
|
||||
qgsdataitem.h
|
||||
qgsdatumtransformstore.h
|
||||
qgsdistancearea.h
|
||||
qgscsexception.h
|
||||
qgseditorwidgetconfig.h
|
||||
|
119
src/core/qgsdatumtransformstore.cpp
Normal file
119
src/core/qgsdatumtransformstore.cpp
Normal file
@ -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 );
|
||||
}
|
70
src/core/qgsdatumtransformstore.h
Normal file
70
src/core/qgsdatumtransformstore.h
Normal file
@ -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
|
@ -408,7 +408,7 @@ void QgsMapRendererJob::drawOldLabeling( const QgsMapSettings& settings, QgsRend
|
||||
|
||||
if ( settings.hasCrsTransformEnabled() )
|
||||
{
|
||||
ct = QgsCoordinateTransformCache::instance()->transform( ml->crs().authid(), settings.destinationCrs().authid() );
|
||||
ct = settings.layerTransfrom( ml );
|
||||
reprojectToLayerExtent( ct, ml->crs().geographicFlag(), r1, r2 );
|
||||
}
|
||||
|
||||
@ -571,7 +571,7 @@ LayerRenderJobs QgsMapRendererJob::prepareJobs( QPainter* painter, QgsPalLabelin
|
||||
|
||||
if ( mSettings.hasCrsTransformEnabled() )
|
||||
{
|
||||
ct = QgsCoordinateTransformCache::instance()->transform( ml->crs().authid(), mSettings.destinationCrs().authid() );
|
||||
ct = mSettings.layerTransfrom( ml );
|
||||
reprojectToLayerExtent( ct, ml->crs().geographicFlag(), r1, r2 );
|
||||
QgsDebugMsg( "extent: " + r1.toString() );
|
||||
if ( !r1.isFinite() || !r2.isFinite() )
|
||||
|
@ -22,6 +22,7 @@ QgsMapSettings::QgsMapSettings()
|
||||
, mExtent()
|
||||
, mProjectionsEnabled( false )
|
||||
, mDestCRS( GEOCRS_ID, QgsCoordinateReferenceSystem::InternalCrsId ) // WGS 84
|
||||
, mDatumTransformStore( mDestCRS )
|
||||
, mBackgroundColor( Qt::white )
|
||||
, mSelectionColor( Qt::yellow )
|
||||
, mShowSelection( true )
|
||||
@ -189,6 +190,7 @@ bool QgsMapSettings::hasCrsTransformEnabled() const
|
||||
void QgsMapSettings::setDestinationCrs( const QgsCoordinateReferenceSystem& crs )
|
||||
{
|
||||
mDestCRS = crs;
|
||||
mDatumTransformStore.setDestinationCrs( crs );
|
||||
}
|
||||
|
||||
const QgsCoordinateReferenceSystem& QgsMapSettings::destinationCrs() const
|
||||
@ -258,27 +260,26 @@ double QgsMapSettings::scale() const
|
||||
|
||||
|
||||
|
||||
const QgsCoordinateTransform* QgsMapSettings::coordTransform( QgsMapLayer *layer ) const
|
||||
const QgsCoordinateTransform* QgsMapSettings::layerTransfrom( QgsMapLayer *layer ) const
|
||||
{
|
||||
if ( !layer )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return QgsCoordinateTransformCache::instance()->transform( layer->crs().authid(), mDestCRS.authid() );
|
||||
return mDatumTransformStore.transformation( layer );
|
||||
}
|
||||
|
||||
|
||||
|
||||
QgsRectangle QgsMapSettings::layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const
|
||||
{
|
||||
QgsDebugMsg( QString( "sourceCrs = " + coordTransform( theLayer )->sourceCrs().authid() ) );
|
||||
QgsDebugMsg( QString( "destCRS = " + coordTransform( theLayer )->destCRS().authid() ) );
|
||||
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
|
||||
if ( hasCrsTransformEnabled() )
|
||||
{
|
||||
try
|
||||
{
|
||||
extent = coordTransform( theLayer )->transformBoundingBox( extent );
|
||||
if ( const QgsCoordinateTransform* ct = layerTransfrom( theLayer ) )
|
||||
{
|
||||
QgsDebugMsg( QString( "sourceCrs = " + ct->sourceCrs().authid() ) );
|
||||
QgsDebugMsg( QString( "destCRS = " + ct->destCRS().authid() ) );
|
||||
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
|
||||
extent = ct->transformBoundingBox( extent );
|
||||
}
|
||||
}
|
||||
catch ( QgsCsException &cse )
|
||||
{
|
||||
@ -294,14 +295,17 @@ QgsRectangle QgsMapSettings::layerExtentToOutputExtent( QgsMapLayer* theLayer, Q
|
||||
|
||||
QgsRectangle QgsMapSettings::outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const
|
||||
{
|
||||
QgsDebugMsg( QString( "layer sourceCrs = " + coordTransform( theLayer )->sourceCrs().authid() ) );
|
||||
QgsDebugMsg( QString( "layer destCRS = " + coordTransform( theLayer )->destCRS().authid() ) );
|
||||
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
|
||||
if ( hasCrsTransformEnabled() )
|
||||
{
|
||||
try
|
||||
{
|
||||
extent = coordTransform( theLayer )->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
|
||||
if ( const QgsCoordinateTransform* ct = layerTransfrom( theLayer ) )
|
||||
{
|
||||
QgsDebugMsg( QString( "sourceCrs = " + ct->sourceCrs().authid() ) );
|
||||
QgsDebugMsg( QString( "destCRS = " + ct->destCRS().authid() ) );
|
||||
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
|
||||
extent = ct->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
|
||||
}
|
||||
}
|
||||
catch ( QgsCsException &cse )
|
||||
{
|
||||
@ -321,7 +325,8 @@ QgsPoint QgsMapSettings::layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint
|
||||
{
|
||||
try
|
||||
{
|
||||
point = coordTransform( theLayer )->transform( point, QgsCoordinateTransform::ForwardTransform );
|
||||
if ( const QgsCoordinateTransform* ct = layerTransfrom( theLayer ) )
|
||||
point = ct->transform( point, QgsCoordinateTransform::ForwardTransform );
|
||||
}
|
||||
catch ( QgsCsException &cse )
|
||||
{
|
||||
@ -342,7 +347,8 @@ QgsRectangle QgsMapSettings::layerToMapCoordinates( QgsMapLayer* theLayer, QgsRe
|
||||
{
|
||||
try
|
||||
{
|
||||
rect = coordTransform( theLayer )->transform( rect, QgsCoordinateTransform::ForwardTransform );
|
||||
if ( const QgsCoordinateTransform* ct = layerTransfrom( theLayer ) )
|
||||
rect = ct->transform( rect, QgsCoordinateTransform::ForwardTransform );
|
||||
}
|
||||
catch ( QgsCsException &cse )
|
||||
{
|
||||
@ -363,7 +369,8 @@ QgsPoint QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint
|
||||
{
|
||||
try
|
||||
{
|
||||
point = coordTransform( theLayer )->transform( point, QgsCoordinateTransform::ReverseTransform );
|
||||
if ( const QgsCoordinateTransform* ct = layerTransfrom( theLayer ) )
|
||||
point = ct->transform( point, QgsCoordinateTransform::ReverseTransform );
|
||||
}
|
||||
catch ( QgsCsException &cse )
|
||||
{
|
||||
@ -384,7 +391,8 @@ QgsRectangle QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRe
|
||||
{
|
||||
try
|
||||
{
|
||||
rect = coordTransform( theLayer )->transform( rect, QgsCoordinateTransform::ReverseTransform );
|
||||
if ( const QgsCoordinateTransform* ct = layerTransfrom( theLayer ) )
|
||||
rect = ct->transform( rect, QgsCoordinateTransform::ReverseTransform );
|
||||
}
|
||||
catch ( QgsCsException &cse )
|
||||
{
|
||||
@ -489,6 +497,8 @@ void QgsMapSettings::readXML( QDomNode& theNode )
|
||||
QDomNode extentNode = theNode.namedItem( "extent" );
|
||||
QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
|
||||
setExtent( aoi );
|
||||
|
||||
mDatumTransformStore.readXML( theNode );
|
||||
}
|
||||
|
||||
|
||||
@ -510,4 +520,6 @@ void QgsMapSettings::writeXML( QDomNode& theNode, QDomDocument& theDoc )
|
||||
QDomElement srsNode = theDoc.createElement( "destinationsrs" );
|
||||
theNode.appendChild( srsNode );
|
||||
destinationCrs().writeXML( srsNode, theDoc );
|
||||
|
||||
mDatumTransformStore.writeXML( theNode, theDoc );
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <QStringList>
|
||||
|
||||
#include "qgscoordinatereferencesystem.h"
|
||||
#include "qgsdatumtransformstore.h"
|
||||
#include "qgsmaptopixel.h"
|
||||
#include "qgsrectangle.h"
|
||||
#include "qgsscalecalculator.h"
|
||||
@ -95,6 +96,9 @@ class CORE_EXPORT QgsMapSettings
|
||||
|
||||
// -- utility functions --
|
||||
|
||||
const QgsDatumTransformStore& datumTransformStore() const { return mDatumTransformStore; }
|
||||
QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
|
||||
|
||||
const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
|
||||
|
||||
/**
|
||||
@ -137,6 +141,12 @@ class CORE_EXPORT QgsMapSettings
|
||||
*/
|
||||
QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
|
||||
|
||||
/**
|
||||
* @brief Return coordinate transform from layer's CRS to destination CRS
|
||||
* @param layer
|
||||
* @return transform - may be null if the transform is not needed
|
||||
*/
|
||||
const QgsCoordinateTransform* layerTransfrom( QgsMapLayer *layer ) const;
|
||||
|
||||
//! returns current extent of layer set
|
||||
QgsRectangle fullExtent() const;
|
||||
@ -159,6 +169,7 @@ class CORE_EXPORT QgsMapSettings
|
||||
|
||||
bool mProjectionsEnabled;
|
||||
QgsCoordinateReferenceSystem mDestCRS;
|
||||
QgsDatumTransformStore mDatumTransformStore;
|
||||
|
||||
QColor mBackgroundColor;
|
||||
QColor mSelectionColor;
|
||||
@ -178,10 +189,7 @@ class CORE_EXPORT QgsMapSettings
|
||||
QgsScaleCalculator mScaleCalculator;
|
||||
QgsMapToPixel mMapToPixel;
|
||||
|
||||
|
||||
void updateDerived();
|
||||
|
||||
const QgsCoordinateTransform* coordTransform( QgsMapLayer *layer ) const;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )
|
||||
|
@ -112,16 +112,12 @@ void QgsLayerTreeMapCanvasBridge::setCanvasLayers()
|
||||
else
|
||||
setCanvasLayers( mRoot, layers );
|
||||
|
||||
mCanvas->setLayerSet( layers );
|
||||
|
||||
QList<QgsLayerTreeLayer*> layerNodes = mRoot->findLayers();
|
||||
|
||||
int currentLayerCount = layerNodes.count();
|
||||
if ( mAutoSetupOnFirstLayer && mLastLayerCount == 0 && currentLayerCount != 0 )
|
||||
{
|
||||
// if we are moving from zero to non-zero layers, let's zoom to those data
|
||||
mCanvas->zoomToFullExtent();
|
||||
bool firstLayers = mAutoSetupOnFirstLayer && mLastLayerCount == 0 && currentLayerCount != 0;
|
||||
|
||||
if ( firstLayers )
|
||||
{
|
||||
// also setup destination CRS and map units if the OTF projections are not yet enabled
|
||||
if ( !mCanvas->mapSettings().hasCrsTransformEnabled() )
|
||||
{
|
||||
@ -131,11 +127,20 @@ void QgsLayerTreeMapCanvasBridge::setCanvasLayers()
|
||||
{
|
||||
mCanvas->setDestinationCrs( layerNode->layer()->crs() );
|
||||
mCanvas->setMapUnits( layerNode->layer()->crs().mapUnits() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mCanvas->setLayerSet( layers );
|
||||
|
||||
if ( firstLayers )
|
||||
{
|
||||
// if we are moving from zero to non-zero layers, let's zoom to those data
|
||||
mCanvas->zoomToFullExtent();
|
||||
}
|
||||
|
||||
if ( !mFirstCRS.isValid() )
|
||||
{
|
||||
// find out what is the first used CRS in case we may need to turn on OTF projections later
|
||||
|
@ -25,12 +25,13 @@
|
||||
QgsDatumTransformDialog::QgsDatumTransformDialog( const QString& layerName, const QList< QList< int > > &dt, QWidget *parent, Qt::WindowFlags f )
|
||||
: QDialog( parent, f )
|
||||
, mDt( dt )
|
||||
, mLayerName( layerName )
|
||||
{
|
||||
setupUi( this );
|
||||
|
||||
QApplication::setOverrideCursor( Qt::ArrowCursor );
|
||||
|
||||
setWindowTitle( tr( "Select datum transformations for layer" ) + " " + layerName );
|
||||
updateTitle();
|
||||
|
||||
QSettings settings;
|
||||
restoreGeometry( settings.value( "/Windows/DatumTransformDialog/geometry" ).toByteArray() );
|
||||
@ -134,6 +135,13 @@ QgsDatumTransformDialog::~QgsDatumTransformDialog()
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void QgsDatumTransformDialog::setDatumTransformInfo( const QString& srcCRSauthId, const QString& destCRSauthId )
|
||||
{
|
||||
mSrcCRSauthId = srcCRSauthId;
|
||||
mDestCRSauthId = destCRSauthId;
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
QList< int > QgsDatumTransformDialog::selectedDatumTransform()
|
||||
{
|
||||
QList<int> list;
|
||||
@ -216,3 +224,11 @@ void QgsDatumTransformDialog::on_mHideDeprecatedCheckBox_stateChanged( int )
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
void QgsDatumTransformDialog::updateTitle()
|
||||
{
|
||||
QString title = tr( "Select datum transformations for layer" ) + " " + mLayerName;
|
||||
if ( !mSrcCRSauthId.isEmpty() && !mDestCRSauthId.isEmpty() )
|
||||
title += QString( " (%1 -> %2)" ).arg( mSrcCRSauthId ).arg( mDestCRSauthId );
|
||||
setWindowTitle( title );
|
||||
}
|
||||
|
@ -27,6 +27,9 @@ class GUI_EXPORT QgsDatumTransformDialog: public QDialog, private Ui::QgsDatumTr
|
||||
QgsDatumTransformDialog( const QString& layerName, const QList< QList< int > >& dt, QWidget * parent = 0, Qt::WindowFlags f = 0 );
|
||||
~QgsDatumTransformDialog();
|
||||
|
||||
//! @note added in 2.4
|
||||
void setDatumTransformInfo( const QString& srcCRSauthId, const QString& destCRSauthId );
|
||||
|
||||
QList< int > selectedDatumTransform();
|
||||
|
||||
bool rememberSelection() const;
|
||||
@ -36,12 +39,15 @@ class GUI_EXPORT QgsDatumTransformDialog: public QDialog, private Ui::QgsDatumTr
|
||||
|
||||
private:
|
||||
QgsDatumTransformDialog();
|
||||
void updateTitle();
|
||||
bool gridShiftTransformation( const QString& itemText ) const;
|
||||
/**Returns false if the location of the grid shift files is known (PROJ_LIB) and the shift file is not there*/
|
||||
bool testGridShiftFileAvailability( QTreeWidgetItem* item, int col ) const;
|
||||
void load();
|
||||
|
||||
const QList< QList< int > > &mDt;
|
||||
QString mLayerName;
|
||||
QString mSrcCRSauthId, mDestCRSauthId;
|
||||
};
|
||||
|
||||
#endif // QGSDATUMTRANSFORMDIALOG_H
|
||||
|
@ -88,8 +88,7 @@ void QgsHighlight::init()
|
||||
{
|
||||
if ( mMapCanvas->mapSettings().hasCrsTransformEnabled() )
|
||||
{
|
||||
// TODO[MD]: after merge - should not use mapRenderer()
|
||||
const QgsCoordinateTransform* ct = mMapCanvas->mapRenderer()->transformation( mLayer );
|
||||
const QgsCoordinateTransform* ct = mMapCanvas->mapSettings().layerTransfrom( mLayer );
|
||||
if ( ct )
|
||||
{
|
||||
if ( mGeometry )
|
||||
|
31
src/gui/qgsmapcanvas.cpp
Executable file → Normal file
31
src/gui/qgsmapcanvas.cpp
Executable file → Normal file
@ -201,8 +201,6 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
|
||||
setFocusPolicy( Qt::StrongFocus );
|
||||
|
||||
mMapRenderer = new QgsMapRenderer;
|
||||
connect( mMapRenderer, SIGNAL( datumTransformInfoRequested( const QgsMapLayer*, const QString&, const QString& ) ),
|
||||
this, SLOT( getDatumTransformInfo( const QgsMapLayer*, const QString& , const QString& ) ) );
|
||||
|
||||
mResizeTimer = new QTimer( this );
|
||||
mResizeTimer->setSingleShot( true );
|
||||
@ -423,6 +421,8 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer> &layers )
|
||||
}
|
||||
}
|
||||
|
||||
updateDatumTransformEntries();
|
||||
|
||||
QgsDebugMsg( "Layers have changed, refreshing" );
|
||||
emit layersChanged();
|
||||
|
||||
@ -510,6 +510,8 @@ void QgsMapCanvas::setDestinationCrs( const QgsCoordinateReferenceSystem &crs )
|
||||
|
||||
mSettings.setDestinationCrs( crs );
|
||||
|
||||
updateDatumTransformEntries();
|
||||
|
||||
emit destinationCrsChanged();
|
||||
}
|
||||
|
||||
@ -1551,6 +1553,22 @@ void QgsMapCanvas::connectNotify( const char * signal )
|
||||
} //connectNotify
|
||||
|
||||
|
||||
void QgsMapCanvas::updateDatumTransformEntries()
|
||||
{
|
||||
QString destAuthId = mSettings.destinationCrs().authid();
|
||||
foreach ( QString layerID, mSettings.layers() )
|
||||
{
|
||||
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerID );
|
||||
if ( !layer )
|
||||
continue;
|
||||
|
||||
// if there are more options, ask the user which datum transform to use
|
||||
if ( !mSettings.datumTransformStore().hasEntryForLayer( layer ) )
|
||||
getDatumTransformInfo( layer, layer->crs().authid(), destAuthId );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
QgsMapTool* QgsMapCanvas::mapTool()
|
||||
{
|
||||
@ -1683,7 +1701,7 @@ void QgsMapCanvas::readProject( const QDomDocument & doc )
|
||||
setCrsTransformEnabled( tmpSettings.hasCrsTransformEnabled() );
|
||||
setDestinationCrs( tmpSettings.destinationCrs() );
|
||||
setExtent( tmpSettings.extent() );
|
||||
// TODO: read only units, extent, projections, dest CRS
|
||||
mSettings.datumTransformStore() = tmpSettings.datumTransformStore();
|
||||
|
||||
clearExtentHistory(); // clear the extent history on project load
|
||||
}
|
||||
@ -1727,6 +1745,7 @@ void QgsMapCanvas::getDatumTransformInfo( const QgsMapLayer* ml, const QString&
|
||||
QVariant defaultDestTransform = s.value( settingsString + "_destTransform" );
|
||||
if ( defaultSrcTransform.isValid() && defaultDestTransform.isValid() )
|
||||
{
|
||||
mSettings.datumTransformStore().addEntry( ml->id(), srcAuthId, destAuthId, defaultSrcTransform.toInt(), defaultDestTransform.toInt() );
|
||||
mMapRenderer->addLayerCoordinateTransform( ml->id(), srcAuthId, destAuthId, defaultSrcTransform.toInt(), defaultDestTransform.toInt() );
|
||||
return;
|
||||
}
|
||||
@ -1737,6 +1756,7 @@ void QgsMapCanvas::getDatumTransformInfo( const QgsMapLayer* ml, const QString&
|
||||
if ( !s.value( "/Projections/showDatumTransformDialog", false ).toBool() )
|
||||
{
|
||||
// just use the default transform
|
||||
mSettings.datumTransformStore().addEntry( ml->id(), srcAuthId, destAuthId, -1, -1 );
|
||||
mMapRenderer->addLayerCoordinateTransform( ml->id(), srcAuthId, destAuthId, -1, -1 );
|
||||
return;
|
||||
}
|
||||
@ -1750,7 +1770,8 @@ void QgsMapCanvas::getDatumTransformInfo( const QgsMapLayer* ml, const QString&
|
||||
|
||||
//if several possibilities: present dialog
|
||||
QgsDatumTransformDialog d( ml->name(), dt );
|
||||
if ( mMapRenderer && ( d.exec() == QDialog::Accepted ) )
|
||||
d.setDatumTransformInfo( srcCRS.authid(), destCRS.authid() );
|
||||
if ( d.exec() == QDialog::Accepted )
|
||||
{
|
||||
int srcTransform = -1;
|
||||
int destTransform = -1;
|
||||
@ -1763,6 +1784,7 @@ void QgsMapCanvas::getDatumTransformInfo( const QgsMapLayer* ml, const QString&
|
||||
{
|
||||
destTransform = t.at( 1 );
|
||||
}
|
||||
mSettings.datumTransformStore().addEntry( ml->id(), srcAuthId, destAuthId, srcTransform, destTransform );
|
||||
mMapRenderer->addLayerCoordinateTransform( ml->id(), srcAuthId, destAuthId, srcTransform, destTransform );
|
||||
if ( d.rememberSelection() )
|
||||
{
|
||||
@ -1772,6 +1794,7 @@ void QgsMapCanvas::getDatumTransformInfo( const QgsMapLayer* ml, const QString&
|
||||
}
|
||||
else
|
||||
{
|
||||
mSettings.datumTransformStore().addEntry( ml->id(), srcAuthId, destAuthId, -1, -1 );
|
||||
mMapRenderer->addLayerCoordinateTransform( ml->id(), srcAuthId, destAuthId, -1, -1 );
|
||||
}
|
||||
}
|
||||
|
@ -547,6 +547,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
||||
*/
|
||||
void connectNotify( const char * signal );
|
||||
|
||||
//! Make sure the datum transform store is properly populated
|
||||
void updateDatumTransformEntries();
|
||||
|
||||
private:
|
||||
/// this class is non-copyable
|
||||
/**
|
||||
@ -621,7 +624,6 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
||||
//! Optionally use cache with rendered map layers for the current map settings
|
||||
QgsMapRendererCache* mCache;
|
||||
|
||||
|
||||
QTimer *mResizeTimer;
|
||||
|
||||
QgsPreviewEffect* mPreviewEffect;
|
||||
|
Loading…
x
Reference in New Issue
Block a user