Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-8180

Polygon running the length of the equator returns incorrect results using $within query and 2dsphere index

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • ALL
    • Hide

      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');*

      Show
      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');*

      $geoIntersects is also returning more results than expected.

            Assignee:
            hari.khalsa@10gen.com hari.khalsa@10gen.com
            Reporter:
            ian.bentley Ian Bentley
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: