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

问题描述

我在 BigQuery 表中存储了 40,000 条道路线串,我想为它们找到所有唯一的交叉点。我在此处 (https://gis.stackexchange.com/questions/20835/identifying-road-intersections-using-postgis/151277#151277) 的 postGIS 中找到了如何执行此操作,但我无法在 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

解决方法

我不明白为什么您需要汇总结果:

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
,

您可以使用大部分相同的答案,但只需要将地理解析为 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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...