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

geoWithin not returning correct data

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Integration
    • ALL
    • Hide

      Here is an example collection

      db.geo_json_test.insertMany([{name: "00A", location: {type: "Point", coordinates: [-81.09670311007132, 46.575020657518266]}},{name: "147", location: {type: "Point", coordinates: [-81.067788, 46.3822689]}},{name: "001", location: {type: "Point", coordinates: [-92.16504975147868, 66.85083025648714]}},{name: "002", location: {type: "Point", coordinates: [-80.9422811, 46.512260000000005]}},{name: "000", location: {type: "Point", coordinates: [-80.942295, 46.51226270000001]}},{name: "008", location: {type: "Point", coordinates: [-81.09670311007132, 46.575020657518266]}},{name: "007", location: {type: "Point", coordinates: [-81.09653748648944, 46.575012427925024]}},{name: "006", location: {type: "Point", coordinates: [-81.0972791024576, 46.57375187851832]}},{name: "005", location: {type: "Point", coordinates: [-81.101199979413, 46.56988771702767]}},{name: "004", location: {type: "Point", coordinates: [-81.05537133207827, 46.56975708845099]}},{name: "003", location: {type: "Point", coordinates: [-81.09831646261244, 46.57729676918206]}},{name: "02", location: {type: "Point", coordinates: [-81.07875689437888, 46.56184186179797]}}])

       

      The following query to the collection returns all points

      db.geo_json_test.find({'$and': [{'location': {'$geoWithin': {'$geometry': {'type': 'Polygon', 'coordinates': [[[-13, 71], [-161, 71], [-161, 16], [-13, 16], [-13, 71]]]}}}}]})

       

      However, the following query which is changing the longitude by 1 unit further to the east returns only one point. This polygon is a little bigger than the previous one and should include all the points that were included in the previous one

      db.geo_json_test.find({'$and': [{'location': {'$geoWithin': {'$geometry': {'type': 'Polygon', 'coordinates': [[[-12, 71], [-161, 71], [-161, 16], [-12, 16], [-12, 71]]]}}}}]})

      Show
      Here is an example collection db.geo_json_test.insertMany([{name: "00A", location: {type: "Point", coordinates: [-81.09670311007132, 46.575020657518266] }},{name: "147", location: {type: "Point", coordinates: [-81.067788, 46.3822689] }},{name: "001", location: {type: "Point", coordinates: [-92.16504975147868, 66.85083025648714] }},{name: "002", location: {type: "Point", coordinates: [-80.9422811, 46.512260000000005] }},{name: "000", location: {type: "Point", coordinates: [-80.942295, 46.51226270000001] }},{name: "008", location: {type: "Point", coordinates: [-81.09670311007132, 46.575020657518266] }},{name: "007", location: {type: "Point", coordinates: [-81.09653748648944, 46.575012427925024] }},{name: "006", location: {type: "Point", coordinates: [-81.0972791024576, 46.57375187851832] }},{name: "005", location: {type: "Point", coordinates: [-81.101199979413, 46.56988771702767] }},{name: "004", location: {type: "Point", coordinates: [-81.05537133207827, 46.56975708845099] }},{name: "003", location: {type: "Point", coordinates: [-81.09831646261244, 46.57729676918206] }},{name: "02", location: {type: "Point", coordinates: [-81.07875689437888, 46.56184186179797] }}])   The following query to the collection returns all points db.geo_json_test.find({'$and': [{'location': {'$geoWithin': {'$geometry': {'type': 'Polygon', 'coordinates': [[ [-13, 71] , [-161, 71] , [-161, 16] , [-13, 16] , [-13, 71] ]]}}}}]})   However, the following query which is changing the longitude by 1 unit further to the east returns only one point. This polygon is a little bigger than the previous one and should include all the points that were included in the previous one db.geo_json_test.find({'$and': [{'location': {'$geoWithin': {'$geometry': {'type': 'Polygon', 'coordinates': [[ [-12, 71] , [-161, 71] , [-161, 16] , [-12, 16] , [-12, 71] ]]}}}}]})
    • QI 2023-07-24, QI 2023-08-07, QI 2023-08-21, QI 2023-09-04, QI 2023-09-18

      The geoWithin query is not returning the data as expected. I have looked at large polygons mentioned here 
      https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/#std-label-geowithin-big-poly
       
      The polygons used however, are not large enough to cover the area of a hemisphere. See the example data and query.
       
      As we increase the polygon sizes up to a certain point the data is returned correctly however going bigger by one longitude unit returns incorrect data.
       
      For completeness though I have tried with
       

      crs: {
      type: "name",
      properties: { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" }
      }

       
      and get the same results.
       
      Can you please identify the mistake here. 

            Assignee:
            will.buerger@mongodb.com Will Buerger
            Reporter:
            khalidbashirbajwa@gmail.com Khalid Bashir Bajwa
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: