Skip to content
This repository has been archived by the owner on Feb 11, 2025. It is now read-only.

Commit

Permalink
FIX #10 Added a dialog in Scale tool to enter scale + DPI
Browse files Browse the repository at this point in the history
- Contributed by Dkrav-UA
- Right-Click to open
  • Loading branch information
gvellut committed Feb 26, 2018
1 parent 15fb905 commit acc7d26
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 23 deletions.
75 changes: 53 additions & 22 deletions freehandrastergeoreferencer_maptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
from operator import itemgetter

from PyQt4.QtCore import Qt
from PyQt4.QtGui import QApplication
from PyQt4.QtGui import QApplication, QInputDialog, QMessageBox
from qgis.core import QGis, QgsPoint, QgsGeometry
from qgis.gui import QgsMapToolEmitPoint, QgsRubberBand


from rastershadowmapcanvasitem import RasterShadowMapCanvasItem
from utils import tryfloat


class MoveRasterMapTool(QgsMapToolEmitPoint):
Expand Down Expand Up @@ -274,36 +276,65 @@ def reset(self):
self.layer = None

def canvasPressEvent(self, e):
self.startPoint = e.pos()
self.endPoint = self.startPoint
self.isEmittingPoint = True
self.height = float(self.canvas.height())
self.width = float(self.canvas.width())
pressed_button = e.button()
if pressed_button == 1:
self.startPoint = e.pos()
self.endPoint = self.startPoint
self.isEmittingPoint = True
self.height = float(self.canvas.height())
self.width = float(self.canvas.width())

modifiers = QApplication.keyboardModifiers()
self.isKeepRelativeScale = bool(modifiers & Qt.ControlModifier)
modifiers = QApplication.keyboardModifiers()
self.isKeepRelativeScale = bool(modifiers & Qt.ControlModifier)

self.isLayerVisible = self.iface.legendInterface().isLayerVisible(
self.layer)
self.iface.legendInterface().setLayerVisible(self.layer, False)
self.isLayerVisible = self.iface.legendInterface().isLayerVisible(
self.layer)
self.iface.legendInterface().setLayerVisible(self.layer, False)

scaling = self.computeScaling()
self.showScaling(*scaling)
scaling = self.computeScaling()
self.showScaling(*scaling)

def canvasReleaseEvent(self, e):
self.isEmittingPoint = False
pressed_button = e.button()
if pressed_button == 1:
self.isEmittingPoint = False

self.rubberBandExtent.reset(QGis.Line)
self.rasterShadow.reset()
self.rubberBandExtent.reset(QGis.Line)
self.rasterShadow.reset()

xScale, yScale = self.computeScaling()
self.layer.setScale(xScale * self.layer.xScale,
yScale * self.layer.yScale)
xScale, yScale = self.computeScaling()
self.layer.setScale(xScale * self.layer.xScale,
yScale * self.layer.yScale)

self.iface.legendInterface().setLayerVisible(self.layer,
self.isLayerVisible)
self.layer.repaint()
self.iface.legendInterface().setLayerVisible(self.layer,
self.isLayerVisible)
elif pressed_button == 2:
number, ok = QInputDialog.getText(
None, u'Scale & DPI', u'Enter scale,dpi (e.g. 3000,96)')
if not ok:
return
scales = number.split(',')
if len(scales) != 2:
QMessageBox.information(
self.iface.mainWindow(),
u'Error',
u'Must be 2 numbers')
return
scale = tryfloat(scales[0])
dpi = tryfloat(scales[1])
if scale and dpi:
xScale = scale / (dpi / 0.0254)
yScale = xScale
else:
QMessageBox.information(
self.iface.mainWindow(),
u'Error',
u'Bad format: Must be scale,dpi (e.g. 3000,96)')
return

self.layer.setScale(xScale, yScale)

self.layer.repaint()
self.layer.commitTransformParameters()

def canvasMoveEvent(self, e):
Expand Down
2 changes: 1 addition & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = Freehand raster georeferencer
qgisMinimumVersion = 2.2
description = Interactive georeferencing of rasters
about = Tools to georeference a raster interactively (move, rotate, scale, export...)
version = 0.3.0
version = 0.4.0
author = Guilhem Vellut
email = [email protected]
tags = raster,georeferencing
Expand Down
8 changes: 8 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ def toRelativeToQGS(imagePath):
qDebug(imagePath.encode('utf8'))

return imagePath


def tryfloat(strF):
try:
f = float(strF)
return f
except ValueError:
return None

0 comments on commit acc7d26

Please sign in to comment.