Solved data conversion issues

This commit is contained in:
Antonio
2018-01-03 14:14:25 +01:00
parent 941af522ae
commit 801c5a3cee
7 changed files with 85 additions and 13 deletions

View File

@@ -92,7 +92,7 @@ class MapboxIsolines():
return self.calculate_isochrone(origin=origin,
time_ranges=[time_range],
profile=profile)
profile=profile)[0].coordinates
def calculate_isoline(self, origin, isorange, upper_rmax,
cost_method=_calculate_matrix_cost,

View File

@@ -0,0 +1,4 @@
MODE_TO_MAPBOX_PROFILE = {
'car': 'driving',
'walk': 'walking',
}

View File

@@ -0,0 +1,19 @@
import plpy
def country_to_iso3(country):
""" Convert country to its iso3 code """
if not country:
return None
try:
country_plan = plpy.prepare("SELECT adm0_a3 as iso3 FROM admin0_synonyms WHERE lower(regexp_replace($1, " \
"'[^a-zA-Z\u00C0-\u00ff]+', '', 'g'))::text = name_; ", ['text'])
country_result = plpy.execute(country_plan, [country], 1)
if country_result:
return country_result[0]['iso3']
else:
return None
except BaseException as e:
plpy.warning("Can't get the iso3 code from {0}: {1}".format(country, e))
return None

View File

@@ -24,3 +24,8 @@ class MapboxGeocoderTestCase(unittest.TestCase):
self.assertEqual(place[0], WELL_KNOWN_LONGITUDE)
self.assertEqual(place[1], WELL_KNOWN_LATITUDE)
def test_valid_request_namedplace(self):
place = self.geocoder.geocode(searchtext='Barcelona')
assert place