2017-01-28 3 views
1

저장되는 경우에도 I는 각각의 위치는 다각형 위치 모음을 갖는다.몽고 체크 포인트는 내부 I는 각 사용자가 포인트</p> <p>userSchema</p> <pre><code>username: string, location: { type: { type: String, default: 'Point' }, coordinates: {type: [Number], default: [0,0] } }, </code></pre> <p>있는 사용자 컬렉션이 다각형

name: {type: String, required: true}, 
area: { 
    type: { type: String, default: 'Polygon' }, 
    coordinates: {type: [], required: true } 
} 

locationsSchema 지금 제가 2 위치 poygons [ID1, ID2]를 선택한 말한다. 이 위치 내부의 모든 사용자, 즉 포이곤 id1과 id2를 찾고 싶습니다. 어떻게해야합니까?

내가 아는 내가 한 지점이 주어진 경우 나는이

db.locations.find({"loc":{"$geoIntersects":{"$geometry":{"type":"Point", "coordinates":[x, y]}}}} 

그러나 내가 다각형을 부여하고 그 안에 모든 사용자를 찾으려는 경우와 같은 다각형을 찾을 수 있습니까?

나는 내가 할 수있는 한 다각형 알아 냈

편집

User.find({location: { $geoWithin: { $geometry: locations[0] }}}); 

어떻게 내가 여러 다각형에 대해 갈 수있는이?

답변

0

누구나이 문제가 있습니다. 모든 다각형을 반복하는 Multipolygon을 작성하여 간단하게 해결했습니다.

var loc_json = {type: 'MultiPolygon', coordinates: []}; 
var flat_loc = _.flatMap(all_loc, 'locations'); 
var locations = []; 
_.forEach(flat_loc, function(loc) { 
    locations.push(loc.area.coordinates); 
}); 
loc_json.coordinates = locations; 
User.find({location: { $geoWithin: { $geometry: loc_json }}});