识别最近邻的线串地理数据框对的快速方法
我有一个包含 90 个地理数据框的列表,所有这些都包含相互连接的 LineString(想象一下 MultiLineString)。
从这个列表中,我想确定两个彼此最接近的 GDF(在考虑每个 GDF 组合线串的范围时最接近)。
我可以想象这样做的手动方法是填充 90x90 矩阵并调用距离函数,如下所示:
matrix = np.zeros((90, 90))
gdfs = [gdf1, gdf2, gdf3, gdf4, ..., gdf90]
for i, gdf_init in enumerate(gdfs):
for j, gdf_pair in enumerate(gdfs):
min_dist = gdf_init.distance(gdf_pair).min()
matrix[i, j] = min_dist
然后使用 np.where 获取矩阵中最小 min_dist 值的 (i, j) 值。
然而,也许嵌套 for 循环并不是最 Pythonic 的处理方式。想知道是否有人对此任务有优化的实施建议?
I have a list of 90 geodataframes, all containing LineStrings that are connected to each other (imagine a MultiLineString).
From this list, I would like to identify the two GDFs that are in closest proximity to each other (closest as in considering the extents of the combined linestrings of each GDF).
A manual way i can imagine doing this is to populate a 90x90 matrix and call the distance function as in:
matrix = np.zeros((90, 90))
gdfs = [gdf1, gdf2, gdf3, gdf4, ..., gdf90]
for i, gdf_init in enumerate(gdfs):
for j, gdf_pair in enumerate(gdfs):
min_dist = gdf_init.distance(gdf_pair).min()
matrix[i, j] = min_dist
And then use np.where to get the (i, j) values of the smallest min_dist value in the matrix.
However, perhaps nested for loops are not the most pythonic way to go about things. Wondering if anyone has an optimized implementation recommendation for this task?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sjoin_nearest()
源线字符串
凸包
最近的
sjoin_nearest()
sourcing line strings
convex hull
nearest