matplotlib OSMNX和真实的GPS数据,标记与行人区域对应的GPS位置

cl25kdpy  于 2023-10-24  发布在  其他
关注(0)|答案(1)|浏览(109)

我正在使用真实的GPS数据(在智能手机应用程序的实验中收集)。数据集由每个时间步(每1秒)的位置(纬度和经度)组成。
我使用OSMNX库在Map上绘制轨迹(参见下面的示例)。
对于给定的个人/轨迹,我想识别那些沿着人行道或绿色区域运行的GPS位置。我知道我可以通过表示轨迹并添加带有标记“行人区域”和“公园”的OSMNX层来可视化地完成,但是,有没有办法将OSMNX信息与真实的数据进行对比,从而根据每个GPS位置是否经过行人区来自动标记该位置还是没有
这里的代码我用来表示一个单一的轨迹和OpenStreetMap与标签对应的步行区和公园。

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

w51jfk4q

w51jfk4q1#

解决方案

在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'])

相关问题