-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCanvasMarkers.py
123 lines (98 loc) · 2.87 KB
/
CanvasMarkers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
'''
Video Uav Tracker v 2.0
Replay a video in sync with a gps track displayed on the map.
-------------------
copyright : (C) 2017 by Salvatore Agosta
email : [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
INSTRUCTION:
Synching:
- Create new project
- Select video and gps track (1 trkpt per second)
- Identify first couple Frame/GpsTime and select it.
- Push Synchronize
- Push Start
Replay:
- Move on map
- Create associated DB shapefile
- Add POI with associated video frame saved
- Extract frames with associated coordinates for rapid photogrammetry use
'''
from PyQt5 import QtGui
from qgis.core import *
from qgis.gui import *
class PositionMarker(QgsMapCanvasItem):
""" marker for current GPS position """
def __init__(self, canvas, alpha=255):
QgsMapCanvasItem.__init__(self, canvas)
self.pos = None
self.hasPosition = False
self.d = 20
self.angle = 0
self.setZValue(100) # must be on top
self.alpha=alpha
def newCoords(self, pos):
if self.pos != pos:
self.pos = QgsPointXY(pos) # copy
self.updatePosition()
def setHasPosition(self, has):
if self.hasPosition != has:
self.hasPosition = has
self.update()
def updatePosition(self):
if self.pos:
self.setPos(self.toCanvasCoordinates(self.pos))
self.update()
def paint(self, p, xxx, xxx2):
if not self.pos:
return
path = QtGui.QPainterPath()
path.moveTo(0,-15)
path.lineTo(15,15)
path.lineTo(0,7)
path.lineTo(-15,15)
path.lineTo(0,-15)
# render position with angle
p.save()
p.setRenderHint(QtGui.QPainter.Antialiasing)
if self.hasPosition:
p.setBrush(QtGui.QBrush(QtGui.QColor(0,0,0, self.alpha)))
else:
p.setBrush(QtGui.QBrush(QtGui.QColor(200,200,200, self.alpha)))
p.setPen(QtGui.QColor(255,255,0, self.alpha))
p.rotate(self.angle)
p.drawPath(path)
p.restore()
def boundingRect(self):
return QtCore.QRectF(-self.d,-self.d, self.d*2, self.d*2)
class ReplayPositionMarker(PositionMarker):
def __init__(self, canvas):
PositionMarker.__init__(self, canvas)
def paint(self, p, xxx, xxx2):
if not self.pos:
return
path = QtGui.QPainterPath()
path.moveTo(-10,1)
path.lineTo(10,1)
path.lineTo(10,0)
path.lineTo(1,0)
path.lineTo(1,-5)
path.lineTo(4,-5)
path.lineTo(0,-9)
path.lineTo(-4,-5)
path.lineTo(-1,-5)
path.lineTo(-1,0)
path.lineTo(-10,0)
path.lineTo(-10,1)
# render position with angle
p.save()
p.setRenderHint(QtGui.QPainter.Antialiasing)
p.setBrush(QtGui.QBrush(QtGui.QColor(255,0,0)))
p.setPen(QtGui.QColor(255,255,0))
p.rotate(self.angle)
p.drawPath(path)
p.restore()