Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
don't crash when transforming between the same CRSes and update map r…
…enderer sip bindings
  • Loading branch information
jef-n committed Nov 11, 2013
1 parent 7c98970 commit 86b6c5b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
26 changes: 23 additions & 3 deletions python/core/qgsmaprenderer.sip
Expand Up @@ -72,7 +72,13 @@ class QgsLabelingEngineInterface
virtual QgsLabelingEngineInterface* clone() = 0 /Factory/;
};


struct QgsLayerCoordinateTransform
{
QString srcAuthId;
QString destAuthId;
int srcDatumTransform; //-1 if unknown or not specified
int destDatumTransform;
};

/** \ingroup core
* A non GUI class for rendering a map layer set onto a QPainter.
Expand Down Expand Up @@ -132,6 +138,7 @@ class QgsMapRenderer : QObject

const QgsMapToPixel* coordinateTransform();

//! Scale denominator
double scale() const;
/**Sets scale for scale based visibility. Normally, the scale is calculated automatically. This
function is only used to force a preview scale (e.g. for print composer)*/
Expand Down Expand Up @@ -159,7 +166,7 @@ class QgsMapRenderer : QObject
QSize outputSize();
QSizeF outputSizeF();

/**
/**
* @brief transform bounding box from layer's CRS to output CRS
* @see layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) if you want to transform a rectangle
* @return a bounding box (aligned rectangle) containing the transformed extent
Expand Down Expand Up @@ -206,7 +213,7 @@ class QgsMapRenderer : QObject
bool hasCrsTransformEnabled() const;

//! sets destination coordinate reference system
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs, bool refreshCoordinateTransformInfo = true );

//! returns CRS of destination coordinate reference system
const QgsCoordinateReferenceSystem& destinationCrs() const;
Expand Down Expand Up @@ -245,6 +252,16 @@ class QgsMapRenderer : QObject
//! Added in QGIS v1.4
void setLabelingEngine( QgsLabelingEngineInterface* iface /Transfer/ );

//! Returns a QPainter::CompositionMode corresponding to a BlendMode
//! Added in 1.9
static QPainter::CompositionMode getCompositionMode( const QgsMapRenderer::BlendMode blendMode );
//! Returns a BlendMode corresponding to a QPainter::CompositionMode
//! Added in 1.9
static QgsMapRenderer::BlendMode getBlendModeEnum( const QPainter::CompositionMode blendMode );

void addLayerCoordinateTransform( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform = -1, int destDatumTransform = -1 );
void clearLayerCoordinateTransforms();

const QgsCoordinateTransform* transformation( const QgsMapLayer *layer ) const;

signals:
Expand All @@ -262,6 +279,9 @@ class QgsMapRenderer : QObject
//! emitted when layer's draw() returned false
void drawError( QgsMapLayer* );

//! Notifies higher level components to show the datum transform dialog and add a QgsLayerCoordinateTransformInfo for that layer
void datumTransformInfoRequested( const QgsMapLayer* ml, const QString& srcAuthId, const QString& destAuthId ) const;

public slots:

//! called by signal from layer current being drawn
Expand Down
41 changes: 30 additions & 11 deletions src/core/qgsmaprenderer.cpp
Expand Up @@ -261,7 +261,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )

mDrawing = true;

const QgsCoordinateTransform* ct;
const QgsCoordinateTransform *ct;

#ifdef QGISDEBUG
QgsDebugMsg( "Starting to render layer stack." );
Expand Down Expand Up @@ -794,7 +794,7 @@ bool QgsMapRenderer::splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent
// extent separately.
static const double splitCoord = 180.0;

const QgsCoordinateTransform* transform = transformation( layer );
const QgsCoordinateTransform *transform = transformation( layer );
if ( layer->crs().geographicFlag() )
{
// Note: ll = lower left point
Expand Down Expand Up @@ -848,7 +848,7 @@ QgsRectangle QgsMapRenderer::layerExtentToOutputExtent( QgsMapLayer* theLayer, Q
{
try
{
const QgsCoordinateTransform* transform = transformation( theLayer );
const QgsCoordinateTransform *transform = transformation( theLayer );
if ( transform )
{
extent = transform->transformBoundingBox( extent );
Expand All @@ -867,14 +867,21 @@ QgsRectangle QgsMapRenderer::layerExtentToOutputExtent( QgsMapLayer* theLayer, Q

QgsRectangle QgsMapRenderer::outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent )
{
QgsDebugMsg( QString( "layer sourceCrs = " + transformation( theLayer )->sourceCrs().authid() ) );
QgsDebugMsg( QString( "layer destCRS = " + transformation( theLayer )->destCRS().authid() ) );
#if QGISDEBUG
const QgsCoordinateTransform *transform = transformation( theLayer );
QgsDebugMsg( QString( "layer sourceCrs = " + ( transform ? transform->sourceCrs().authid() : "none" ) ) );
QgsDebugMsg( QString( "layer destCRS = " + ( transform ? transform->destCRS().authid() : "none" ) ) );
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
#endif
if ( hasCrsTransformEnabled() )
{
try
{
extent = transformation( theLayer )->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
const QgsCoordinateTransform *transform = transformation( theLayer );
if ( transform )
{
extent = transform->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
}
}
catch ( QgsCsException &cse )
{
Expand All @@ -893,7 +900,11 @@ QgsPoint QgsMapRenderer::layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint
{
try
{
point = transformation( theLayer )->transform( point, QgsCoordinateTransform::ForwardTransform );
const QgsCoordinateTransform *transform = transformation( theLayer );
if ( transform )
{
point = transform->transform( point, QgsCoordinateTransform::ForwardTransform );
}
}
catch ( QgsCsException &cse )
{
Expand All @@ -913,7 +924,11 @@ QgsRectangle QgsMapRenderer::layerToMapCoordinates( QgsMapLayer* theLayer, QgsRe
{
try
{
rect = transformation( theLayer )->transform( rect, QgsCoordinateTransform::ForwardTransform );
const QgsCoordinateTransform *transform = transformation( theLayer );
if ( transform )
{
rect = transform->transform( rect, QgsCoordinateTransform::ForwardTransform );
}
}
catch ( QgsCsException &cse )
{
Expand All @@ -933,7 +948,9 @@ QgsPoint QgsMapRenderer::mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint
{
try
{
point = transformation( theLayer )->transform( point, QgsCoordinateTransform::ReverseTransform );
const QgsCoordinateTransform *transform = transformation( theLayer );
if ( transform )
point = transform->transform( point, QgsCoordinateTransform::ReverseTransform );
}
catch ( QgsCsException &cse )
{
Expand All @@ -953,7 +970,9 @@ QgsRectangle QgsMapRenderer::mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRe
{
try
{
rect = transformation( theLayer )->transform( rect, QgsCoordinateTransform::ReverseTransform );
const QgsCoordinateTransform *transform = transformation( theLayer );
if ( transform )
rect = transform->transform( rect, QgsCoordinateTransform::ReverseTransform );
}
catch ( QgsCsException &cse )
{
Expand Down Expand Up @@ -1245,7 +1264,7 @@ void QgsMapRenderer::setLabelingEngine( QgsLabelingEngineInterface* iface )
mLabelingEngine = iface;
}

const QgsCoordinateTransform* QgsMapRenderer::transformation( const QgsMapLayer *layer ) const
const QgsCoordinateTransform *QgsMapRenderer::transformation( const QgsMapLayer *layer ) const
{
if ( !layer || !mDestCRS )
{
Expand Down

0 comments on commit 86b6c5b

Please sign in to comment.