[QGIS Commit] r10028 - trunk/qgis/src/gui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Jan 27 01:08:31 EST 2009
Author: timlinux
Date: 2009-01-27 01:08:31 -0500 (Tue, 27 Jan 2009)
New Revision: 10028
Modified:
trunk/qgis/src/gui/qgsmapcanvas.cpp
Log:
Write a world file when creating a screenshot so that it is georeferenced
Modified: trunk/qgis/src/gui/qgsmapcanvas.cpp
===================================================================
--- trunk/qgis/src/gui/qgsmapcanvas.cpp 2009-01-27 01:15:05 UTC (rev 10027)
+++ trunk/qgis/src/gui/qgsmapcanvas.cpp 2009-01-27 06:08:31 UTC (rev 10028)
@@ -20,6 +20,8 @@
#include <QtGlobal>
#include <QApplication>
#include <QCursor>
+#include <QDir>
+#include <QFile>
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QGraphicsView>
@@ -29,6 +31,7 @@
#include <QPaintEvent>
#include <QPixmap>
#include <QRect>
+#include <QTextStream>
#include <QResizeEvent>
#include <QString>
#include <QStringList>
@@ -412,6 +415,31 @@
{
mMap->pixmap().save( theFileName, theFormat.toLocal8Bit().data() );
}
+ //create a world file to go with the image...
+ QgsRectangle myRect = mMapRenderer->extent();
+ QString myHeader;
+ //Pixel XDim
+ myHeader += QString::number( mapUnitsPerPixel() ) + "\r\n";
+ //Rotation on y axis - hard coded
+ myHeader += "0 \r\n";
+ //Rotation on x axis - hard coded
+ myHeader += "0 \r\n";
+ //Pixel YDim - almost always negative - see
+ //http://en.wikipedia.org/wiki/World_file#cite_note-2
+ myHeader += "-" + QString::number( mapUnitsPerPixel() ) + "\r\n";
+ //Origin X (top left corner)
+ myHeader += QString::number( myRect.xMinimum() ) + "\r\n";
+ //Origin Y (top left corner)
+ myHeader += QString::number( myRect.yMaximum() ) + "\r\n";
+ QFileInfo myInfo = QFileInfo(theFileName);
+ QString myWorldFileName = myInfo.absolutePath() + QDir::separator() + myInfo.baseName() + "." + theFormat + "w";
+ QFile myWorldFile(myWorldFileName);
+ if (!myWorldFile.open(QIODevice::WriteOnly | QIODevice::Text))
+ {
+ return;
+ }
+ QTextStream myStream(&myWorldFile);
+ myStream << myHeader;
} // saveAsImage
More information about the QGIS-commit
mailing list