def test_nearest(self, mock_urlopen): mock_urlopen.return_value = MockReadable( u"""{"waypoints":[{"distance":22064.816067,"hint":"YtOXh5LYdIgAAAAAAAAAAH0FAAAAAAAA-1IAAD2o_wUlqP8FbrcAAC6OdgIrck4BEL95AngUTwEAAAEBfDhq3w==","name":"","location":[41.324078,21.918251]}],"code":"Ok"}""" ) result = osrm.nearest((41.5332, 21.9598)) # nearest only return the parsed JSON response self.assertEqual(result["waypoints"][0]["distance"], 22064.816067)
def test_non_existing_host(self): Profile = osrm.RequestConfig("localhost/v1/flying") self.assertEqual(Profile.host, "localhost") with self.assertRaises(URLError): osrm.nearest((12.36, 45.36), url_config=Profile) with self.assertRaises(URLError): osrm.trip([(13.38886, 52.51703), (10.00, 53.55), (52.374444, 9.738611)], url_config=Profile) with self.assertRaises(URLError): osrm.simple_route((13.38886, 52.51703), (10.00, 53.55), url_config=Profile) with self.assertRaises(URLError): osrm.AccessIsochrone((13.38886, 52.51703), points_grid=100, url_config=Profile) with self.assertRaises(URLError): osrm.match([(10.00, 53.55), (52.374444, 9.738611)], url_config=Profile) with self.assertRaises(URLError): osrm.table([(10.00, 53.55), (52.374444, 9.738611)], [(10.00, 53.55), (52.374444, 9.738611)], url_config=Profile)
def test_non_existing_host(self): Profile = osrm.RequestConfig("localhost/v1/flying") self.assertEqual(Profile.host, "localhost") with self.assertRaises(URLError): osrm.nearest((12.36, 45.36), url_config=Profile) with self.assertRaises(URLError): osrm.trip( [(13.38886, 52.51703), (10.00, 53.55), (52.374444, 9.738611)], url_config=Profile) with self.assertRaises(URLError): osrm.simple_route( (13.38886, 52.51703), (10.00, 53.55), url_config=Profile) with self.assertRaises(URLError): osrm.AccessIsochrone( (13.38886, 52.51703), points_grid=100, url_config=Profile) with self.assertRaises(URLError): osrm.match( [(10.00, 53.55), (52.374444, 9.738611)], url_config=Profile) with self.assertRaises(URLError): osrm.table( [(10.00, 53.55), (52.374444, 9.738611)], [(10.00, 53.55), (52.374444, 9.738611)], url_config=Profile)
def Snap2Road(df): longitude_2snap = df.longitude.tolist() latitude_2snap = df.latitude.tolist() snapped_output = df.latitude.tolist() for i in range(0, len(latitude_2snap)): snapped_result = osrm.nearest((longitude_2snap[i], latitude_2snap[i])) snapped_output[i] = tuple([ snapped_result['waypoints'][0]['location'][0], snapped_result['waypoints'][0]['location'][1] ]) df['snap_pos'] = snapped_output return df