如何从存储在 BigQuery 中的大型线串数据集中查找所有道路交叉口

How to find all roadway intersections from a large dataset of linestrings stored in BigQuery

我在 BigQuery table 中存储了 40,000 条道路线串,我想为它们找到所有独特的交叉路口。我在这里找到了如何在 postGIS 中执行此操作 (https://gis.stackexchange.com/questions/20835/identifying-road-intersections-using-postgis/151277#151277),但我无法在 BigQuery 中使用此代码,因为我无法按地理位置分组。

SELECT      
    ST_Intersection(a.geom, b.geom),
    Count(Distinct a.gid)
FROM
    roads as a,
    roads as b
WHERE
    ST_Touches(a.geom, b.geom)
    AND a.gid != b.gid
GROUP BY
    ST_Intersection(a.geom, b.geom)



  [1]: https://gis.stackexchange.com/questions/20835/identifying-road-intersections-using-postgis/151277#151277

您可以使用大部分相同的答案,但只需要在 CTE 中将地理解析为文本,然后将其转换回地理。

with geomandcount as (
SELECT      
    st_astext(ST_Intersection(a.geom, b.geom)) as the_geom,
    Count(Distinct a.geoid) as count
    
FROM
    `roadways_table` as a,
    `roadways_table` as b
WHERE
    ST_intersects(a.geom, b.geom)
    AND a.geoid != b.geoid

group by st_astext(ST_Intersection(a.geom, b.geom))
)

select st_geogfromtext(the_geom) as the_geom, count 

from geomandcount

我不知道为什么你需要汇总结果:

SELECT ST_Intersection(r1.geom, r2.geom)
FROM roads r1 JOIN
     roads r2
     ON ST_Touches(r1.geom, r2.geom) AND
        r1.gid < r2.gid