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

$geoWithin edge problems

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.1
    • Component/s: Geo
    • Labels:
      None
    • ALL
    • Hide

      Here's the REPL transcript.

      > use test
      switched to db test
      > db.dropDatabase()
      { "dropped" : "test", "ok" : 1 }
      > db.test.createIndex({grid:'2dsphere'})
      {
      	"createdCollectionAutomatically" : true,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      // make a square, coordinates start at NW corner
      > db.test.insert({grid:{type:'Polygon',coordinates:[[[1,2],[2,2],[2,1],[1,1],[1,2]]]}})
      WriteResult({ "nInserted" : 1 })
      // find the square inside the square
      > db.test.find({grid: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [[[1,2],[2,2],[2,1],[1,1],[1,2]]] } } } })
      { "_id" : ObjectId("5531aa43fb4a314ff06590d9"), "grid" : { "type" : "Polygon", "coordinates" : [ [ [ 1, 2 ], [ 2, 2 ], [ 2, 1 ], [ 1, 1 ], [ 1, 2 ] ] ] } }
      // square is missing from various rectangles including the square but extending in different directions, $geoIntersects works
      > db.test.find({grid: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [[[0,2],[2,2],[2,1],[0,1],[0,2]]] } } } })
      > db.test.find({grid: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [[[0,2],[3,2],[3,1],[0,1],[0,2]]] } } } })
      > db.test.find({grid: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [[[0,3],[3,3],[3,1],[0,1],[0,3]]] } } } })
      // square is present in larger square
      > db.test.find({grid: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [[[0,3],[3,3],[3,0],[0,0],[0,3]]] } } } })
      { "_id" : ObjectId("5531aa43fb4a314ff06590d9"), "grid" : { "type" : "Polygon", "coordinates" : [ [ [ 1, 2 ], [ 2, 2 ], [ 2, 1 ], [ 1, 1 ], [ 1, 2 ] ] ] } }
      
      Show
      Here's the REPL transcript. > use test switched to db test > db.dropDatabase() { "dropped" : "test", "ok" : 1 } > db.test.createIndex({grid:'2dsphere'}) { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } // make a square, coordinates start at NW corner > db.test.insert({grid:{type:'Polygon',coordinates:[[[1,2],[2,2],[2,1],[1,1],[1,2]]]}}) WriteResult({ "nInserted" : 1 }) // find the square inside the square > db.test.find({grid: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [[[1,2],[2,2],[2,1],[1,1],[1,2]]] } } } }) { "_id" : ObjectId("5531aa43fb4a314ff06590d9"), "grid" : { "type" : "Polygon", "coordinates" : [ [ [ 1, 2 ], [ 2, 2 ], [ 2, 1 ], [ 1, 1 ], [ 1, 2 ] ] ] } } // square is missing from various rectangles including the square but extending in different directions, $geoIntersects works > db.test.find({grid: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [[[0,2],[2,2],[2,1],[0,1],[0,2]]] } } } }) > db.test.find({grid: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [[[0,2],[3,2],[3,1],[0,1],[0,2]]] } } } }) > db.test.find({grid: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [[[0,3],[3,3],[3,1],[0,1],[0,3]]] } } } }) // square is present in larger square > db.test.find({grid: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [[[0,3],[3,3],[3,0],[0,0],[0,3]]] } } } }) { "_id" : ObjectId("5531aa43fb4a314ff06590d9"), "grid" : { "type" : "Polygon", "coordinates" : [ [ [ 1, 2 ], [ 2, 2 ], [ 2, 1 ], [ 1, 1 ], [ 1, 2 ] ] ] } }

      (I posted to the user group for help, see here: https://groups.google.com/forum/#!topic/mongodb-user/iOEDaxjDyHY)

      I make a square but can't find it via $geoWithin in cases where the query rectangle has some same edges as the square but not all same edges. But the $geoWithin docs say "When determining inclusion, MongoDB considers the border of a shape to be part of the shape, subject to the precision of floating point numbers."

      This happens in versions 2.6 and 3

            Assignee:
            siyuan.zhou@mongodb.com Siyuan Zhou
            Reporter:
            jfgorski-hivemapper john gregorski
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: