Skip to content
Permalink
Browse files

Catch datum transform request signal in QgsMapCanvas

  • Loading branch information
mhugent committed Oct 18, 2013
1 parent c82606c commit a2e0a1a4a903fc7ef705b9aac3e14eb7acaacc15
Showing with 69 additions and 11 deletions.
  1. +1 −1 src/core/qgscoordinatetransform.cpp
  2. +28 −10 src/core/qgsmaprenderer.cpp
  3. +37 −0 src/gui/qgsmapcanvas.cpp
  4. +3 −0 src/gui/qgsmapcanvas.h
@@ -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();

0 comments on commit a2e0a1a

Please sign in to comment.
You can’t perform that action at this time.