您如何使用 pandas 和 python 来评估用户位于多少个地理框内?

How do you use pandas and python to assess within how many geographic boxes the user is located?

我想弄清楚 Uber 和 UbersEats 等应用程序是如何运营和管理物流的。我想知道我们如何构建一个函数来计算用户位于多少个框内。 这是用户的数据:

user_id,loc_lat,loc_lon
1,55.737564,37.345186
2,56.234564,37.234590
3,55.234578,36.295745

这是盒子(地方)的坐标:

place_id,loc_lat,loc_lon,point_number
1,55.747022,37.787073,0
1,55.751713,37.784328,1
1,55.753878,37.777638,2
1,55.751031,37.779351,3
2,55.803885,37.458311,0
2,55.808677,37.464054,1
2,55.809763,37.461314,2
2,55.810840,37.458654,3

因此,对于用户 1 而言,将有 2 个可用位置,而对于用户 3,则为 0 个。 如果您能指出正确的方向,我将不胜感激。

来自用户的测试用例:none 个在框的范围内。遵循来自的逻辑 How can I determine whether a 2D Point is within a Polygon?

// p is your point, p.x is the x coord, p.y is the y coord
if (p.x < Xmin || p.x > Xmax || p.y < Ymin || p.y > Ymax) {
    // Definitely not within the polygon!
}

正在 Python 中加载 DataFrame:

import pandas as pd
columns = ['user_id','loc_lat','loc_lon','point_number']
df = pd.DataFrame([[1,55.747022,37.787073,0],[1,55.751713,37.784328,1],[1,55.753878,37.777638,2],[1,55.751031,37.779351,3]], columns = columns)