OSMNX 和真实 GPS 数据。标记与步行区相对应的 GPS 位置

问题描述 投票:0回答:1

我正在使用真实的 GPS 数据(在使用智能手机应用程序进行实验期间收集)。数据集由每个时间步长(每 1 秒)的位置(纬度和经度)组成。

我正在使用 OSMNX 库在地图上绘制轨迹(请参见下面的示例)。

对于给定的个人/轨迹,我想识别那些沿着人行道或绿区运行的 GPS 位置。我知道我可以通过表示轨迹并添加带有“行人区”和“公园”标签的 OSMNX 层来直观地做到这一点,但是有没有办法将 OSMNX 信息与真实数据进行比较,以自动标记每个 GPS 位置,具体取决于是否经过步行区?

这里是我用来表示单个轨迹的代码和带有与步行区和公园相对应的标签的 OpenStreet 地图。

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()

python matplotlib gps openstreetmap osmnx
1个回答
0
投票

解决方案

osmnx 中有一个名为 features_from_point 的功能,它允许我们使用标签来搜索它们是否在距给定点的特定距离内。这可以在循环中使用来搜索和报告每个点。如下

import osmnx as ox
import pandas as pd

coord_list = ['2.0222896712044047, 41.31342875737123',
              '2.020637430467157, 41.31562064060337',
              '2.021967806127375, 41.3168857750397',
              '2.021195329938532, 41.31902113718169',
              '2.0221180098307614, 41.320834125592924'
             ]

results = []

for coord in coord_list:

    tags1 = {"leisure": "park"}
    tags2 = {"highway": "pedestrian", "area": True}

    tag_results = []
    
    gdf1 = ox.features.features_from_place(place, tags1, 5)
    gdf2 = ox.features.features_from_place(place, tags2, 5)

    if gdf1.shape[0] > 0:
        tag_results.append("Park")
        
    if gdf2.shape[0] > 0:
        tag_results.append("Pedestrian Area")
        
    results.append([coord, tag_results])

    
df_results = pd.DataFrame(results, columns=['Coordinate','Tags'])
© www.soinside.com 2019 - 2024. All rights reserved.