Saturday, 9 September 2023

OSMNX and real GPS data. Label GPS locations corresponding to pedestrian areas

I am working with real GPS data (collected during an experiment with a smartphone app). The data-set is composed by the locations (latitude and longitude) at each time-step (every 1 second).

I'm using the OSMNX library to plot the trajectories on maps (see example below).

For a given individual/trajectory, I would like to identify those GPS locations that run along a pedestrian walkway or green zone. I know I can do it visually by representing the trajectory and adding the OSMNX layer with the tags "pedestrian area" and "park", but is there any way to confront the OSMNX information with the real data to automatically tag each GPS location depending on whether it goes through a pedestrian area or not?

Here the code I used to represent a single trajectory and the OpenStreet Map with the tags corresponding to pedestrian areas and parks.

import networkx as nx
import osmnx as ox
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import glob
import os
import osrm

#%matplotlib inline
ox.config(log_console=True)
ox.__version__

# Create the graph with a given GPS coordenates.
G = ox.graph_from_point((41.31367857092018, 2.0233411472684057), dist=1000, network_type='walk')

# Plot the OSM graph together with the real GPS trajectory
fig, ax = ox.plot_graph(G, show=False, close=False)

df = pd.read_csv('2018-11-05_sgv_0101_PEU.csv')  # read the GPS data

# Get the parks (in green) and the pedestrian areas (in purple)
place = "Viladecans, Baix Llobregat"   
tags = {"leisure": "park"}
tags2 = {"highway": "pedestrian", "area": True}
gdf = ox.geometries_from_place(place, tags)
gdf2 = ox.geometries_from_place(place, tags2)
gdf.shape
gdf2.shape
gdf.plot(ax=ax,color='darkgreen')
gdf2.plot(ax=ax,color='purple')

ax.scatter(2.0233411472684057,41.31367857092018, marker='*', c='yellow', s=200)
ax.scatter(df['longitude'],df['latitude'], c='red', s=1)

plt.show()

output MAP



from OSMNX and real GPS data. Label GPS locations corresponding to pedestrian areas

No comments:

Post a Comment