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:
多边形的外壳无效:{type:“Polygon”,坐标:[[[0.0,0.0],[0.0,1.0],[1.0,0.0],[1.0,1.0],[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