5

I am using the Freehand Raster Georeferencing code in a widget to help size and locate site plans on aerial GE backdrops. I need to find a way for a user to input a specific angle of rotation and the site plan snaps to that angle. Below is a screenshot of my current set-up with comments.

example

In addition, is there a way to have a Qt-widget that dynamically changes the rotation angle when the user manually rotates the image. (Note: this is not my main question)

Below is the georeferencing rotation class:

class RotateRasterMapTool(QgsMapToolEmitPoint):
def __init__(self, iface):
    self.iface = iface
    self.canvas = iface.mapCanvas()
    super(RotateRasterMapTool, self).__init__(self.canvas)

    self.rasterShadow = RasterShadowMapCanvasItem(self.canvas)

    self.rubberBandExtent = QgsRubberBand(self.canvas, QgsWkbTypes.LineGeometry)
    self.rubberBandExtent.setColor(Qt.red)
    self.rubberBandExtent.setWidth(1)

    self.reset()

def setLayer(self, layer):
    self.layer = layer

def reset(self):
    self.startPoint = self.endPoint = None
    self.isEmittingPoint = False
    self.rubberBandExtent.reset(QgsWkbTypes.LineGeometry)
    self.rasterShadow.reset()
    self.layer = None

def canvasPressEvent(self, e):
    self.startY = e.pos().y()
    self.endY = self.startY
    self.isEmittingPoint = True
    self.height = self.canvas.height()

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

    rotation = self.computeRotation()
    self.showRotation(rotation)


def canvasReleaseEvent(self, e):
    self.isEmittingPoint = False

    self.rubberBandExtent.reset(QgsWkbTypes.LineGeometry)
    self.rasterShadow.reset()

    rotation = self.computeRotation()
    self.layer.setRotation(self.layer.rotation + rotation)

    setLayerVisible(self.iface, self.layer, self.isLayerVisible)
    self.layer.repaint()

    self.layer.commitTransformParameters()

def canvasMoveEvent(self, e):
    if not self.isEmittingPoint:
        return

    self.endY = e.pos().y()
    rotation = self.computeRotation()
    self.showRotation(rotation)

def computeRotation(self):
    dY = self.endY - self.startY
    return 90.0 * dY / self.height

def showRotation(self, rotation):
    center, originalRotation, xScale, yScale = self.layer.transformParameters()
    newRotation = rotation + originalRotation
    cornerPoints = self.layer.transformedCornerCoordinates(center, newRotation, xScale, yScale)

    self.rubberBandExtent.reset(QgsWkbTypes.LineGeometry)
    for point in cornerPoints:
        self.rubberBandExtent.addPoint(point, False)
    # for closing
    self.rubberBandExtent.addPoint(cornerPoints[0], True)
    self.rubberBandExtent.show()

    self.rasterShadow.reset(self.layer)
    self.rasterShadow.setDeltaRotation(rotation, True)
    self.rasterShadow.show()

Any ideas as to how to integrate a user-specific rotation angle input with this dock.

Any ideas as to how I could take the rotation angle and show it on a Qt-widget?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.