【问题标题】:Bigquery - Given a geo point and distance how to get a polygon around itBigquery - 给定一个地理点和距离如何在它周围获得一个多边形
【发布时间】:2020-04-02 01:05:33
【问题描述】:

我有一个问题要解决,在给定中心地理点和距离的情况下,我需要在它周围提取一个多边形。

想象一下任何地理点:比如说:41.6748248,-83.6882749,我需要用 50 的距离在它周围找到一个八边形,例如

回答我自己的问题,因为我没有找到任何其他可以直接在 BQ 中使用的方法。 (到目前为止,BQ 中还没有针对此的原生函数。)

【问题讨论】:

    标签: google-bigquery geospatial


    【解决方案1】:
    CREATE TEMPORARY FUNCTION get_point_at_a_distance(latitude float64, longitude float64, d int64, brng int64) as (
        (select ST_GEOGPOINT(((longitude* (ACOS(-1)/180)) + atan2(sin(brng* (ACOS(-1)/180))*sin(d/6371000)*cos(latitude* (ACOS(-1)/180)),cos(d/6371000)-sin(latitude* (ACOS(-1)/180))*sin(latitude* (ACOS(-1)/180))))* (180/ACOS(-1)), 
        (asin(sin(latitude* (ACOS(-1)/180))*cos(d/6371000) + cos(latitude* (ACOS(-1)/180))*sin(d/6371000)*cos(brng* (ACOS(-1)/180))))* (180/ACOS(-1))))
    ); 
    
    CREATE TEMPORARY FUNCTION get_polygon(latitude float64, longitude float64, distance int64) as (
    
    (select ST_MAKEPOLYGON(ST_MAKELINE(ARRAY_AGG(geo_point))) 
    from 
    (
    select get_point_at_a_distance(latitude, longitude, distance, 0) as geo_point union all 
    select get_point_at_a_distance(latitude, longitude, distance, 45) as geo_point  union all 
    select get_point_at_a_distance(latitude, longitude, distance, 90) as geo_point  union all 
    select get_point_at_a_distance(latitude, longitude, distance, 135) as geo_point  union all 
    select get_point_at_a_distance(latitude, longitude, distance, 180) as geo_point  union all 
    select get_point_at_a_distance(latitude, longitude, distance, 225) as geo_point  union all 
    select get_point_at_a_distance(latitude, longitude, distance, 270) as geo_point  union all 
    select get_point_at_a_distance(latitude, longitude, distance, 315) as geo_point 
    )));
    
    select get_polygon(41.6748248, -83.6882749, 50)```
    
    
    Confirm with: https://www.keene.edu/campus/maps/tool/
    Try to plot the output: 
    -83.6887005865171, 41.6751427574177
     -83.6888769116458, 41.6748247984293
     -83.6887005865171 ,41.6745068410117
     -83.6882749, 41.674375139197
     -83.6878492134828, 41.6745068410116
     -83.6876728883542, 41.6748247984293
    -83.6878492134828, 41.6751427574177
     -83.6882749, 41.675274460803
     -83.6887005865171, 41.6751427574177
    
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    相关资源
    最近更新 更多