vinayan / RectOvalDigitPlugin

A Quantum GIS plugin to digitize rectangles, ovals and other shapes
3 stars 5 forks source link

Feature Request: Set dimensions when creating new feature #1

Open mixedbredie opened 10 years ago

mixedbredie commented 10 years ago

How easy would it be to update the plugin to allow the user to define the radius of a circle or dimensions of a rectangle / elipse when creating new features? It would be useful if the user could define the circle radius as, say 10m, and then create a set of circles of the same size. Or have a feature that showing the radius/dimensions of the feature being created as the user digitises it.

jonathan-wcc commented 10 years ago

+1 - this would be exceptionally useful. I've had two users in completely separate teams ask for this in the last couple of days.

jtornero commented 10 years ago

Well... I've read two messages from the qgis list abouit this and maybe some code I'm trying for my transectizer plugin can be useful for you. Instead of having a harcoded QCursor, I create it assign it to the tool in every canvasMoveEnvent:

    def canvasMoveEvent(self, e):
        """
        When isEmittingPoint is True (set by canvasPressEvent),
        the signal movingCanvas is emitted with the initial and end
        point of the rubberband and also the rubberBand is updated.
        Also the tool's cursor is updated with the bearing
        """
        if self.isEmittingPoint:
            start=self.startPoint
            end=self.toMapCoordinates(e.pos())
            startLat = math.radians(start.y())
            startLon = math.radians(start.x())
            endLat = math.radians(end.y())
            endLon = math.radians(end.x())

            # Calculation. The bearing is obtained in azimuth and radians and must be
            # transformed to degrees and bearing
            deltaLon = endLon - startLon
            y = math.sin(deltaLon) * math.cos(endLat)
            x = math.cos(startLat) * math.sin(endLat) - math.sin(startLat) *\
                math.cos(endLat) * math.cos(deltaLon)
            bearing = (5 * math.pi / 2) - math.atan2(x, y)
            bearing = round( math.degrees(bearing), 0) % 360

            #Here is the cursor stuff
            self.cursorPix.fill(Qt.transparent)
            pinta=QPainter(self.cursorPix)
            font=QFont()
            font.setPixelSize(8)
            pinta.setFont(font)
            pinta.drawText(0,0,32,32,Qt.AlignHCenter,str('BRG\n%i' %bearing))
            #This is for making the hot point always visible (experimental)
            hotx=round(32*math.cos(math.radians(bearing)),0)
            hoty=round(32*math.sin(math.radians(bearing)),0)

            self.cursor=QCursor(self.cursorPix,hotx,hoty)

            self.parent().setCursor(self.cursor)

            self.movingCanvas.emit(self.startPoint,self.toMapCoordinates(e.pos()))

Well, it could be helpful and it is just matter of doing this in every canvasMoveEvent of the tool classes in rectovaldigittools file, making the appropiate changes of course and instead of calculating my bearing (which is my case) call to qgsdistancearea measureline method or something like that.

Best regards

Jorge Tornero