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

$geoWithin and $geoIntersects do not match the query polygon's border

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 2.6.8
    • Fix Version/s: Backlog
    • Component/s: Geo
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      1. insert linestring into test collection

      db.geo_test.insert({
          "geometry": {
              "type": "LineString",
              "coordinates": [[2.0, 0.0], [1.0, 0.0]]
          }
      })
      

      2. create a 2dsphere index

      db.geo_test.ensureIndex({'geometry': '2dsphere'})
      

      3. query the index with a polygon

      db.geo_test.find({
         'geometry': {
            $geoWithin: {
               $geometry: {
                  'type': "Polygon",
                  'coordinates': [[[1.0, 1.0], [2.0, 1.0], [2.0, 0.0], [1.0, 0.0], [1.0, 1.0]]]
               }
            }
         }
      })
      

      Show
      1. insert linestring into test collection db.geo_test.insert({ "geometry" : { "type" : "LineString" , "coordinates" : [[2.0, 0.0], [1.0, 0.0]] } }) 2. create a 2dsphere index db.geo_test.ensureIndex({ 'geometry' : '2dsphere' }) 3. query the index with a polygon db.geo_test.find({ 'geometry' : { $geoWithin: { $geometry: { 'type' : "Polygon" , 'coordinates' : [[[1.0, 1.0], [2.0, 1.0], [2.0, 0.0], [1.0, 0.0], [1.0, 1.0]]] } } } })

      Description

      The $geoWithin and $geoIntersects operators do not retrieve (parts of) the border of the polygon that they are queried with. This doesn't make sense, and the docs seem to agree:

      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 issue presents itself when all coordinate pairs of a linestring intersect (i.e. are part of) the polygon border. When one of the line's points on the border is moved to the inside of the polygon, that line is retrieved by the query as expected.

      I would be surprised if this issue is caused by floating point precision or the spherical reference system.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated: