Skip to content
Permalink
Browse files

Fix bounding box after rotating atlas geometry

  • Loading branch information
Zverik committed Jun 18, 2017
1 parent e03b563 commit 1aa2a4ef311440b320c880a8d2820c91ded6117f
Showing with 23 additions and 3 deletions.
  1. +23 −3 src/core/composer/qgsatlascomposition.cpp
@@ -14,6 +14,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include <algorithm>
#include <stdexcept>
#include <QtAlgorithms>

@@ -438,11 +439,30 @@ void QgsAtlasComposition::computeExtent( QgsComposerMap *map )
// QgsGeometry::boundingBox is expressed in the geometry"s native CRS
// We have to transform the geometry to the destination CRS and ask for the bounding box
// Note: we cannot directly take the transformation of the bounding box, since transformations are not linear
QgsGeometry g(currentGeometry( map->crs() ));
QgsGeometry g = currentGeometry( map->crs() );
// Rotating the geometry, so the bounding box is correct wrt map rotation
if ( map->mapRotation() != 0.0 )
g.rotate(map->mapRotation(), g.centroid().asPoint());
mTransformedFeatureBounds = g.boundingBox();
{
QgsPointXY prevCenter = g.boundingBox().center();
g.rotate( map->mapRotation(), g.boundingBox().center() );
// Rotation center will be still the bounding box center of an unrotated geometry.
// Which means, if the center of bbox moves after rotation, the viewport will
// also be offset, and part of the geometry will fall out of bounds.
// Here we compensate for that roughly: by extending the rotated bounds
// so that its center is the same as the original.
QgsRectangle bounds = g.boundingBox();
double dx = std::max( std::abs( prevCenter.x() - bounds.xMinimum() ),
std::abs( prevCenter.x() - bounds.xMaximum() ) );
double dy = std::max( std::abs( prevCenter.y() - bounds.yMinimum() ),
std::abs( prevCenter.y() - bounds.yMaximum() ) );
QgsPointXY center = g.boundingBox().center();
mTransformedFeatureBounds = QgsRectangle( center.x() - dx, center.y() - dy,
center.x() + dx, center.y() + dy );
}
else
{
mTransformedFeatureBounds = g.boundingBox();
}
}

void QgsAtlasComposition::prepareMap( QgsComposerMap *map )

0 comments on commit 1aa2a4e

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