Skip to content

Commit c0b0dda

Browse files
committed
Add ClipTrajectoriesByExtentAlgorithm
1 parent c58d73d commit c0b0dda

File tree

5 files changed

+92
-316
lines changed

5 files changed

+92
-316
lines changed

qgis_processing/clipTrajectoriesByExtentAlgorithm.py

Lines changed: 0 additions & 165 deletions
This file was deleted.

qgis_processing/createTrajectoriesAlgorithm.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818

1919
class CreateTrajectoriesAlgorithm(TrajectoriesAlgorithm):
20-
SPEED_UNIT = "SPEED_UNIT"
2120

2221
def __init__(self):
2322
super().__init__()

qgis_processing/overlayAlgorithm.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import os
2+
import sys
3+
4+
import shapely.wkt
5+
from shapely.geometry import Polygon
6+
7+
from qgis.PyQt.QtCore import QCoreApplication, QVariant
8+
from qgis.PyQt.QtGui import QIcon
9+
from qgis.core import (
10+
QgsField,
11+
QgsFields,
12+
QgsGeometry,
13+
QgsFeature,
14+
QgsFeatureSink,
15+
QgsFeatureRequest,
16+
QgsProcessing,
17+
QgsProcessingAlgorithm,
18+
QgsProcessingParameterFeatureSource,
19+
QgsProcessingParameterString,
20+
QgsProcessingParameterExtent,
21+
QgsProcessingParameterField,
22+
QgsProcessingParameterNumber,
23+
QgsProcessingParameterBoolean,
24+
QgsProcessingParameterFeatureSink,
25+
QgsProcessingParameterEnum,
26+
QgsWkbTypes,
27+
)
28+
29+
sys.path.append("..")
30+
31+
from .qgisUtils import tc_to_sink, traj_to_sink
32+
from .trajectoriesAlgorithm import TrajectoriesAlgorithm
33+
34+
35+
class ClipTrajectoriesByExtentAlgorithm(TrajectoriesAlgorithm):
36+
EXTENT = "EXTENT"
37+
38+
def __init__(self):
39+
super().__init__()
40+
41+
def initAlgorithm(self, config=None):
42+
super().initAlgorithm(config)
43+
self.addParameter(
44+
QgsProcessingParameterExtent(
45+
name=self.EXTENT, description=self.tr("Extent"), optional=False
46+
)
47+
)
48+
49+
def name(self):
50+
return "clip_traj_extent"
51+
52+
def tr(self, text):
53+
return QCoreApplication.translate("clip_traj_extent", text)
54+
55+
def displayName(self):
56+
return self.tr("Clip trajectories by extent")
57+
58+
def group(self):
59+
return self.tr("Overlay")
60+
61+
def groupId(self):
62+
return "TrajectoryOverlay"
63+
64+
def shortHelpString(self):
65+
return self.tr(
66+
"<p>Creates a trajectory point layers with speed and direction information "
67+
"as well as a trajectory line layer clipped by the specified extent.</p>"
68+
"<p><b>Speed</b> is calculated based on the input layer CRS information and "
69+
"converted to the desired speed units. For more info on the supported units, "
70+
"see https://movingpandas.org/units</p>"
71+
"<p><b>Direction</b> is calculated between consecutive locations. Direction "
72+
"values are in degrees, starting North turning clockwise.</p>"
73+
)
74+
75+
def helpUrl(self):
76+
return "https://movingpandas.org/units"
77+
78+
def createInstance(self):
79+
return type(self)()
80+
81+
def processTc(self, tc, parameters, context):
82+
extent = self.parameterAsExtent(parameters, self.EXTENT, context)
83+
extent = shapely.wkt.loads(extent.asWktPolygon())
84+
tc = tc.clip(extent)
85+
tc_to_sink(tc, self.sink_pts, self.fields_pts, self.timestamp_field)
86+
for split in tc:
87+
traj_to_sink(split, self.sink_trajs)
88+
89+

0 commit comments

Comments
 (0)