Skip to content

Commit f14d758

Browse files
author
mhugent
committed
Backport of smizunos patch that fixes #1540
git-svn-id: http://svn.osgeo.org/qgis/branches/Version-1_0@10593 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c2e13e7 commit f14d758

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎src/gui/qgsmapcanvas.cpp‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,23 +418,25 @@ void QgsMapCanvas::saveAsImage( QString theFileName, QPixmap * theQPixmap, QStri
418418
//create a world file to go with the image...
419419
QgsRectangle myRect = mMapRenderer->extent();
420420
QString myHeader;
421+
// note: use 17 places of precision for all numbers output
421422
//Pixel XDim
422-
myHeader += QString::number( mapUnitsPerPixel() ) + "\r\n";
423+
myHeader += QString::number( mapUnitsPerPixel(), 'g', 17 ) + "\r\n";
423424
//Rotation on y axis - hard coded
424425
myHeader += "0 \r\n";
425426
//Rotation on x axis - hard coded
426427
myHeader += "0 \r\n";
427428
//Pixel YDim - almost always negative - see
428429
//http://en.wikipedia.org/wiki/World_file#cite_note-2
429-
myHeader += "-" + QString::number( mapUnitsPerPixel() ) + "\r\n";
430-
//Origin X (top left corner)
431-
myHeader += QString::number( myRect.xMinimum() ) + "\r\n";
432-
//Origin Y (top left corner)
433-
myHeader += QString::number( myRect.yMaximum() ) + "\r\n";
430+
myHeader += "-" + QString::number( mapUnitsPerPixel(), 'g', 17 ) + "\r\n";
431+
//Origin X (center of top left cell)
432+
myHeader += QString::number( myRect.xMinimum() + ( mapUnitsPerPixel() / 2 ), 'g', 17 ) + "\r\n";
433+
//Origin Y (center of top left cell)
434+
myHeader += QString::number( myRect.yMaximum() - ( mapUnitsPerPixel() / 2 ), 'g', 17 ) + "\r\n";
434435
QFileInfo myInfo = QFileInfo( theFileName );
435-
QString myWorldFileName = myInfo.absolutePath() + QDir::separator() + myInfo.baseName() + "." + theFormat + "w";
436+
// allow dotted names
437+
QString myWorldFileName = myInfo.absolutePath() + QDir::separator() + myInfo.completeBaseName() + "." + theFormat + "w";
436438
QFile myWorldFile( myWorldFileName );
437-
if ( !myWorldFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
439+
if ( !myWorldFile.open( QIODevice::WriteOnly ) ) //don't use QIODevice::Text
438440
{
439441
return;
440442
}

0 commit comments

Comments
 (0)