Bigquery - 给定一个地理点和距离如何在它周围获得一个多边形
Posted
技术标签:
【中文标题】Bigquery - 给定一个地理点和距离如何在它周围获得一个多边形【英文标题】:Bigquery - Given a geo point and distance how to get a polygon around it 【发布时间】:2020-04-02 01:05:33 【问题描述】:我有一个问题要解决,在给定中心地理点和距离的情况下,我需要在它周围提取一个多边形。
想象一下任何地理点:比如说:41.6748248,-83.6882749,我需要用 50 米的距离在它周围找到一个八边形,例如
回答我自己的问题,因为我没有找到任何其他可以直接在 BQ 中使用的方法。 (到目前为止,BQ 中还没有针对此的原生函数。)
【问题讨论】:
【参考方案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
【讨论】:
我的办公室朋友@Mikhail 将这个库发给我以查看:github.com/CartoDB/bigquery-jslibs 分享给任何人以探索更多内容以上是关于Bigquery - 给定一个地理点和距离如何在它周围获得一个多边形的主要内容,如果未能解决你的问题,请参考以下文章
查询以将在特定地理距离内的行返回到给定行(使用 sql server 2008)