ustroetz / python-osrm

A Python wrapper around the OSRM API
MIT License
133 stars 55 forks source link

Problem with routing table and coordinates #13

Closed TRomijn closed 6 years ago

TRomijn commented 6 years ago

In version 0.11.1 I think there is a mistake in the way the routes for the routing table are calculated.

Either the Point object or the osrm.table function swaps the latitudes and longitudes. The workaround to get good results now is to create Point objects with swapped latitudes and longitudes.

You can test it with:

import osrm
import pandas as pd
from osrm import Point

# Coordinates for latitude and longitude are swapped.
# Amsterdam: longitude: 4.899431, Latitude: 52.379189 .
# Delft: Longitude: 4.3570677, Latitude: 52.0115769
ams = Point(longitude=52.370216, latitude= 4.895168)
delft = Point(longitude= 52.0115769,latitude= 4.3570677)

list_coord = [ams, delft]

list_id = ['Ams', 'Delft']

osrm.RequestConfig.host = osrm.RequestConfig.host = "router.project-osrm.org"

time_matrix, snapped_coords, a = osrm.table(
    list_coord, ids_origin=list_id, output='dataframe')

time_matrix
mthh commented 6 years ago

I think the problem lies in the use of our namedtuple Point and the fact we are using the 0 index to get the longitude and the 1 index to get latitude on the given coordinates.
See below :

In [41]: coord = (13.3888, 52.517033) # (longitude, latitude)

In [42]: coord[0] # longitude
Out[42]: 13.3888

In [43]: coord_Point1 = Point(13.3888, 52.517033)

In [44]: coord_Point1[0] # longitude
Out[44]: 13.3888

In [45]: coord_Point2 = Point(longitude=13.3888, latitude=52.517033)

In [46]: coord_Point2[0] # Not the longitude!
Out[46]: 52.517033

I will submit a PR to fix it.