Skip to content

Node ids rounded off in v6.0.0 in map matching and output is also in floatΒ #7271

@mohit-at-delhivery

Description

@mohit-at-delhivery

Issue

When i created the docker image using v6.0.0 and then tried the following map matching code then i am getting osm nodes in floating point and these are not even in India even though my pbf file is of India.

import requests 
import json

def get_osrm_match(geo_coords, port_number=5000):
    """
    Matches given GPS coordinates to the nearest roads using OSRM map matching.

    Args:
        geo_coords (list of tuples): A list of coordinates (latitude, longitude, timestamp).
        port_number (int, optional): The OSRM server port number. Defaults to 5000.

    Returns:
        tuple: 
            - decoded_geometry (list of tuples): Route geometry as a list of (lat, lon).
            - matched_geometry (list of tuples): Final matched coordinates to the corresponding geo coords.
            - snap_distance (float): Total distance (in meters) between the original and matched points.
            - location_type_list (list of dicts): Detailed information about each tracepoint and OSM node in the matched trace.
    """

    # Construct OSRM request URL and parameters
    osrm_route_url = f"http://127.0.0.1:{port_number}/match/v1/driving/"
    map_matching_radius = 20

    # Format the coordinates for the OSRM request
    loc = ';'.join([f"{coord[1]},{coord[0]}" for coord in geo_coords])
    radii = ';'.join([str(map_matching_radius)] * len(geo_coords))

    # Build the final request URL
    url = (f"{osrm_route_url}{loc}?overview=full&radiuses={radii}"
           "&generate_hints=false&skip_waypoints=false&gaps=ignore"
           "&geometries=geojson&annotations=nodes")

    try:
        # Send the GET request to the OSRM server
        request_output = requests.get(url)
    except Exception:
        return None, None, None, None  # Return empty results on failure

    # Check if the request was successful
    if request_output.status_code != 200:
        return None, None, None, None

    # Parse the response from the OSRM server
    response = request_output.json()

    return response


geo_coords = geo_coords = [[28.609423, 77.045058, 1759296437014.0], [28.609437, 77.0449, 1759296555105.0]]

response = get_osrm_match(geo_coords, port_number=5000)

print(json.dumps(response, indent=4))

Output using v6.0.0 (stable since last 7 months):


{
    "code": "Ok",
    "matchings": [
        {
            "confidence": 2.097487991e-05,
            "legs": [
                {
                    "distance": 20.2,
                    "annotation": {
                        "nodes": [
                            7232674578,
                            12252920890.0,
                            9918335465
                        ]
                    },
                    "duration": 3,
                    "summary": "",
                    "weight": 3,
                    "steps": []
                }
            ],
            "weight_name": "routability",
            "geometry": {
                "coordinates": [
                    [
                        77.044764,
                        28.609622
                    ],
                    [
                        77.044764,
                        28.609622
                    ],
                    [
                        77.044759,
                        28.60944
                    ]
                ],
                "type": "LineString"
            },
            "weight": 3,
            "duration": 3,
            "distance": 20.2
        }
    ],
    "tracepoints": [
        {
            "waypoint_index": 0,
            "matchings_index": 0,
            "name": "",
            "alternatives_count": 4,
            "location": [
                77.044764,
                28.609622
            ],
            "distance": 36.23505615
        },
        {
            "waypoint_index": 1,
            "matchings_index": 0,
            "name": "",
            "alternatives_count": 7,
            "location": [
                77.044759,
                28.60944
            ],
            "distance": 13.79218809
        }
    ]
}

output using v5.27.1 (stable since last 3 years):

{
    "code": "Ok",
    "matchings": [
        {
            "confidence": 2.097487991,
            "geometry": {
                "coordinates": [
                    [
                        77.044764,
                        28.609622
                    ],
                    [
                        77.044764,
                        28.609622
                    ],
                    [
                        77.044759,
                        28.60944
                    ]
                ],
                "type": "LineString"
            },
            "legs": [
                {
                    "steps": [],
                    "summary": "",
                    "weight": 3,
                    "duration": 3,
                    "annotation": {
                        "nodes": [
                            7232674578,
                            12252920893,
                            9918335465
                        ]
                    },
                    "distance": 20.2
                }
            ],
            "weight_name": "routability",
            "weight": 3,
            "duration": 3,
            "distance": 20.2
        }
    ],
    "tracepoints": [
        {
            "alternatives_count": 4,
            "waypoint_index": 0,
            "matchings_index": 0,
            "distance": 36.235056148,
            "name": "",
            "location": [
                77.044764,
                28.609622
            ]
        },
        {
            "alternatives_count": 7,
            "waypoint_index": 1,
            "matchings_index": 0,
            "distance": 13.792188086,
            "name": "",
            "location": [
                77.044759,
                28.60944
            ]
        }
    ]
}

As you can see the ouptut "12252920890.0," in v6.0.0 is not a valid osm node and even without float if you check it without floating part its some node in US (Link)

The thing is the correct node is "12252920893" from v5.27.1 and it has been rounded off in v6.0.0 i guess "12252920890.0" like 3 units difference right?

I have also attached the osrm setup script here.
start_osrm_docker.sh

So please tell me what is the issue and how can i fix it? Or should i use the older v5.27.1 only?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions