Rahul Dey Rahul Dey - 11 days ago 6
Node.js Question

Mongodb Geo Boundary

Suppose I have a 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]

]


That is saved in mongodb databae.

Now my goal is to check two or more point at a time, are those under that boundary? It is working well for single point checking.

Answer

try this: point-in-polygon

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]