问题描述
我想在多边形查询中为 1400 万次纽约出租车行程创建一个点,并找出这些行程位于 263 个出租车区域中的哪个区域。
我想要 RAPIDS cuspatial 上的代码。我阅读了一些论坛和帖子,并遇到了尖角多边形限制,即用户在每次运行中只能对 32 个多边形执行查询。因此,我执行以下操作以分批拆分多边形。
这是我的出租车区多边形文件
cusptaxizone
(0 0
1 1
2 34
3 35
4 36
...
258 348
259 349
260 350
261 351
262 353
Name: f_pos,Length: 263,dtype: int32,0 0
1 232
2 1113
3 1121
4 1137
...
349 97690
350 97962
351 98032
352 98114
353 98144
Name: r_pos,Length: 354,x y
0 933100.918353 192536.085697
1 932771.395560 191317.004138
2 932693.871591 191245.031174
3 932566.381345 191150.211914
4 932326.317026 190934.311748
... ... ...
98187 996215.756543 221620.885314
98188 996078.332519 221372.066989
98189 996698.728091 221027.461362
98190 997355.264443 220664.404123
98191 997493.322715 220912.386162
[98192 rows x 2 columns])
总共有 263 个多边形/出租车区 - 我想在每次迭代中以 24 个批次和 11 个多边形进行查询。
def create_iterations(start,end,batches):
iterations = list(np.arange(start,batches))
iterations.append(end)
return iterations
pip_iterations = create_iterations(0,264,24)
#loop to do point in polygon query in a table
def perform_pip(cuda_df,cuspatial_data,polygon_name,iter_batch):
cuda_df['borough'] = " "
for i in range(len(iter_batch)-1):
start = pip_iterations[i]
end = pip_iterations[i+1]
pip = cuspatial.point_in_polygon(cuda_df['pickup_longitude'],cuda_df['pickup_latitude'],cuspatial_data[0][start:end],#poly_offsets
cuspatial_data[1],#poly_ring_offsets
cuspatial_data[2]['x'],#poly_points_x
cuspatial_data[2]['y'] #poly_points_y
)
for i in pip.columns:
cuda_df['borough'].loc[pip[i]] = polygon_name[i]
return cuda_df
当我运行该函数时,我收到一个类型错误。我想知道是什么原因导致了这个问题?
pip_pickup = perform_pip(cutaxi,cusptaxizone,pip_iterations)
TypeError: perform_pip() missing 1 required positional argument: 'iter_batch'
解决方法
似乎您正在为 cutaxi
传入 cuda_df
,为 cusptaxizone
传入 cuspatial_data
,为 pip_iterations
中的 polygon_name
变量传入 perform_pip
}} 功能。没有为 iter_batch
函数中定义的 perform_pip
传递变量/值:
def perform_pip(cuda_df,cuspatial_data,polygon_name,iter_batch):
因此,您会收到上述错误,指出 iter_batch
缺失。正如上述评论中所述,您没有为 perform_pip
函数传递正确数量的参数。
如果您编辑代码以将正确数量的变量传递给 perform_pip
函数,则会出现上述错误:
TypeError: perform_pip() missing 1 required positional argument: 'iter_batch'
会解决。