Mongodb Geo Boundary

时间:2016-11-29 12:00:18

标签: javascript node.js mongodb

假设我有一个多边形

[
    [22.592477,88.395223],
    [22.580589,88.401060],
    [22.562281,88.408098],
    [22.558001,88.411703],
    [22.576389,88.422689],
    [22.585107,88.435821],
    [22.600955,88.424577],
    [22.602936,88.413333],
    [22.592477,88.395223]

]

保存在mongodb databae。

现在我的目标是一次检查两个或更多点,是那个边界下的点吗?它适用于单点检查。

1 个答案:

答案 0 :(得分:0)

试试这个:not very well documented

const inside = require('point-in-polygon')
const polygon = [
    [22.592477, 88.395223],
    [22.580589, 88.401060],
    [22.562281, 88.408098],
    [22.558001, 88.411703],
    [22.576389, 88.422689],
    [22.585107, 88.435821],
    [22.600955, 88.424577],
    [22.602936, 88.413333],
    [22.592477, 88.395223]
]

const pointOne = [ 22.562281, 88.408098 ]
const pointTwo = [ 4.9, 1.2 ]

console.dir([
    inside(pointOne, polygon),
    inside(pointTwo, polygon)
]) // output: [true, false]