我正在尝试遍历一组几何,并查看它们是否与另一个几何相交,所以像这样:
select unnest(
ARRAY[
ST_Intersects(box,ST_GeomFromText('POINT(4 4)')),
ST_Intersects(box,ST_GeomFromText('POINT(4.0001 4.0001)')),
ST_Intersects(box,ST_GeomFromText('POINT(4.4 4.4)')),
ST_Intersects(box,ST_GeomFromText('POINT(4.4002 4.4002)')),
ST_Intersects(box,ST_GeomFromText('POINT(5 5)'))
]
) from (select ST_MakeBox2D(ST_Point(3,2),ST_Point(5,4)) as box) as sq
如何做到这一点而不必分别在每个点上调用ST_Intersects?
答案 0 :(得分:1)
如果您不想在每个字母上都写上st_intersects
,则可以改写它们:
select st_intersects(st_MakeBox2D(ST_Point(3,2),ST_Point(5,4)), point) from unnest(
ARRAY[
ST_GeomFromText('POINT(4 4)'),
ST_GeomFromText('POINT(4.0001 4.0001)'),
ST_GeomFromText('POINT(4.4 4.4)'),
ST_GeomFromText('POINT(4.4002 4.4002)'),
ST_GeomFromText('POINT(5 5)')
]) point;
通过这种方式,您无需重复相交,只需取消嵌套数组并检查与框的交集即可。当然在内部,总是对每个检查进行检查。