在带有点和多边形的 Snowflake 中使用 ST_Intersects 有技巧吗?
Is there a trick to using ST_Intersects in Snowflake with a point and a multipolygon?
我可以 ST_Intersects 处理一个点和一个多边形,但不能处理一个点和一个多边形。有没有一种简单的方法可以将多边形拆分为单独的多边形,并在每个多边形上 运行 ST_Intersects?
我发现交叉点和多边形没有问题:
with a as (
select to_geography('POLYGON((0.0 0.0, 1.0 0.0, 1.0 2.0, 0.0 2.0, 0.0 0.0))') as polygon
union all select to_geography('MULTIPOLYGON(((-124.20 42.00, -120.01 41.99, -121.1 42.01, -124.20 42.0)), ((0.0 0.0, 1.0 0.0, 1.0 2.0, 0.0 2.0, 0.0 0.0)))')
), b as (
select to_geography('POINT(0.1 0.1)') point
union all select to_geography('POINT(3.3 3.3)')
union all select to_geography('POINT(-124.20 42.00)')
)
select ST_ASWKT(point), ST_ASWKT(polygon), st_intersects(polygon, point) intersects
from a, b
结果完全符合我的预期:
我可以 ST_Intersects 处理一个点和一个多边形,但不能处理一个点和一个多边形。有没有一种简单的方法可以将多边形拆分为单独的多边形,并在每个多边形上 运行 ST_Intersects?
我发现交叉点和多边形没有问题:
with a as (
select to_geography('POLYGON((0.0 0.0, 1.0 0.0, 1.0 2.0, 0.0 2.0, 0.0 0.0))') as polygon
union all select to_geography('MULTIPOLYGON(((-124.20 42.00, -120.01 41.99, -121.1 42.01, -124.20 42.0)), ((0.0 0.0, 1.0 0.0, 1.0 2.0, 0.0 2.0, 0.0 0.0)))')
), b as (
select to_geography('POINT(0.1 0.1)') point
union all select to_geography('POINT(3.3 3.3)')
union all select to_geography('POINT(-124.20 42.00)')
)
select ST_ASWKT(point), ST_ASWKT(polygon), st_intersects(polygon, point) intersects
from a, b
结果完全符合我的预期: