Description
The behavior section sounds ambiguous to me.
http://docs.mongodb.org/manual/reference/operator/query/geoIntersects/
http://docs.mongodb.org/manual/reference/operator/query/geoWithin/
Behavior
Any geometry specified with GeoJSON to $geoIntersects queries must fit within a single hemisphere. MongoDB interprets geometries larger than half of the sphere as queries for the smaller of the complementary geometries.
A geometry in query doesn't have to fit within a single hemisphere. For exmaple, let's imagine we have a band around the equator as following. Visualize it by dragging the GeoJSON definition to http://map.visualzhou.com, or see the screenshot attached. It's impossible to cover this band with any hemisphere cap, no matter North/South hemisphere or any hemisphere. However, since its area is less than half of the surface area of the earth, MongoDB/S2 still interpret it as the band we want. So the area matters, rather than the span.
var band = {
|
"type" : "Polygon",
|
"coordinates" : [
|
[
|
[-170, 10 ],
|
[-85, 10 ],
|
[0, 10 ],
|
[85, 10 ],
|
[170, 10 ],
|
[170, -10 ],
|
[85, -10 ],
|
[0, -10 ],
|
[-85, -10 ],
|
[-170, -10 ],
|
[-170, 10 ]
|
]
|
]
|
}
|
|
|
var coll = db.geo_hemisphere;
|
coll.drop();
|
assert.writeOK(coll.insert({loc: [0, 0]}));
|
assert.commandWorked(coll.ensureIndex({loc: "2dsphere"}));
|
|
|
assert.eq(1, coll.find({loc: { $geoWithin: {$geometry: band}}}).count());
|