2016-11-29 60 views
-1

假設我有一個多邊形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。

現在我的目標是一次檢查兩個或多個點,那些是在那個邊界之下?它對單點檢查很有效。

回答

0

試試這個: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] 
+1

由於它的工作原理 –