コード例 #1
0
ファイル: QgsFmvDrawToolBar.py プロジェクト: mhugent/QGISFMV
    def drawLinesOnVideo(pt, idx, painter, surface, gt, drawLines):
        ''' Draw Lines on Video '''
        if hasElevationModel():
            pt = GetLine3DIntersectionWithPlane(GetSensor(), pt,
                                                GetFrameCenter()[2])

        scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface)

        center = QPoint(scr_x, scr_y)

        painter.setPen(LinePen)

        if len(drawLines) > 1:
            try:
                pt = drawLines[idx + 1]
                if hasElevationModel():
                    pt = GetLine3DIntersectionWithPlane(
                        GetSensor(), pt,
                        GetFrameCenter()[2])
                scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface)
                end = QPoint(scr_x, scr_y)
                painter.drawLine(center, end)

                # Draw Start/End Points
                painter.setPen(DrawToolBar.white_pen)
                painter.drawPoint(center)
                painter.drawPoint(end)
            except Exception:
                None
        return
コード例 #2
0
    def drawRulerOnVideo(pt, idx, painter, surface, gt, drawRuler):
        ''' Draw Ruler on Video '''
        if hasElevationModel():
            pt = GetLine3DIntersectionWithPlane(
                GetSensor(), pt, GetFrameCenter()[2])

        scr_x, scr_y = vut.GetInverseMatrix(
            pt[1], pt[0], gt, surface)

        center_pt = pt

        radius_pt = 5
        center = QPoint(scr_x, scr_y)

        if len(drawRuler) > 1:
            try:
                pen = QPen(Qt.red)
                pen.setWidth(3)
                painter.setPen(pen)

                end_pt = drawRuler[idx + 1]

                if hasElevationModel():
                    end_pt = GetLine3DIntersectionWithPlane(
                        GetSensor(), end_pt, GetFrameCenter()[2])
                scr_x, scr_y = vut.GetInverseMatrix(
                    end_pt[1], end_pt[0], gt, surface)
                end = QPoint(scr_x, scr_y)
                painter.drawLine(center, end)

                font12 = QFont("Arial", 12, weight=QFont.Bold)
                painter.setFont(font12)

                distance = round(sphere.distance(
                    (center_pt[0], center_pt[1]), (end_pt[0], end_pt[1])), 2)

                text = str(distance) + " m"
                global RulerTotalMeasure
                RulerTotalMeasure += distance

                # Draw Start/End Points
                pen = QPen(Qt.white)
                pen.setWidth(radius_pt)
                pen.setCapStyle(Qt.RoundCap)
                painter.setPen(pen)
                painter.drawPoint(center)
                painter.drawPoint(end)

                painter.drawText(end + QPoint(5, -5), text)

                pen = QPen(QColor(255, 51, 153))
                painter.setPen(pen)
                painter.drawText(end + QPoint(5, 10),
                                 str(round(RulerTotalMeasure, 2)) + " m")

            except Exception:
                None
        return
コード例 #3
0
    def drawMeasureAreaOnVideo(values, painter, surface, gt):
        ''' Draw Measure Area on Video '''

        a_value = sphere.polygon_area([values])
        
        poly = []
        lat = []
        long = []
        for pt in values:
            if hasElevationModel():
                pt = GetLine3DIntersectionWithPlane(
                    GetSensor(), pt, GetFrameCenter()[2])
            scr_x, scr_y = vut.GetInverseMatrix(
                pt[1], pt[0], gt, surface)
            center = QPoint(scr_x, scr_y)
            poly.append(center)
            
            lat.append(pt[0])
            long.append(pt[1])

#         Fix: Temporary correction
#         mousePressEvent calls after mouseMoveEvent.
#         A problem occurs because the centroid is miscalculated.
#         We remove duplicates values
        lat = list(dict.fromkeys(lat))
        long = list(dict.fromkeys(long))

        # Calculate Centroid Position
        scr_x, scr_y = vut.GetInverseMatrix(
                sum(long)/len(long), sum(lat)/len(lat), gt, surface)
        
        centroid = QPoint(scr_x, scr_y)
        
        # Create Poligon
        polygon = QPolygonF(poly)
        
        path = QPainterPath()
        path.addPolygon(polygon)
        
        painter.setFont(DrawToolBar.bold_12)

        painter.setPen(MeasurePen)
        painter.drawPolygon(polygon)
        painter.fillPath(path, MeasureBrush)
        painter.setPen(DrawToolBar.white_pen)
        painter.drawPoints(polygon)
        
        # Area
        if a_value >= 10000:
            painter.drawText(centroid , str(round(a_value/1000000, 2)) + " km²")
        else:
            painter.drawText(centroid , str(round(a_value, 2)) + " m²")
        return
コード例 #4
0
    def drawMeasureAreaOnVideo(values, painter, surface, gt):
        """ Draw Measure Area on Video """

        da = QgsDistanceArea()
        da.setEllipsoid(WGS84String)

        points = []
        poly = []

        for pt in values:
            scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface)
            center = QPoint(scr_x, scr_y)
            poly.append(center)
            points.append(QgsPointXY(pt[1], pt[0]))

        # Create Video Polygon
        polygon = QPolygonF(poly)

        path = QPainterPath()
        path.addPolygon(polygon)

        painter.setFont(DrawToolBar.bold_12)

        painter.setPen(MeasurePen)
        painter.drawPolygon(polygon)
        painter.fillPath(path, MeasureBrush)
        painter.setPen(DrawToolBar.white_pen)
        painter.drawPoints(polygon)

        # Create QGIS Polygon
        mapPolygon = QgsGeometry.fromPolygonXY([points])

        # Calculate polygon area
        area = da.measureArea(mapPolygon)

        try:
            ctr = mapPolygon.centroid().asPoint()
            # Calculate Centroid Position
            scr_x, scr_y = vut.GetInverseMatrix(ctr.x(), ctr.y(), gt, surface)
            centroid = QPoint(scr_x, scr_y)

            # Area
            if area >= 10000:
                painter.drawText(
                    centroid,
                    str(round(da.convertAreaMeasurement(area, 1), 2)) + " km²")
            else:
                painter.drawText(centroid, str(round(area, 2)) + " m²")
        except Exception:
            None

        return
コード例 #5
0
ファイル: QgsFmvDrawToolBar.py プロジェクト: mhugent/QGISFMV
    def drawMeasureDistanceOnVideo(pt, idx, painter, surface, gt,
                                   drawMDistance):
        ''' Draw Measure Distance on Video '''
        if hasElevationModel():
            pt = GetLine3DIntersectionWithPlane(GetSensor(), pt,
                                                GetFrameCenter()[2])

        scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface)

        center = QPoint(scr_x, scr_y)

        if len(drawMDistance) > 1:
            try:
                painter.setPen(MeasurePen)

                end_pt = drawMDistance[idx + 1]

                if hasElevationModel():
                    end_pt = GetLine3DIntersectionWithPlane(
                        GetSensor(), end_pt,
                        GetFrameCenter()[2])
                scr_x, scr_y = vut.GetInverseMatrix(end_pt[1], end_pt[0], gt,
                                                    surface)
                end = QPoint(scr_x, scr_y)
                painter.drawLine(center, end)

                painter.setFont(DrawToolBar.bold_12)

                distance = round(
                    sphere.distance((pt[0], pt[1]), (end_pt[0], end_pt[1])), 2)

                text = str(distance) + " m"
                global RulerTotalMeasure
                RulerTotalMeasure += distance

                # Line lenght
                painter.setPen(MeasurePen)
                painter.drawText(end + QPoint(5, -10), text)

                painter.setPen(DrawToolBar.white_pen)
                # Total lenght
                painter.drawText(end + QPoint(5, 10),
                                 str(round(RulerTotalMeasure, 2)) + " m")

                # Draw Start/End Points
                painter.drawPoint(center)
                painter.drawPoint(end)
            except Exception:
                None
        return
コード例 #6
0
    def drawMeasureDistanceOnVideo(pt, idx, painter, surface, gt,
                                   drawMDistance):
        """ Draw Measure Distance on Video """
        global RulerTotalMeasure

        scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface)

        center = QPoint(scr_x, scr_y)

        if len(drawMDistance) > 1:
            try:
                painter.setPen(MeasurePen)

                end_pt = drawMDistance[idx + 1]

                scr_x, scr_y = vut.GetInverseMatrix(end_pt[1], end_pt[0], gt,
                                                    surface)
                end = QPoint(scr_x, scr_y)
                painter.drawLine(center, end)

                painter.setFont(DrawToolBar.bold_12)

                initialPoint = QgsPointXY(pt[0], pt[1])
                destPoint = QgsPointXY(end_pt[0], end_pt[1])

                da = QgsDistanceArea()
                da.setEllipsoid(WGS84String)
                m = da.measureLine(initialPoint, destPoint)
                distance = round(m, 2)
                text = str(distance) + " m"

                # Sum values to total distance
                RulerTotalMeasure += distance

                # Line lenght
                painter.setPen(MeasurePen)
                painter.drawText(end + QPoint(5, -10), text)

                painter.setPen(DrawToolBar.white_pen)
                # Total lenght
                painter.drawText(end + QPoint(5, 10),
                                 str(round(RulerTotalMeasure, 2)) + " m")

                # Draw Start/End Points
                painter.drawPoint(center)
                painter.drawPoint(end)
            except Exception:
                None
        return
コード例 #7
0
ファイル: QgsFmvDrawToolBar.py プロジェクト: mhugent/QGISFMV
    def drawPointOnVideo(number, pt, painter, surface, gt):
        ''' Draw Points on Video '''
        if hasElevationModel():
            pt = GetLine3DIntersectionWithPlane(GetSensor(), pt,
                                                GetFrameCenter()[2])

        scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface)

        # don't draw something outside the screen.
        if scr_x < vut.GetXBlackZone(surface) or scr_y < vut.GetYBlackZone(
                surface):
            return

        if scr_x > vut.GetXBlackZone(surface) + vut.GetNormalizedWidth(
                surface) or scr_y > vut.GetYBlackZone(
                    surface) + vut.GetNormalizedHeight(surface):
            return

        center = QPoint(scr_x, scr_y)

        painter.setPen(PointPen)
        painter.drawPoint(center)
        painter.setFont(DrawToolBar.bold_12)
        painter.drawText(center + QPoint(5, -5), str(number))
        return
コード例 #8
0
    def drawPointOnVideo(number, pt, painter, surface, gt):
        ''' Draw Points on Video '''
        if hasElevationModel():
            pt = GetLine3DIntersectionWithPlane(
                GetSensor(), pt, GetFrameCenter()[2])

        scr_x, scr_y = vut.GetInverseMatrix(
            pt[1], pt[0], gt, surface)

        # don't draw something outside the screen.
        if scr_x < vut.GetXBlackZone(surface) or scr_y < vut.GetYBlackZone(surface):
            return

        if scr_x > vut.GetXBlackZone(surface) + vut.GetNormalizedWidth(surface) or scr_y > vut.GetYBlackZone(surface) + vut.GetNormalizedHeight(surface):
            return

        radius = 10
        center = QPoint(scr_x, scr_y)

        pen = QPen(Qt.red)
        pen.setWidth(radius)
        pen.setCapStyle(Qt.RoundCap)
        painter.setPen(pen)
        painter.drawPoint(center)
        font12 = QFont("Arial", 12, weight=QFont.Bold)
        painter.setFont(font12)
        painter.drawText(center + QPoint(5, -5), str(number))
        return
コード例 #9
0
    def drawPolygonOnVideo(values, painter, surface, gt):
        ''' Draw Polygons on Video '''
        poly = []
        for pt in values:
            if hasElevationModel():
                pt = GetLine3DIntersectionWithPlane(
                    GetSensor(), pt, GetFrameCenter()[2])
            scr_x, scr_y = vut.GetInverseMatrix(
                pt[1], pt[0], gt, surface)
            center = QPoint(scr_x, scr_y)
            poly.append(center)

        poly.append(poly[0])

        radius = 3
        polygon = QPolygonF(poly)
        pen = QPen()
        pen.setColor(Qt.green)
        pen.setWidth(radius)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)

        brush = QBrush()
        brush.setColor(QColor(176, 255, 128, 28))
        brush.setStyle(Qt.SolidPattern)

        path = QPainterPath()
        path.addPolygon(polygon)

        painter.setPen(pen)
        painter.drawPolygon(polygon)
        painter.fillPath(path, brush)
        return
コード例 #10
0
    def drawMeasureAreaOnVideo(values, painter, surface, gt):
        ''' Draw Measure Area on Video '''
        a_value = sphere.polygon_area([values])

        poly = []
        lat = []
        long = []
        for pt in values:
            scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface)
            center = QPoint(scr_x, scr_y)
            poly.append(center)

            lat.append(pt[0])
            long.append(pt[1])

        lat = list(dict.fromkeys(lat))
        long = list(dict.fromkeys(long))

        # Calculate Centroid Position
        scr_x, scr_y = vut.GetInverseMatrix(
            sum(long) / len(long),
            sum(lat) / len(lat), gt, surface)

        centroid = QPoint(scr_x, scr_y)

        # Create Poligon
        polygon = QPolygonF(poly)

        path = QPainterPath()
        path.addPolygon(polygon)

        painter.setFont(DrawToolBar.bold_12)

        painter.setPen(MeasurePen)
        painter.drawPolygon(polygon)
        painter.fillPath(path, MeasureBrush)
        painter.setPen(DrawToolBar.white_pen)
        painter.drawPoints(polygon)

        # Area
        if a_value >= 10000:
            painter.drawText(centroid,
                             str(round(a_value / 1000000, 2)) + " km²")
        else:
            painter.drawText(centroid, str(round(a_value, 2)) + " m²")
        return
コード例 #11
0
    def drawLinesOnVideo(pt, idx, painter, surface, gt, drawLines):
        ''' Draw Lines on Video '''
        if hasElevationModel():
            pt = GetLine3DIntersectionWithPlane(
                GetSensor(), pt, GetFrameCenter()[2])

        scr_x, scr_y = vut.GetInverseMatrix(
            pt[1], pt[0], gt, surface)

        radius = 3
        radius_pt = 5
        center = QPoint(scr_x, scr_y)

        pen = QPen(Qt.yellow)
        pen.setWidth(radius)
        pen.setCapStyle(Qt.RoundCap)
        # pen.setDashPattern([1, 4, 5, 4])

        painter.setPen(pen)

        if len(drawLines) > 1:
            try:
                pt = drawLines[idx + 1]
                if hasElevationModel():
                    pt = GetLine3DIntersectionWithPlane(
                        GetSensor(), pt, GetFrameCenter()[2])
                scr_x, scr_y = vut.GetInverseMatrix(
                    pt[1], pt[0], gt, surface)
                end = QPoint(scr_x, scr_y)
                painter.drawLine(center, end)

                # Draw Start/End Points
                pen = QPen(Qt.white)
                pen.setWidth(radius_pt)
                pen.setCapStyle(Qt.RoundCap)
                painter.setPen(pen)
                painter.drawPoint(center)
                painter.drawPoint(end)

            except Exception:
                None
        return
コード例 #12
0
    def drawLinesOnVideo(pt, idx, painter, surface, gt, drawLines):
        ''' Draw Lines on Video '''
        scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface)

        center = QPoint(scr_x, scr_y)

        painter.setPen(LinePen)

        if len(drawLines) > 1:
            try:
                pt = drawLines[idx + 1]
                scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface)
                end = QPoint(scr_x, scr_y)
                painter.drawLine(center, end)

                # Draw Start/End Points
                painter.setPen(DrawToolBar.white_pen)
                painter.drawPoint(center)
                painter.drawPoint(end)
            except Exception:
                None
        return
コード例 #13
0
    def drawPolygonOnVideo(values, painter, surface, gt):
        ''' Draw Polygons on Video '''
        poly = []
        for pt in values:
            scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface)
            center = QPoint(scr_x, scr_y)
            poly.append(center)

        polygon = QPolygonF(poly)

        path = QPainterPath()
        path.addPolygon(polygon)

        painter.setPen(PolyPen)
        painter.drawPolygon(polygon)
        painter.fillPath(path, PolyBrush)
        painter.setPen(DrawToolBar.white_pen)
        painter.drawPoints(polygon)
        return
コード例 #14
0
ファイル: QgsFmvDrawToolBar.py プロジェクト: mhugent/QGISFMV
    def drawPolygonOnVideo(values, painter, surface, gt):
        ''' Draw Polygons on Video '''
        poly = []
        for pt in values:
            if hasElevationModel():
                pt = GetLine3DIntersectionWithPlane(GetSensor(), pt,
                                                    GetFrameCenter()[2])
            scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface)
            center = QPoint(scr_x, scr_y)
            poly.append(center)

        polygon = QPolygonF(poly)

        path = QPainterPath()
        path.addPolygon(polygon)

        painter.setPen(PolyPen)
        painter.drawPolygon(polygon)
        painter.fillPath(path, PolyBrush)
        painter.setPen(DrawToolBar.white_pen)
        painter.drawPoints(polygon)
        return
コード例 #15
0
    def drawPointOnVideo(number, pt, painter, surface, gt):
        ''' Draw Points on Video '''

        scr_x, scr_y = vut.GetInverseMatrix(pt[1], pt[0], gt, surface)

        # don't draw something outside the screen.
        if scr_x < vut.GetXBlackZone(surface) or scr_y < vut.GetYBlackZone(
                surface):
            return

        if scr_x > vut.GetXBlackZone(surface) + vut.GetNormalizedWidth(
                surface) or scr_y > vut.GetYBlackZone(
                    surface) + vut.GetNormalizedHeight(surface):
            return

        center = QPoint(scr_x, scr_y)

        painter.setPen(PointPen)
        painter.drawPoint(center)
        painter.setFont(DrawToolBar.bold_12)
        painter.drawText(center + QPoint(5, -5), str(number))
        return