Last active
August 29, 2015 14:10
-
-
Save m-kuhn/54950404f47375208b65 to your computer and use it in GitHub Desktop.
QgsMapToPixel / QMatrix4x4
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
QgsMapSettings mapSettings = mMapCanvas->mapSettings(); | |
QMatrix4x4 matrix; | |
float scaleFactor = mMapCanvas->width() / mapSettings.extent().width(); | |
// The following leads to a slight offset depending on the position on the canvas | |
// float scaleFactor = 1/mapSettings.mapToPixel().mapUnitsPerPixel(); | |
matrix.scale( scaleFactor, -scaleFactor ); | |
matrix.translate( -mapSettings.extent().xMinimum(), -mapSettings.extent().yMaximum() ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
QMatrix4x4 works on qReal (Qt4) and float (Qt5). That introduces unprecise results on large scales. Better to switch it to a double precision matrix instead.