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

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

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.8
    • Component/s: Geo
    • Query Integration
    • ALL
    • 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]]] } } } })

      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.

            Assignee:
            backlog-query-integration [DO NOT USE] Backlog - Query Integration
            Reporter:
            AliOli Alex Olieman
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated: