Skip to content
Permalink
Browse files

Fix generation of world file when exporting canvas

Fixes #18491
  • Loading branch information
nyalldawson committed Mar 22, 2018
1 parent 8a5924d commit a2ba566e2b98c5bb520b46c0635652fbf2140979
Showing with 10 additions and 6 deletions.
  1. +7 −6 src/core/qgsmapsettingsutils.cpp
  2. +3 −0 tests/src/core/testqgsmapsettingsutils.cpp
@@ -87,7 +87,7 @@ QString QgsMapSettingsUtils::worldFileContent( const QgsMapSettings &mapSettings
s[1] = 0;
s[2] = xOrigin;
s[3] = 0;
s[4] = ms.mapUnitsPerPixel();
s[4] = -ms.mapUnitsPerPixel();
s[5] = yOrigin;

// rotation matrix
@@ -104,7 +104,9 @@ QString QgsMapSettingsUtils::worldFileContent( const QgsMapSettings &mapSettings
double b = r[0] * s[1] + r[1] * s[4];
double c = r[0] * s[2] + r[1] * s[5] + r[2];
double d = r[3] * s[0] + r[4] * s[3];
double e = r[3] * s[1] + r[4] * s[4];
// Pixel YDim - almost always negative
// See https://en.wikipedia.org/wiki/World_file#cite_ref-3, https://issues.qgis.org/issues/18491
double e = r[3] * s[1] + r[4] * s[4];
double f = r[3] * s[2] + r[4] * s[5] + r[5];

QString content;
@@ -113,10 +115,9 @@ QString QgsMapSettingsUtils::worldFileContent( const QgsMapSettings &mapSettings
// Rotation on y axis
content += qgsDoubleToString( d ) + "\r\n";
// Rotation on x axis
content += qgsDoubleToString( -b ) + "\r\n";
// Pixel YDim - almost always negative
// See https://en.wikipedia.org/wiki/World_file#cite_ref-3
content += "-" + qgsDoubleToString( e ) + "\r\n";
content += qgsDoubleToString( b ) + "\r\n";
// Pixel YDim
content += qgsDoubleToString( e ) + "\r\n";
// Origin X (center of top left cell)
content += qgsDoubleToString( c ) + "\r\n";
// Origin Y (center of top left cell)
@@ -52,6 +52,9 @@ void TestQgsMapSettingsUtils::createWorldFileContent()

mMapSettings.setRotation( 45 );
QCOMPARE( QgsMapSettingsUtils::worldFileContent( mMapSettings ), QString( "0.70710678118654757\r\n0.70710678118654746\r\n0.70710678118654746\r\n-0.70710678118654757\r\n0.5\r\n0.49999999999999994\r\n" ) );

mMapSettings.setRotation( 145 );
QCOMPARE( QgsMapSettingsUtils::worldFileContent( mMapSettings ), QString( "-0.81915204428899191\r\n0.57357643635104594\r\n0.57357643635104594\r\n0.81915204428899191\r\n0.5\r\n0.49999999999999994\r\n" ) );
}

QGSTEST_MAIN( TestQgsMapSettingsUtils )

0 comments on commit a2ba566

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