问题描述
- 我有两个数据框
df_main
& df_lookup
。
df_main
有 219k 条具有地理空间特征的记录POINT(latitude, longitude)
。
df_lookup
有 12k 条具有地理空间特征的记录LINESTRING(latitude longitude, ..........., latitude longitude)
- 让我向您展示
df_main
.
df_lookup
也是一样的,但不是POINT
它有LINESTRING
import pandas as pd
import numpy as np
df_main = pd.read_csv("lat_long.csv")
df_lookup = pd.read_csv("line.csv")
df_main
**Latitude Longitude point**
0 33.94 -80.37 POINT (33.9428727 -80.37280269999999)
1 42.71 -71.17 POINT (42.715921 -71.17759649999999)
2 40.75 -73.99 POINT (40.7513773 -73.9924884)
3 40.51 -78.40 POINT (40.51711 -78.402507)
4 33.04 -96.86 POINT (33.0458064 -96.86345449999999)
- 我试图得到一个点
df_main
到所有线的最小距离df_lookup
。
- 我还在
df_main
每次索引迭代时更新列中的相同距离。这是下面的代码:
cnt=0
for pnt in df_main.point:
for line in df_lookup.line:
min_dist = []
min_dist.append(line.distance(pnt))
# print("Result appended :", cnt)
df_main.loc[cnt,'distance_GAF_locations'] = np.min(min_dist)
df_main.to_csv("GAF_location_distance.csv", index = False)
cnt+=1
- 这需要太多时间。
- 有没有一种简单的方法可以并行化这个过程?
标签: python-3.xpandasparallel-processinggeospatial
解决方案
推荐阅读