函数 pointInPolygon() 可以判断一个 2D 坐标点是否位于一个多边形区域内,并返回 1(是)、0(否)。点落在区域边界上的视为否。
Arguments:
- 2D 坐标 <point|list>
- 多边形区域 <list>
Returns:
- 判断结果 <number>
一般用法
示例:异源别名直接计算
uncollect [[1.5,0.5],[2,2]] as point
uncollect [[[1,0],[3,0],[3,1],[1,1]],[[1,0],[2,1],[1,2],[0,1]]] as polygon
return table(toString(point), toString(polygon), pointInPolygon(point, polygon))
| toString(point) | toString(polygon) | pointInPolygon(point, polygon) |
|-----------------|---------------------------|--------------------------------|
| [1.5,0.5] | [[1,0],[3,0],[3,1],[1,1]] | 1 |
| [2,2] | [[1,0],[2,1],[1,2],[0,1]] | 0 |
示例:异源别名笛卡尔积后计算
uncollect [[1.5,0.5],[2,2]] as point
uncollect [[[1,0],[3,0],[3,1],[1,1]],[[1,0],[2,1],[1,2],[0,1]]] as polygon
with pointInPolygon(point, polygon) as result
return table(toString(point), toString(polygon), result)
| toString(point) | toString(polygon) | result |
|-----------------|---------------------------|--------|
| [1.5,0.5] | [[1,0],[3,0],[3,1],[1,1]] | 1 |
| [1.5,0.5] | [[1,0],[2,1],[1,2],[0,1]] | 0 |
| [2,2] | [[1,0],[3,0],[3,1],[1,1]] | 0 |
| [2,2] | [[1,0],[2,1],[1,2],[0,1]] | 0 |