用于计算距离的笛卡尔积的 BigQuery Geography 函数
BigQuery Geography function to compute cartesian product of distances
我需要计算一组 GEO 点的距离的笛卡尔积。
更具体地说,计算从第一个点到所有其他 5 个点的距离,然后是从第二个点到所有其他点的距离等。
想知道是否有可以有效执行此类计算的 BigQuery Geography 函数。
另一种方法是显式地成对进行,这是一种蛮力方法。
POINT(-95.665885 29.907145)
POINT(-95.636533 29.757219)
POINT(-95.652796 29.89204)
POINT(-84.27087 33.991642)
POINT(-84.466853 33.987008)
我尝试使用您的示例数据创建示例:
//Creating a temporary table with your data
with t as
(Select * from UNNEST(
['POINT(-95.665885 29.907145)',
'POINT(-95.636533 29.757219)',
'POINT(-95.652796 29.89204)',
'POINT(-84.27087 33.991642)',
'POINT(-84.466853 33.987008)']) f
)
//Doing a cross join of the created table with itself, filtering some cases to avoid calculating the distance of a point to itself and calculating the distance between the points
select
t.f point_1,
t2.f point_2,
ST_DISTANCE(ST_GeogFromText(t.f), ST_GeogFromText(t2.f))
from t cross join t t2
where t.f <> t2.f
group by point_1, point_2
是您要找的吗?
当然如果你认为两点之间的距离是相同的,无论它们的顺序如何,它都可以优化。
我需要计算一组 GEO 点的距离的笛卡尔积。 更具体地说,计算从第一个点到所有其他 5 个点的距离,然后是从第二个点到所有其他点的距离等。
想知道是否有可以有效执行此类计算的 BigQuery Geography 函数。
另一种方法是显式地成对进行,这是一种蛮力方法。
POINT(-95.665885 29.907145)
POINT(-95.636533 29.757219)
POINT(-95.652796 29.89204)
POINT(-84.27087 33.991642)
POINT(-84.466853 33.987008)
我尝试使用您的示例数据创建示例:
//Creating a temporary table with your data
with t as
(Select * from UNNEST(
['POINT(-95.665885 29.907145)',
'POINT(-95.636533 29.757219)',
'POINT(-95.652796 29.89204)',
'POINT(-84.27087 33.991642)',
'POINT(-84.466853 33.987008)']) f
)
//Doing a cross join of the created table with itself, filtering some cases to avoid calculating the distance of a point to itself and calculating the distance between the points
select
t.f point_1,
t2.f point_2,
ST_DISTANCE(ST_GeogFromText(t.f), ST_GeogFromText(t2.f))
from t cross join t t2
where t.f <> t2.f
group by point_1, point_2
是您要找的吗? 当然如果你认为两点之间的距离是相同的,无论它们的顺序如何,它都可以优化。