mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Catch datum transform request signal in QgsMapCanvas
This commit is contained in:
parent
c82606cae2
commit
a2e0a1a4a9
@ -785,7 +785,7 @@ QList< QList< int > > QgsCoordinateTransform::datumTransformations( const QgsCoo
|
||||
}
|
||||
|
||||
QList<int> directTransforms;
|
||||
searchDatumTransform( QString( "SELECT coord_op_code FROM tbl_datum_transform WHERE source_crs_code = %1 AND dest_crs_code = %2" ).arg( srcAuthCode ).arg( destAuthCode ),
|
||||
searchDatumTransform( QString( "SELECT coord_op_code FROM tbl_datum_transform WHERE source_crs_code = %1 AND target_crs_code = %2" ).arg( srcAuthCode ).arg( destAuthCode ),
|
||||
directTransforms );
|
||||
QList<int> srcToWgs84;
|
||||
searchDatumTransform( QString( "SELECT coord_op_code FROM tbl_datum_transform WHERE ( source_crs_code = %1 AND target_crs_code = %2 ) OR ( source_crs_code = %2 AND target_crs_code = %1 )" ).arg( srcAuthCode ).arg( 4326 ),
|
||||
|
@ -792,17 +792,23 @@ bool QgsMapRenderer::splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent
|
||||
// extent separately.
|
||||
static const double splitCoord = 180.0;
|
||||
|
||||
const QgsCoordinateTransform* transform = tr( layer );
|
||||
if ( layer->crs().geographicFlag() )
|
||||
{
|
||||
// Note: ll = lower left point
|
||||
// and ur = upper right point
|
||||
QgsPoint ll = tr( layer )->transform( extent.xMinimum(), extent.yMinimum(),
|
||||
QgsCoordinateTransform::ReverseTransform );
|
||||
|
||||
QgsPoint ur = tr( layer )->transform( extent.xMaximum(), extent.yMaximum(),
|
||||
QgsCoordinateTransform::ReverseTransform );
|
||||
QgsPoint ll( extent.xMinimum(), extent.yMinimum() );
|
||||
QgsPoint ur( extent.xMaximum(), extent.yMaximum() );
|
||||
|
||||
extent = tr( layer )->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
|
||||
if ( transform )
|
||||
{
|
||||
ll = transform->transform( ll.x(), ll.y(),
|
||||
QgsCoordinateTransform::ReverseTransform );
|
||||
ur = transform->transform( ur.x(), ur.y(),
|
||||
QgsCoordinateTransform::ReverseTransform );
|
||||
extent = transform->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
|
||||
}
|
||||
|
||||
if ( ll.x() > ur.x() )
|
||||
{
|
||||
@ -814,7 +820,10 @@ bool QgsMapRenderer::splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent
|
||||
}
|
||||
else // can't cross 180
|
||||
{
|
||||
extent = tr( layer )->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
|
||||
if ( transform )
|
||||
{
|
||||
extent = transform->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( QgsCsException &cse )
|
||||
@ -830,14 +839,18 @@ bool QgsMapRenderer::splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent
|
||||
|
||||
QgsRectangle QgsMapRenderer::layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent )
|
||||
{
|
||||
QgsDebugMsg( QString( "sourceCrs = " + tr( theLayer )->sourceCrs().authid() ) );
|
||||
QgsDebugMsg( QString( "destCRS = " + tr( theLayer )->destCRS().authid() ) );
|
||||
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
|
||||
//QgsDebugMsg( QString( "sourceCrs = " + tr( theLayer )->sourceCrs().authid() ) );
|
||||
//QgsDebugMsg( QString( "destCRS = " + tr( theLayer )->destCRS().authid() ) );
|
||||
//QgsDebugMsg( QString( "extent = " + extent.toString() ) );
|
||||
if ( hasCrsTransformEnabled() )
|
||||
{
|
||||
try
|
||||
{
|
||||
extent = tr( theLayer )->transformBoundingBox( extent );
|
||||
const QgsCoordinateTransform* transform = tr( theLayer );
|
||||
if ( transform )
|
||||
{
|
||||
extent = transform->transformBoundingBox( extent );
|
||||
}
|
||||
}
|
||||
catch ( QgsCsException &cse )
|
||||
{
|
||||
@ -1250,6 +1263,11 @@ const QgsCoordinateTransform* QgsMapRenderer::tr( QgsMapLayer *layer )
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( layer->crs().authid() == mDestCRS->authid() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
QHash< QString, QgsLayerCoordinateTransform >::const_iterator ctIt = mLayerCoordinateTransformInfo.find( layer->id() );
|
||||
if ( ctIt != mLayerCoordinateTransformInfo.constEnd() )
|
||||
{
|
||||
|
@ -38,6 +38,7 @@ email : sherman at mrcc.com
|
||||
|
||||
#include "qgis.h"
|
||||
#include "qgsapplication.h"
|
||||
#include "qgscrscache.h"
|
||||
#include "qgslogger.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
#include "qgsmapcanvasmap.h"
|
||||
@ -110,6 +111,8 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
|
||||
setFocusPolicy( Qt::StrongFocus );
|
||||
|
||||
mMapRenderer = new QgsMapRenderer;
|
||||
connect( mMapRenderer, SIGNAL( datumTransformInfoRequested( QgsMapLayer*, const QString&, const QString& ) ),
|
||||
this, SLOT( getDatumTransformInfo( QgsMapLayer*, const QString& , const QString& ) ) );
|
||||
|
||||
// create map canvas item which will show the map
|
||||
mMap = new QgsMapCanvasMap( this );
|
||||
@ -1543,6 +1546,40 @@ void QgsMapCanvas::writeProject( QDomDocument & doc )
|
||||
mMapRenderer->writeXML( mapcanvasNode, doc );
|
||||
}
|
||||
|
||||
/**Ask user which datum transform to use*/
|
||||
void QgsMapCanvas::getDatumTransformInfo( QgsMapLayer* ml, const QString& srcAuthId, const QString& destAuthId )
|
||||
{
|
||||
if ( !ml )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//create two crs
|
||||
const QgsCoordinateReferenceSystem& srcCRS = QgsCRSCache::instance()->crsByAuthId( srcAuthId );
|
||||
const QgsCoordinateReferenceSystem& destCRS = QgsCRSCache::instance()->crsByAuthId( destAuthId );
|
||||
|
||||
//get list of datum transforms (QgsCoordinateTransform::datumTransformations
|
||||
QList< QList< int > > dt = QgsCoordinateTransform::datumTransformations( srcCRS, destCRS );
|
||||
if ( dt.size() < 2 )
|
||||
{
|
||||
return; //skip?
|
||||
}
|
||||
|
||||
//if several possibilities: present dialog
|
||||
//QgsDatumTransformDialog d( dt );
|
||||
//if( d.exec() == QDialog::Accepted )
|
||||
//{
|
||||
// int srcTransform = -1;
|
||||
// int destTransform = -1;
|
||||
// QList<int> t = d.selectedDatumTransform();
|
||||
// if( t.size() > 0 )
|
||||
// {
|
||||
// srcTransform = t.at( 0 );
|
||||
// }
|
||||
// QgsMapRenderer::addLayerCoordinateTransform( ml->id(), const QString& srcAuthId, const QString& destAuthId, int srcTransform = -1, int destTransform = -1 )
|
||||
//}
|
||||
}
|
||||
|
||||
void QgsMapCanvas::zoomByFactor( double scaleFactor )
|
||||
{
|
||||
if ( mDrawing )
|
||||
|
@ -303,6 +303,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
||||
//! called to write map canvas settings to project
|
||||
void writeProject( QDomDocument & );
|
||||
|
||||
//! ask user about datum transformation
|
||||
void getDatumTransformInfo( QgsMapLayer* ml, const QString& srcAuthId, const QString& destAuthId );
|
||||
|
||||
private slots:
|
||||
//! called when current maptool is destroyed
|
||||
void mapToolDestroyed();
|
||||
|
Loading…
x
Reference in New Issue
Block a user