Skip to content

Instantly share code, notes, and snippets.

@m-kuhn
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-kuhn/54950404f47375208b65 to your computer and use it in GitHub Desktop.
Save m-kuhn/54950404f47375208b65 to your computer and use it in GitHub Desktop.
QgsMapToPixel / QMatrix4x4
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() );
@m-kuhn
Copy link
Author

m-kuhn commented Nov 24, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment