Skip to content

Commit 8f5fe10

Browse files
committed
Fix #10081 (problems with reprojection of layers)
1 parent 0f5d743 commit 8f5fe10

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/core/qgsmaprendererjob.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,24 @@ bool QgsMapRendererJob::reprojectToLayerExtent( const QgsCoordinateTransform* ct
503503
extent.setXMinimum( -splitCoord );
504504
extent.setXMaximum( splitCoord );
505505
}
506+
507+
// TODO: the above rule still does not help if using a projection that covers the whole
508+
// world. E.g. with EPSG:3857 the longitude spectrum -180 to +180 is mapped to approx.
509+
// -2e7 to +2e7. Converting extent from -5e7 to +5e7 is transformed as -90 to +90,
510+
// but in fact the extent should cover the whole world.
506511
}
507512
else // can't cross 180
508513
{
509-
extent = ct->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
514+
if ( ct->destCRS().geographicFlag() &&
515+
( extent.xMinimum() <= -180 || extent.xMaximum() >= 180 ||
516+
extent.yMinimum() <= -90 || extent.yMaximum() >= 90 ) )
517+
// Use unlimited rectangle because otherwise we may end up transforming wrong coordinates.
518+
// E.g. longitude -200 to +160 would be understood as +40 to +160 due to periodicity.
519+
// We could try to clamp coords to (-180,180) for lon resp. (-90,90) for lat,
520+
// but this seems like a safer choice.
521+
extent = QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
522+
else
523+
extent = ct->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
510524
}
511525
}
512526
catch ( QgsCsException &cse )

0 commit comments

Comments
 (0)