Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add a QgsMapSettingsUtils::worldFileContent() function
- Loading branch information
Showing
9 changed files
with
194 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgsmapsettingsutils.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
class QgsMapSettingsUtils | ||
{ | ||
%Docstring | ||
Utilities for map settings. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsmapsettingsutils.h" | ||
%End | ||
public: | ||
|
||
static QString worldFileContent( const QgsMapSettings &mapSettings ); | ||
%Docstring | ||
Creates the content of a world file. | ||
\param mapSettings map settings | ||
.. note:: | ||
|
||
Uses 17 places of precision for all numbers output | ||
:rtype: str | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgsmapsettingsutils.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*************************************************************************** | ||
qgsmapsettingsutils.cpp | ||
------------------- | ||
begin : May 2017 | ||
copyright : (C) 2017 by Mathieu Pellerin | ||
email : nirvn dot asia at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsmapsettings.h" | ||
#include "qgsmapsettingsutils.h" | ||
|
||
#include <QString> | ||
|
||
QString QgsMapSettingsUtils::worldFileContent( const QgsMapSettings &mapSettings ) | ||
{ | ||
double xOrigin = mapSettings.visiblePolygon().at( 0 ).x() + ( mapSettings.mapUnitsPerPixel() / 2 ); | ||
double yOrigin = mapSettings.visiblePolygon().at( 0 ).y() - ( mapSettings.mapUnitsPerPixel() / 2 ); | ||
|
||
QString content; | ||
// Pixel XDim | ||
content += qgsDoubleToString( mapSettings.mapUnitsPerPixel() ) + "\r\n"; | ||
// Rotation on y axis | ||
content += QString( "%1\r\n" ).arg( mapSettings.rotation() ); | ||
// Rotation on x axis | ||
content += QString( "%1\r\n" ).arg( mapSettings.rotation() ); | ||
// Pixel YDim - almost always negative | ||
// See https://en.wikipedia.org/wiki/World_file#cite_ref-3 | ||
content += '-' + qgsDoubleToString( mapSettings.mapUnitsPerPixel() ) + "\r\n"; | ||
// Origin X (center of top left cell) | ||
content += qgsDoubleToString( xOrigin ) + "\r\n"; | ||
// Origin Y (center of top left cell) | ||
content += qgsDoubleToString( yOrigin ) + "\r\n"; | ||
|
||
return content; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*************************************************************************** | ||
qgsmapsettingsutils.h | ||
------------------- | ||
begin : May 2017 | ||
copyright : (C) 2017 by Mathieu Pellerin | ||
email : nirvn dot asia at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSMAPSETTINGSUTILS_H | ||
#define QGSMAPSETTINGSUTILS_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgsmapsettings.h" | ||
|
||
#include <QString> | ||
|
||
/** \ingroup core | ||
* Utilities for map settings. | ||
* \since QGIS 3.0 | ||
*/ | ||
class CORE_EXPORT QgsMapSettingsUtils | ||
{ | ||
|
||
public: | ||
|
||
/** Creates the content of a world file. | ||
* \param mapSettings map settings | ||
* \note Uses 17 places of precision for all numbers output | ||
*/ | ||
static QString worldFileContent( const QgsMapSettings &mapSettings ); | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*************************************************************************** | ||
testqgsmapsettingsutils.cpp | ||
----------------------- | ||
begin : May 2017 | ||
copyright : (C) 2017 by Mathieu Pellerin | ||
email : nirvn dot asia at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgstest.h" | ||
|
||
#include "qgsmapsettings.h" | ||
#include "qgsmapsettingsutils.h" | ||
|
||
#include <QString> | ||
|
||
class TestQgsMapSettingsUtils : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
private slots: | ||
void initTestCase();// will be called before the first testfunction is executed. | ||
void cleanupTestCase() {} // will be called after the last testfunction was executed. | ||
void init() {} // will be called before each testfunction is executed. | ||
void cleanup() {} // will be called after each testfunction was executed. | ||
|
||
void createWorldFileContent(); //test world file content function | ||
|
||
private: | ||
|
||
QgsMapSettings mMapSettings; | ||
|
||
}; | ||
|
||
void TestQgsMapSettingsUtils::initTestCase() | ||
{ | ||
mMapSettings.setExtent( QgsRectangle( 0, 0, 1, 1 ) ); | ||
} | ||
|
||
void TestQgsMapSettingsUtils::createWorldFileContent() | ||
{ | ||
QCOMPARE( QgsMapSettingsUtils::worldFileContent( mMapSettings ), QString( "1\r\n0\r\n0\r\n-1\r\n0.5\r\n0.5\r\n" ) ); | ||
} | ||
|
||
QGSTEST_MAIN( TestQgsMapSettingsUtils ) | ||
#include "testqgsmapsettingsutils.moc" |