From bc4c9fea33dd4c39e89f3676c3a63268c65ce279 Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 26 Feb 2018 12:45:08 +0100 Subject: [PATCH 1/4] Using Mapbox returned destinations as coordinates for isolines --- .../cartodb_services/mapbox/isolines.py | 24 +++++++++++++------ .../cartodb_services/mapbox/matrix_client.py | 2 ++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py index e7f06c1..b837a3b 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py @@ -4,6 +4,7 @@ Uses the Mapbox Time Matrix service. ''' import json +from cartodb_services.tools import Coordinate from cartodb_services.tools.spherical import (get_angles, calculate_dest_location) from cartodb_services.mapbox.matrix_client import (validate_profile, @@ -11,7 +12,9 @@ from cartodb_services.mapbox.matrix_client import (validate_profile, PROFILE_WALKING, PROFILE_DRIVING, PROFILE_CYCLING, - ENTRY_DURATIONS) + ENTRY_DURATIONS, + ENTRY_DESTINATIONS, + ENTRY_LOCATION) MAX_SPEEDS = { PROFILE_WALKING: 3.3333333, # In m/s, assuming 12km/h walking speed @@ -53,6 +56,7 @@ class MapboxIsolines(): return [] costs = [None] * number_of_angles + destinations = [None] * number_of_angles for idx, cost in enumerate(json_response[ENTRY_DURATIONS][0][1:]): if cost: @@ -60,7 +64,11 @@ class MapboxIsolines(): else: costs[idx] = isorange - return costs + for idx, destination in enumerate(json_response[ENTRY_DESTINATIONS][1:]): + destinations[idx] = Coordinate(destination[ENTRY_LOCATION][0], + destination[ENTRY_LOCATION][1]) + + return costs, destinations def calculate_isochrone(self, origin, time_ranges, profile=DEFAULT_PROFILE): @@ -122,10 +130,12 @@ class MapboxIsolines(): # NOTE: sometimes it cannot calculate the cost and returns None. # Just assume isorange and stop the calculations there - costs = cost_method(origin=origin, targets=location_estimates, - isorange=isorange, profile=profile, - unit_factor=unit_factor, - number_of_angles=number_of_angles) + costs, destinations = cost_method(origin=origin, + targets=location_estimates, + isorange=isorange, + profile=profile, + unit_factor=unit_factor, + number_of_angles=number_of_angles) if not costs: continue @@ -153,7 +163,7 @@ class MapboxIsolines(): location_estimates_filtered = [] for i, c in enumerate(costs): if c != isorange: - location_estimates_filtered.append(location_estimates[i]) + location_estimates_filtered.append(destinations[i]) return location_estimates_filtered diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/matrix_client.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/matrix_client.py index 8d547b6..fd4cf1f 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/matrix_client.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/matrix_client.py @@ -30,6 +30,8 @@ VALID_PROFILES = [PROFILE_DRIVING_TRAFFIC, PROFILE_WALKING] ENTRY_DURATIONS = 'durations' +ENTRY_DESTINATIONS = 'destinations' +ENTRY_LOCATION = 'location' def validate_profile(profile): From 9fb04fdc241618523e1dc4991b2c324f3b6ef105 Mon Sep 17 00:00:00 2001 From: Antonio Date: Wed, 28 Feb 2018 11:49:23 +0100 Subject: [PATCH 2/4] Version bumped --- NEWS.md | 5 +++++ server/lib/python/cartodb_services/setup.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 036318d..53c6bab 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,9 @@ +February 22th, 2018 +================== +* Version `0.17.2` of the python library + * Fix bug with Mapbox isolines not stopping at the seacoast + February 27th, 2018 ================== * Version `0.17.1` of the python library diff --git a/server/lib/python/cartodb_services/setup.py b/server/lib/python/cartodb_services/setup.py index 95a2c16..c1c5893 100644 --- a/server/lib/python/cartodb_services/setup.py +++ b/server/lib/python/cartodb_services/setup.py @@ -10,7 +10,7 @@ from setuptools import setup, find_packages setup( name='cartodb_services', - version='0.17.1', + version='0.17.2', description='CartoDB Services API Python Library', From 4308b5f351aef2339a2166a12b02ecc74e58d1d7 Mon Sep 17 00:00:00 2001 From: Antonio Date: Fri, 2 Mar 2018 10:23:58 +0100 Subject: [PATCH 3/4] Remove too far away points (filtering by time) --- .../python/cartodb_services/cartodb_services/mapbox/isolines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py index b837a3b..9c1eb07 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py @@ -162,7 +162,7 @@ class MapboxIsolines(): # delete points that got None location_estimates_filtered = [] for i, c in enumerate(costs): - if c != isorange: + if c < isorange * (1 + tolerance): location_estimates_filtered.append(destinations[i]) return location_estimates_filtered From 35f743164e6c01c7a10fa77baeed1f7379fc2a2e Mon Sep 17 00:00:00 2001 From: Antonio Date: Fri, 2 Mar 2018 10:27:37 +0100 Subject: [PATCH 4/4] Keep deleting points that got None --- .../python/cartodb_services/cartodb_services/mapbox/isolines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py index 9c1eb07..4d6563f 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/isolines.py @@ -162,7 +162,7 @@ class MapboxIsolines(): # delete points that got None location_estimates_filtered = [] for i, c in enumerate(costs): - if c < isorange * (1 + tolerance): + if c != isorange and c < isorange * (1 + tolerance): location_estimates_filtered.append(destinations[i]) return location_estimates_filtered