gpt4 book ai didi

geolocation - 雪花查询以获取多边形内的数据

转载 作者:行者123 更新时间:2023-12-05 06:33:23 28 4
gpt4 key购买 nike

我有一个表,其中包含位置列数据作为经纬度信息,如何获取多边形内位置的记录

多边形点

[
[42.811521745097906, -105.60058593749999],
[33.94335994657882, -109.2041015625],
[35.60371874069732, -88.02246093749999],
[46.67959446564018, -89.6923828125],
[42.811521745097906, -105.60058593749999]
]

最佳答案

这是一个 UDF 示例。

create or replace function inside(point array, vs array)
returns string
language javascript
as $$
var point = POINT;
var vs = VS;

var x = point[0], y = point[1];

var inside = false;
for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
var xi = vs[i][0], yi = vs[i][1];
var xj = vs[j][0], yj = vs[j][1];

var intersect = ((yi > y) != (yj > y))
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
if (intersect) inside = !inside;
}

return inside;
$$;

select inside(parse_json('[ 4.9, 1.2 ]')::array, parse_json('[ [ 1, 1 ], [ 1, 2 ], [ 2, 2 ], [ 2, 1 ] ]')::array);

关于geolocation - 雪花查询以获取多边形内的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50794172/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com