Skip to content

Commit

Permalink
qgis: add LayerToTrack method
Browse files Browse the repository at this point in the history
  • Loading branch information
mdvandamme committed Oct 11, 2024
1 parent 3d38fee commit e821dbe
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions tracklib/util/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
knowledge of the CeCILL-C license and that you accept its terms.
"""

from tracklib import Track, TrackCollection
from tracklib import Track, TrackCollection, ENUCoords, ObsTime, Obs

try:
from qgis.PyQt.QtCore import QVariant
from qgis.core import QgsProject, QgsVectorLayer, QgsField
from qgis.core import QgsPointXY, QgsFeature, QgsGeometry
from qgis.core import QgsPointXY, QgsFeature, QgsGeometry, QgsWkbTypes
from qgis.core import QgsMarkerSymbol, QgsLineSymbol, QgsSimpleLineSymbolLayer
#from qgis.core import QgsFillSymbol
from PyQt5.QtGui import QColor
Expand Down Expand Up @@ -465,6 +465,31 @@ def plotMatching(matching, track2, af_name="pair", NO_DATA_VALUE:int=-1):

QgsProject.instance().addMapLayer(layerMatching)

@staticmethod
def layerToTrack(layer):
track = Track()

if layer.wkbType() == QgsWkbTypes.Point:
for f in layer.getFeatures():
pt = f.geometry().asPoint()
time = ObsTime()
E = pt.x()
N = pt.y()
point = Obs(ENUCoords(E, N, 0), time)
track.addObs(point)

if layer.wkbType() == QgsWkbTypes.LineString:
for f in layer.getFeatures():
ligne = f.geometry()
for vertex in ligne.vertices():
time = ObsTime()
E = vertex.x()
N = vertex.y()
point = Obs(ENUCoords(E, N, 0), time)
track.addObs(point)

return track


'''
# SpatialIndex
Expand Down

0 comments on commit e821dbe

Please sign in to comment.