如果不与另一条折线相交,如何在 Folium 中绘制折线

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

我正在使用 Folium 绘制数百万个 Google 位置历史数据点。我的目标是查看我在我居住的城市访问过哪些街道。我遇到的问题是多段线相互重叠。如果它不会与另一条折线重叠,我只想绘制一条折线。在 Folium 中有办法做到这一点吗?

map = folium.Map(location=[coord1, coord2])
for i in range(len(df)):
    folium.PolyLine(([df.iloc[i]['lat'], df.iloc[i]['lon']],
    [df.iloc[i+1]['lat'], df.iloc[i+1]['lon']] ), 
    no_clip=True, smooth_factor=1).add_to(map)
        count += 1
    if count > 10000:
        break
map.save('test.html')
python geospatial folium
1个回答
0
投票

以下是查看线段AB和CD是否相交的方法:

def intersect(A, B, C, D):
    """
    Check if line segments AB and CD intersect
    """
    def ccw(A,B,C):
        return (C[1]-A[1]) * (B[0]-A[0]) > (B[1]-A[1]) * (C[0]-A[0])
    
    return ccw(A,C,D) != ccw(B,C,D) and ccw(A,B,C) != ccw(A,B,D)

在地图上添加一条线时,将它与所有其他折线进行比较,看它们是否相交,如果不与任何一条线相交,则绘制线。

© www.soinside.com 2019 - 2024. All rights reserved.