【问题标题】:data analysis using gps coordinates使用 gps 坐标进行数据分析
【发布时间】:2021-10-13 21:52:25
【问题描述】:

我有这种数据,包含时间戳、经度、纬度和tripId,

我是否可以仅从这些数据中找到交叉路口的等待时间,或者我需要其他什么? 我可以从这些数据中获得哪些信息?

"时间戳","tripId","经度","纬度" "2021-07-05 10:35:04","1866491","8.167035","53.160473" "2021-07-05 10:35:03","1866491","8.167023","53.160469" "2021-07-05 10:35:02","1866491","8.167007","53.160459" "2021-07-05 10:35:01","1866491","8.166987","53.160455" "2021-07-05 10:35:00","1866491","8.166956","53.160448" "2021-07-05 10:34:20","1866491","8.167286","53.15919" "2021-07-05 10:34:19","1866491","8.167328","53.15918" "2021-07-05 10:34:18","1866491","8.16735","53.159165" "2021-07-05 10:34:17","1866491","8.167371","53.159148" "2021-07-05 10:34:16","1866491","8.167388","53.159124" "2021-07-05 10:34:15","1866491","8.167399","53.159105" "2021-06-30 20:25:30","1862861","8.211288","53.150848" "2021-06-30 20:25:29","1862861","8.211264","53.150851" "2021-06-30 20:25:28","1862861","8.211269","53.150842" "2021-06-30 20:25:27","1862861","8.211273","53.150836" "2021-06-30 20:25:26","1862861","8.211279","53.150836" "2021-06-30 20:25:25","1862861","8.211259","53.150848" "2021-06-30 20:25:24","1862861","8.211263","53.15085" "2021-06-30 20:25:21","1862861","8.211455","53.150782" "2021-06-30 20:25:20","1862861","8.211453","53.150786" "2021-06-30 20:25:19","1862861","8.211449","53.150792"

【问题讨论】:

    标签: python jupyter-notebook gps data-analysis analysis


    【解决方案1】:

    回答这个问题:

    我可以从这种数据中得到哪些信息

    您有一个timestamp、一个tripId 和一个坐标(longitudelatitude)。

    因此,您知道该人或车辆在其行程18664912021-07-05 10:35:01 期间位于8.166987 / 53.160455 位置。此外,您还可以计算行程持续时间

    您还可以通过按时间戳顺序连接行程的所有坐标来创建线。然后,您可以找出这些行程彼此相交的位置

    根据线要素,您可以计算它们的长度(行程距离)。连同行程的持续时间,您还可以计算平均步行或驾驶速度

    (您的示例数据没有相互交叉的行程。我不确定您所说的等待时间是什么意思。)


    下面的示例脚本如何将点转换为线并找到行程相互交叉的点:

    from itertools import combinations
    
    import pandas as pd
    import geopandas as gpd
    
    from shapely.geometry import LineString
    
    # Read CSV File
    df = pd.read_csv("trips.csv")
    
    # Create Points
    points = gpd.GeoDataFrame(
        df,
        geometry=gpd.points_from_xy(df.longitude, df.latitude),
        crs="EPSG:4326"
    )
    points = points.drop(columns=["latitude", "longitude"])
    
    # Make sure Points are ordered (important)
    points = points.sort_values(["tripId", "timestamp"])
    
    # Create Lines
    tolist = lambda x: LineString(x.tolist())
    lines = points.groupby(["tripId"], as_index=False)["geometry"].apply(tolist)
    lines = gpd.GeoDataFrame(lines, geometry="geometry", crs="EPSG:4326")
    

    查找行程相互交叉的点:

    # Get Intersection Points
    template={"tripA":[], "tripB":[], "geometry":[]}
    intersection_points = gpd.GeoDataFrame(template, geometry="geometry")
    for index in combinations(lines.index, 2):
        
        combination = lines.loc[index,:]
        
        geometries = combination["geometry"].tolist()
        point = geometries[0].intersection(geometries[1])
    
        if point:  # LINESTRING EMPTY evaluates to false
    
            trips = combination["tripId"].tolist()
            row = pd.Series([trips[0], trips[1], point], index=intersection_points.columns)
            intersection_points = intersection_points.append(row, ignore_index=True)
    

    intersection_points 写入 CSV 文件:

    intersection_points["longitude"] = intersection_points.geometry.x
    intersection_points["latitude"] = intersection_points.geometry.y
    
    columns = ["tripA", "tripB", "latitude", "longitude"]
    intersection_points.to_csv("intersections.csv", columns=columns)
    

    将创建的线和交点写入形状文件:

    # Write Shape Files
    lines.to_file("trips.shp")
    intersection_points.to_file("intersections.shp")
    

    两个行程相互交叉的示例数据(基于问题的示例数据):

    "timestamp","tripId","longitude","latitude"
    "2021-07-05 10:35:04","1866491","8.167035","53.160473"
    "2021-07-05 10:35:03","1866491","8.167023","53.160469"
    "2021-07-05 10:35:02","1866491","8.167007","53.160459"
    "2021-07-05 10:35:01","1866491","8.166987","53.160455"
    "2021-07-05 10:35:00","1866491","8.166956","53.160448"
    "2021-07-05 10:34:20","1866491","8.167286","53.15919"
    "2021-07-05 10:34:19","1866491","8.167328","53.15918"
    "2021-07-05 10:34:18","1866491","8.16735","53.159165"
    "2021-07-05 10:34:17","1866491","8.167371","53.159148"
    "2021-07-05 10:34:16","1866491","8.167388","53.159124"
    "2021-07-05 10:34:15","1866491","8.167399","53.159105"
    "2021-06-30 20:25:30","1862861","8.211288","53.150848"
    "2021-06-30 20:25:29","1862861","8.211264","53.150851"
    "2021-06-30 20:25:28","1862861","8.211269","53.150842"
    "2021-06-30 20:25:27","1862861","8.211273","53.150836"
    "2021-06-30 20:25:26","1862861","8.211279","53.150836"
    "2021-06-30 20:25:25","1862861","8.211259","53.150848"
    "2021-06-30 20:25:24","1862861","8.211263","53.15085"
    "2021-06-30 20:25:21","1862861","8.211455","53.150782"
    "2021-06-30 20:25:19","1862861","8.211449","53.150792"
    "2021-06-30 20:25:20","1862861","8.211453","53.150786"
    "2021-06-30 20:25:18","1862861","8.166607","53.159654"
    

    【讨论】:

    • 非常感谢先生的回答,这很有帮助:D 我还有一个问题,是否有可能计算每个 tripId 在每个路口的等待时间?通过你的代码,我们现在也有了所有的交叉点,我们应该只比较经度和纬度是否改变?如果它没有改变,那意味着用户正在等待,然后我们应该检查它是否是一个交叉路口,如果是这样,那么我们应该在“时间戳”上看到花了多少时间......或者还有另一种方法可以计算十字路口的等待时间
    • 不客气。不,我看不到在十字路口提取等待时间的方法。您需要知道他们何时到达十字路口以及何时离开。你没有这个信息。至少没有提供的示例数据。对不起。
    猜你喜欢
    • 2012-12-21
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多