var t = db.geo_s2oddshapes
t.drop()
t.ensureIndex(
{ geo : "2dsphere" }
);
var testPoint = {
name: "origin",
geo:
{
type: "Point",
coordinates: [0.0, 0.0]
}
};
var testHorizLine = {
name: "horiz",
geo:
{
type: "LineString",
coordinates: [[-2.0, 10.0], [2.0, 10.0]]
}
};
var testVertLine = {
name: "vert",
geo:
{
type: "LineString",
coordinates: [[10.0, -2.0], [10.0, 2.0]]
}
};
t.insert(testPoint);
t.insert(testHorizLine);
t.insert(testVertLine);
//Test a poly that runs horizontally along the equator.
var longPoly =
{type: "Polygon",
coordinates: [
[[89.0, 1.0], [-89.0, 1.0], [-89.0, -1.0], [89.0, -1.0], [89.0, 1.0]]
]}
;
//We expect that the testPoint (at the origin) will be within this poly.
result = t.find({geo: {$within: {$geometry: longPoly}}});
assert.eq(result.count(), 1);
assert.eq(result[0].name, 'origin');
//We expect that the testPoint, and the testVertLine should geoIntersect
//with this poly.
result = t.find({geo: {$geoIntersects: {$geometry: longPoly}}});
assert.eq(result.count(), 2);
assert.eq(result[0].name, 'vert');
assert.eq(result[1].name, 'origin');*