Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-4486

$geoWithin and $geoIntersects's Behavior

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • v1.3.15
    • None
    • manual
    • None

    Description

      The behavior section sounds ambiguous to me.
      http://docs.mongodb.org/manual/reference/operator/query/geoIntersects/
      http://docs.mongodb.org/manual/reference/operator/query/geoWithin/

      Behavior
      Any geometry specified with GeoJSON to $geoIntersects queries must fit within a single hemisphere. MongoDB interprets geometries larger than half of the sphere as queries for the smaller of the complementary geometries.

      A geometry in query doesn't have to fit within a single hemisphere. For exmaple, let's imagine we have a band around the equator as following. Visualize it by dragging the GeoJSON definition to http://map.visualzhou.com, or see the screenshot attached. It's impossible to cover this band with any hemisphere cap, no matter North/South hemisphere or any hemisphere. However, since its area is less than half of the surface area of the earth, MongoDB/S2 still interpret it as the band we want. So the area matters, rather than the span.

      var band = {
        "type" : "Polygon",
        "coordinates" : [
          [
            [-170, 10 ],
            [-85, 10 ],
            [0, 10 ],
            [85, 10 ],
            [170, 10 ],
            [170, -10 ],
            [85, -10 ],
            [0, -10 ],
            [-85, -10 ],
            [-170, -10 ],
            [-170, 10 ]
          ]
        ]
      }
       
      var coll = db.geo_hemisphere;
      coll.drop();
      assert.writeOK(coll.insert({loc: [0, 0]}));
      assert.commandWorked(coll.ensureIndex({loc: "2dsphere"}));
       
      assert.eq(1, coll.find({loc: { $geoWithin: {$geometry: band}}}).count());

      Attachments

        Activity

          People

            kay.kim@mongodb.com Kay Kim (Inactive)
            siyuan.zhou@mongodb.com Siyuan Zhou
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              9 years, 10 weeks, 1 day ago