Browse Source

improve speed for many points

requesting 5 points at a time
feature/processing_qgs2
Norwin 2 months 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 = [
'foot-walking',
'foot-hiking',
]
POINTS_PER_REQ = 5

def requestFromPoint(client, point, metric, ranges, profile):
"""
@@ -67,9 +68,15 @@ def requestFromPoint(client, point, metric, ranges, profile):
if profile not in ISOCHRONES_PROFILES:
raise InvalidParameterException('profile', profile, ISOCHRONES_PROFILES)

if isinstance(point, list):
locations = [(p.x(), p.y()) for p in point]
else:
# locations = [(point.x(), point.y())]
locations = [point.x(), point.y()]

params = {
# altough the parameter is called locations, it only supports one point..
'locations': _build_coords([point.x(), point.y()]),
'locations': _build_coords(locations),
'profile': profile,
'range': _comma_list(ranges),
'range_type': metric,
@@ -117,7 +124,7 @@ def layerFromRequests(responses, layer=None):

:rtype: QgsVectorLayer
"""
if not len(responses):
raise ApiError("no results!")


+ 7
- 7
osmtools_processing/isochrones.py View File

@@ -52,6 +52,7 @@ from OSMtools.core.client import Client
from OSMtools.core.isochrones import (
ISOCHRONES_METRICS,
ISOCHRONES_PROFILES,
POINTS_PER_REQ,
requestFromPoint,
layerFromRequests,
_stylePoly
@@ -128,16 +129,15 @@ class IsochronesGeoAlg(GeoAlgorithm):

progress.setInfo('Processing each selected point')
responses = []
POINTS_REQ = 5
pointsInReq = 0
points = []
for feature in features(pointLayer):

# TODO: run 5 points per request!

feature.geometry().transform(transformer)
point = feature.geometry().asPoint()
points.append(feature.geometry().asPoint())

responses.append(requestFromPoint(client, point, metric, ranges, profile))
# run 5 points per request
if len(points) == POINTS_PER_REQ:
responses.append(requestFromPoint(client, points, metric, ranges, profile))
points = []

processedFeatureCount += 1
progress.setPercentage(int(processedFeatureCount * totalFeatureCount))

+ 1
- 0
osmtools_processing/isochrones_join.py View File

@@ -50,6 +50,7 @@ from OSMtools.core.client import Client
from OSMtools.core.isochrones import (
ISOCHRONES_METRICS,
ISOCHRONES_PROFILES,
POINTS_PER_REQ,
requestFromPoint,
featuresFromResponses,
_stylePoly

Loading…
Cancel
Save