2013-07-29 21 views
0
db.restaurant.ensureIndex({'deliver_area': '2dsphere'}) 
db.restaurant.insert({'deliver_area':{type: 'Polygon', coordinates:[[[0,0], [0,1], [1,0], [1,1], [0, 0]]]}}) 

加註EXC:MongoDB錯誤:多邊形的外殼無效?

多邊形的外觀外殼無效:{類型: 「多邊形」,座標:[[[0.0,0.0],[0.0,1.0],[1.0,0.0],[1.0 ,1.0],[0.0,0.0]]]}

爲什麼多邊形無效?

回答

3

這是自交的多邊形:

2  4 
    |\ /| 
    | \/| 
    | \/ | 
    | /\ | 
    |/\ | 
    |/ \| 
1/5  3 

你想:

{ 
    type: "Polygon", 
    coordinates: [ [ 
     [ 0.0, 0.0 ], 
     [ 0.0, 1.0 ], 
     [ 1.0, 1.0 ], 
     [ 1.0, 0.0 ], 
     [ 0.0, 0.0 ] 
    ] ] 
} 

那就是:

2------3 
    |  | 
    |  | 
    |  | 
    |  | 
    |  | 
    |  | 
1/5-----4 
+0

你好,德里克。感謝您的回答。我有關於mongodb地理空間索引的另一個問題[鏈接](http://stackoverflow.com/questions/18032023/mongodb-2-4-2dsphere-queries-very-slow-using-geointersects) – Tallmad