Skip to content
Permalink
Browse files

Refine QgsMapRendererJob::reprojectToLayerExtent to remove

unused "split" boolean return and instead return whether
the reprojection was successful or whether we had to fallback
to a "whole globe" extent
  • Loading branch information
nyalldawson committed Sep 21, 2020
1 parent 9990b84 commit 3ec1154796f28275026a176e8fb5093f16e17735
Showing with 16 additions and 8 deletions.
  1. +10 −6 src/core/qgsmaprendererjob.cpp
  2. +6 −2 src/core/qgsmaprendererjob.h
@@ -149,8 +149,7 @@ bool QgsMapRendererJob::prepareLabelCache() const

bool QgsMapRendererJob::reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 )
{
bool split = false;

bool res = true;
// we can safely use ballpark transforms without bothering the user here -- at the likely scale of layer extents there
// won't be an appreciable difference, and we aren't actually transforming any rendered points here anyway (just the layer extent)
QgsCoordinateTransform approxTransform = ct;
@@ -197,6 +196,7 @@ bool QgsMapRendererJob::reprojectToLayerExtent( const QgsMapLayer *ml, const Qgs
else
{
extent = QgsRectangle( -180.0, -90.0, 180.0, 90.0 );
res = false;
}
}
else
@@ -225,6 +225,7 @@ bool QgsMapRendererJob::reprojectToLayerExtent( const QgsMapLayer *ml, const Qgs
// for rendering, labeling and caching as everything is rendered just in one go
extent.setXMinimum( -SPLIT_COORD );
extent.setXMaximum( SPLIT_COORD );
res = false;
}
}

@@ -242,20 +243,23 @@ bool QgsMapRendererJob::reprojectToLayerExtent( const QgsMapLayer *ml, const Qgs
// E.g. longitude -200 to +160 would be understood as +40 to +160 due to periodicity.
// We could try to clamp coords to (-180,180) for lon resp. (-90,90) for lat,
// but this seems like a safer choice.
{
extent = QgsRectangle( std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max() );
res = false;
}
else
extent = approxTransform.transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
}
}
catch ( QgsCsException &cse )
catch ( QgsCsException & )
{
Q_UNUSED( cse )
QgsDebugMsg( QStringLiteral( "Transform error caught" ) );
extent = QgsRectangle( std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max() );
r2 = QgsRectangle( std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max() );
r2 = QgsRectangle( std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max() );
res = false;
}

return split;
return res;
}

QImage *QgsMapRendererJob::allocateImage( QString layerId )
@@ -408,8 +408,12 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
* Convenience function to project an extent into the layer source
* CRS, but also split it into two extents if it crosses
* the +/- 180 degree line. Modifies the given extent to be in the
* source CRS coordinates, and if it was split, returns TRUE, and
* also sets the contents of the r2 parameter
* source CRS coordinates, and if it was split also sets the contents
* of the r2 parameter.
*
* If FALSE is returned then the extent could not be accurately
* transformed to the layer's CRS, and a "full globe" extent
* was used instead.
*/
static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );

0 comments on commit 3ec1154

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