Issues with Repeated Nearest Nodes in GPS Data Interpolation Using NetworkX and OSMnx

23 Views Asked by At

I am working on a project that involves interpolating GPS points using the OpenStreetMap (OSM) data with NetworkX and OSMnx in Python. The goal is to interpolate additional GPS points if the distance between two consecutive points is greater than 20 meters. However, I've encountered a problem where the nearest nodes identified for each GPS point are repeatedly the same, which seems abnormal.

user_file_path = 'C:/..../gps_data_stackoverflow.xlsx'  # Replace with your file path
user_data = pd.read_excel(user_file_path)
north = user_data['Latitude'].max()
south = user_data['Latitude'].min()
east = user_data['Longitude'].max()
west = user_data['Longitude'].min()

# Create the graph from the bounding box
G = ox.graph_from_bbox(bbox=(north, south, east, west), network_type='all')
ox.plot_graph(G)

# Convert your GPS data to a GeoDataFrame
gdf_user_data = gpd.GeoDataFrame(user_data, geometry=gpd.points_from_xy(user_data.Longitude, user_data.Latitude))
# Find the nearest node in the graph for each point
nearest_nodes = []
for point in tqdm.tqdm(gdf_user_data.geometry, desc="Processing points"):
    nearest_node = ox.distance.nearest_nodes(G, point.x, point.y)
    nearest_nodes.append(nearest_node)
user_data['nearest_nodes'] = nearest_nodes

Is this repetition of nearest nodes indicative of an issue with the GPS data, the graph generated from OSM data, or the method used to calculate the nearest nodes?

Expected Behavior: I expected to see a list of distinct nearest nodes corresponding to each GPS point's geographical location, allowing for accurate interpolation of points along the paths.

A small Dataset:

timestamsp Latitude Longitude
1/16/2024 1:42:38 PM -1.320816 36.735867
1/16/2024 1:42:39 PM -1.321233 36.736233
1/16/2024 1:42:42 PM -1.321666 36.73665
1/16/2024 1:42:43 PM -1.322116 36.737083
1/16/2024 1:42:46 PM -1.322566 36.737633
0

There are 0 best solutions below