Browse Source

improve speed for many points

requesting 5 points at a time
feature/processing_qgs2
Norwin Roosen 1 week ago
parent
commit
90ce4594e4
3 changed files with 17 additions and 9 deletions
  1. 9
    2
      core/isochrones.py
  2. 7
    7
      osmtools_processing/isochrones.py
  3. 1
    0
      osmtools_processing/isochrones_join.py

+ 9
- 2
core/isochrones.py View File

@@ -36,6 +36,7 @@ ISOCHRONES_PROFILES = [
36 36
     'foot-walking',
37 37
     'foot-hiking',
38 38
 ]
39
+POINTS_PER_REQ = 5
39 40
 
40 41
 def requestFromPoint(client, point, metric, ranges, profile):
41 42
     """
@@ -67,9 +68,15 @@ def requestFromPoint(client, point, metric, ranges, profile):
67 68
     if profile not in ISOCHRONES_PROFILES:
68 69
         raise InvalidParameterException('profile', profile, ISOCHRONES_PROFILES)
69 70
 
71
+    if isinstance(point, list):
72
+        locations = [(p.x(), p.y()) for p in point]
73
+    else:
74
+        # locations = [(point.x(), point.y())]
75
+        locations = [point.x(), point.y()]
76
+
70 77
     params = {
71 78
         # altough the parameter is called locations, it only supports one point..
72
-        'locations': _build_coords([point.x(), point.y()]),
79
+        'locations': _build_coords(locations),
73 80
         'profile': profile,
74 81
         'range': _comma_list(ranges),
75 82
         'range_type': metric,
@@ -117,7 +124,7 @@ def layerFromRequests(responses, layer=None):
117 124
 
118 125
     :rtype: QgsVectorLayer
119 126
     """
120
-    
127
+
121 128
     if not len(responses):
122 129
         raise ApiError("no results!")
123 130
 

+ 7
- 7
osmtools_processing/isochrones.py View File

@@ -52,6 +52,7 @@ from OSMtools.core.client import Client
52 52
 from OSMtools.core.isochrones import (
53 53
     ISOCHRONES_METRICS,
54 54
     ISOCHRONES_PROFILES,
55
+    POINTS_PER_REQ,
55 56
     requestFromPoint,
56 57
     layerFromRequests,
57 58
     _stylePoly
@@ -128,16 +129,15 @@ class IsochronesGeoAlg(GeoAlgorithm):
128 129
 
129 130
         progress.setInfo('Processing each selected point')
130 131
         responses = []
131
-        POINTS_REQ = 5
132
-        pointsInReq = 0
132
+        points = []
133 133
         for feature in features(pointLayer):
134
-
135
-            # TODO: run 5 points per request!
136
-
137 134
             feature.geometry().transform(transformer)
138
-            point = feature.geometry().asPoint()
135
+            points.append(feature.geometry().asPoint())
139 136
 
140
-            responses.append(requestFromPoint(client, point, metric, ranges, profile))
137
+            # run 5 points per request
138
+            if len(points) == POINTS_PER_REQ:
139
+                responses.append(requestFromPoint(client, points, metric, ranges, profile))
140
+                points = []
141 141
 
142 142
             processedFeatureCount += 1
143 143
             progress.setPercentage(int(processedFeatureCount * totalFeatureCount))

+ 1
- 0
osmtools_processing/isochrones_join.py View File

@@ -50,6 +50,7 @@ from OSMtools.core.client import Client
50 50
 from OSMtools.core.isochrones import (
51 51
     ISOCHRONES_METRICS,
52 52
     ISOCHRONES_PROFILES,
53
+    POINTS_PER_REQ,
53 54
     requestFromPoint,
54 55
     featuresFromResponses,
55 56
     _stylePoly

Loading…
Cancel
Save