-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46654 from nirvn/scalecalc_canvaswidth
[feature] Add a QgsScaleCalculator function to calculate canvas width from a given extent, scale, and dpi
- Loading branch information
Showing
5 changed files
with
101 additions
and
15 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
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,39 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for QgsScaleCalculator | ||
.. note:: 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. | ||
""" | ||
__author__ = 'Mathieu Pellerin' | ||
__date__ = '30/12/2021' | ||
__copyright__ = 'Copyright 2021, The QGIS Project' | ||
|
||
import qgis # NOQA | ||
import math | ||
from qgis.PyQt.QtCore import Qt, QSizeF | ||
from qgis.PyQt.QtTest import QSignalSpy | ||
|
||
from qgis.core import QgsScaleCalculator, QgsRectangle, QgsUnitTypes | ||
from qgis.testing import start_app, unittest | ||
|
||
start_app() | ||
|
||
|
||
class TestQgsScaleCalculator(unittest.TestCase): | ||
|
||
def testCalculateImageSize(self): | ||
calculator = QgsScaleCalculator() | ||
|
||
calculator.setDpi(96) | ||
calculator.setMapUnits(QgsUnitTypes.DistanceMeters) | ||
|
||
extent = QgsRectangle(336609, 1162304, 354942, 1168151) | ||
image_size = calculator.calculateImageSize(extent, 65000) | ||
self.assertAlmostEqual(image_size.width(), 1066.001, 3) | ||
self.assertAlmostEqual(image_size.height(), 339.983, 3) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |