Check for some issues like empty input, recoverable exceptions, etc

This commit is contained in:
Mario de Frutos
2016-03-22 15:19:03 +01:00
parent 4061009df0
commit 357458f44d
6 changed files with 21 additions and 9 deletions

View File

@@ -10,7 +10,11 @@ def polyline_to_linestring(polyline):
coordinates.append("%s %s" % (point[1]/10, point[0]/10))
wkt_coordinates = ','.join(coordinates)
sql = "SELECT ST_GeomFromText('LINESTRING({0})', 4326) as geom".format(wkt_coordinates)
geometry = plpy.execute(sql, 1)[0]['geom']
try:
sql = "SELECT ST_GeomFromText('LINESTRING({0})', 4326) as geom".format(wkt_coordinates)
geometry = plpy.execute(sql, 1)[0]['geom']
except BaseException as e:
plpy.warning("Can't generate LINESTRING from polyline: {0}".format(e))
geometry = None
return geometry

View File

@@ -17,3 +17,5 @@ class Coordinate:
def to_json(self):
return "{{\"lon\": {0},\"lat\": {1}}}".format(self._longitude,
self._latitude)
def __str__(self):
return "{0}, {1}".format(self._longitude, self._latitude)

View File

@@ -11,14 +11,11 @@ class PolyLine:
for chunk in chunks:
coordinate = self._process_chunk(chunk)
coordinate /= 1e5
print coordinate
if len(coordinates) > 1:
# We have to sum the previous with the offset in this chunk
coordinate += coordinates[-2]
coordinates.append(round(coordinate, 5))
print coordinates
return zip(coordinates, coordinates[1:])[::2]
def _extract_chunks(self, data):

View File

@@ -10,7 +10,7 @@ from setuptools import setup, find_packages
setup(
name='cartodb_services',
version='0.3.2',
version='0.3.3',
description='CartoDB Services API Python Library',

View File

@@ -132,7 +132,6 @@ class HereMapsRoutingIsolineTestCase(unittest.TestCase):
HereMapsRoutingIsoline.ISOLINE_PATH)
def test_calculate_isodistance_with_valid_params(self, req_mock):
print self.isoline_url
url = "{0}?start=geo%2133.0%2C1.0&mode=shortest%3Bcar".format(self.isoline_url)
req_mock.register_uri('GET', url, text=self.GOOD_RESPONSE)
response = self.routing.calculate_isodistance('geo!33.0,1.0', 'car',