Skip to main content
2 of 2
deleted 1 character in body
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404

The error is related with (0.5)*(extent.width). You try to multiply a float (0.5) by a method (extent.width). width doesn't call the method. To call a method, you have to use parentheses. So it has to be extent.width(). Also center.x and center.y have to be center.x() and center.y(). You used all in original code correctly, but missed in the next one.

Try in this way:

def __createRubberBand(self):
    self.__cleanup()
    extent = self.mapitem.extent()
    center = self.iface.mapCanvas().extent().center()
    
    r = iface.mapCanvas().rotation()    
    rs = math.sin(r)
    rc = math.cos(r)    
    w = 0.5 * extent.width() ##
                                  ##                              ##
    self.corner = QPointF(center.x() - (w * rc - w * rs), center.y() - (w * rs + w * rc))
    self.rect = QRectF(self.corner.x(), self.corner.y(), extent.width(), extent.height())
    self.mapitem.setExtent(QgsRectangle(self.rect))
    self.rubberband = QgsRubberBand(self.iface.mapCanvas(), QgsWkbTypes.PolygonGeometry)
    self.rubberband.setToCanvasRectangle(self.__canvasRect(self.rect))
    self.rubberband.setColor(QColor(127, 127, 255, 127))

I'm not sure if it solves your other problem, but it helps you not to get that error.

Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404