Skip to content

Commit

Permalink
[composer] Ensure geographic longitude values are wrapped in decimal
Browse files Browse the repository at this point in the history
grid annotations
  • Loading branch information
nyalldawson committed Aug 10, 2015
1 parent cd7592d commit 2ef2414
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/core/composer/qgscomposermapgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit 2ef2414

Please sign in to comment.