Skip to content
Permalink
Browse files

[composer] Ensure geographic longitude values are wrapped in decimal

grid annotations
  • Loading branch information
nyalldawson committed Aug 10, 2015
1 parent cd7592d commit 2ef2414c9a131200615292dc91545dfa3028b162
Showing with 25 additions and 10 deletions.
  1. +25 −10 src/core/composer/qgscomposermapgrid.cpp
@@ -1368,24 +1368,39 @@ void QgsComposerMapGrid::drawAnnotation( QPainter* p, const QPointF& pos, int ro

QString QgsComposerMapGrid::gridAnnotationString( double value, QgsComposerMapGrid::AnnotationCoordinate coord ) const
{
if ( mGridAnnotationFormat == QgsComposerMapGrid::Decimal )
//check if we are using degrees (ie, geographic crs)
bool geographic = false;
if ( mCRS.isValid() && mCRS.geographicFlag() )
{
return QString::number( value, 'f', mGridAnnotationPrecision );
geographic = true;
}
else if ( mGridAnnotationFormat == QgsComposerMapGrid::DecimalWithSuffix )
else if ( mComposerMap && mComposerMap->composition() )
{
QString hemisphere;
geographic = mComposerMap->composition()->mapSettings().destinationCrs().geographicFlag();
}

//check if we are using degrees (ie, geographic crs)
bool geographic = false;
if ( mCRS.isValid() && mCRS.geographicFlag() )
if ( geographic && coord == QgsComposerMapGrid::Longitude &&
( mGridAnnotationFormat == QgsComposerMapGrid::Decimal || mGridAnnotationFormat == QgsComposerMapGrid::DecimalWithSuffix ) )
{
// wrap around longitudes > 180 or < -180 degrees, so that eg "190E" -> "170W"
double wrappedX = fmod( value, 360.0 );
if ( wrappedX > 180.0 )
{
geographic = true;
value = wrappedX - 360.0;
}
else if ( mComposerMap && mComposerMap->composition() )
else if ( wrappedX < -180.0 )
{
geographic = mComposerMap->composition()->mapSettings().destinationCrs().geographicFlag();
value = wrappedX + 360.0;
}
}

if ( mGridAnnotationFormat == QgsComposerMapGrid::Decimal )
{
return QString::number( value, 'f', mGridAnnotationPrecision );
}
else if ( mGridAnnotationFormat == QgsComposerMapGrid::DecimalWithSuffix )
{
QString hemisphere;

double coordRounded = qRound( value * pow( 10.0, mGridAnnotationPrecision ) ) / pow( 10.0, mGridAnnotationPrecision );
if ( coord == QgsComposerMapGrid::Longitude )

0 comments on commit 2ef2414

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