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

Geospatial queries over GeoJSONs return wrong results

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Done
    • Affects Version/s: 4.2.6, 4.4.4
    • Fix Version/s: None
    • Component/s: Geo, Index Maintenance, Querying
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      In the following example, I have some stored polygons located over the Baltic sea (between Sweden and Finland). Whenever I draw a polygon over the area where the polygons lie, they are correctly detected, namely all 609 objects are found. (see query and Screenshot_1)

      db.geojsons.find({
        location: {
          $geoIntersects: {
            $geometry: {
              type: "Polygon",
              coordinates: [
                [ [17.314453, 61.648162], [17.314453, 64.434892], [26.542969, 64.434892], [26.542969, 61.648162], [17.314453, 61.648162], ],
              ],
            },
          },
        },
      });
      

      However, the strange behavior occurs when submitting a wider query polygon a little bit below (see Screenshot 2 and 3 with the corresponding queries).

      db.geojsons.find({
        location: {
          $geoIntersects: {
            $geometry: {
              type: "Polygon",
              coordinates: [
                [ [-4.482422, 61.93895], [46.318359, 61.93895], [46.318359, 58.585436], [-4.482422, 58.585436], [-4.482422, 61.93895], ],
              ],
            },
          },
        },
      });
      

      As well as:

      db.geojsons.find({
        location: {
          $geoIntersects: {
            $geometry: {
              type: "Polygon",
              coordinates: [
                [ [-4.482422, 61.93895], [36.318359, 61.93895], [36.318359, 58.585436], [-4.482422, 58.585436], [-4.482422, 61.93895], ],
              ],
            },
          },
        },
      });
      

       

      Hereby, I also attach three example GeoJSONs that I use:

      {
        type: "Feature",
        location: {
          type: "Polygon",
          coordinates: [
            [
              [20.9995991794984, 63.4348461784678],
              [20.9995991794984, 63.4240745387888],
              [21.0236395339339, 63.4240745387888],
              [21.0236395339339, 63.4348461784678],
              [20.9995991794984, 63.4348461784678],
            ],
          ],
        },
        properties: { acquisitionDate: ISODate("2017-01-13T09:10:31Z") },
        _class: "com.models.database.GeoJson",
      };
       
      {
        type: "Feature",
        location: {
          type: "Polygon",
          coordinates: [
            [
              [20.9995993299129, 63.424076492091],
              [20.9995993299129, 63.413304836971],
              [21.0236306669723, 63.413304836971],
              [21.0236306669723, 63.424076492091],
              [20.9995993299129, 63.424076492091],
            ],
          ],
        },
        properties: { acquisitionDate: ISODate("2017-01-13T09:10:31Z") },
        _class: "com.models.database.GeoJson",
      };
       
      {
        type: "Feature",
        location: {
          type: "Polygon",
          coordinates: [
            [
              [20.9995994802004, 63.4133067893598],
              [20.9995994802004, 63.4025351187936],
              [21.0236218074932, 63.4025351187936],
              [21.0236218074932, 63.4133067893598],
              [20.9995994802004, 63.4133067893598],
            ],
          ],
        },
        properties: { acquisitionDate: ISODate("2017-01-13T09:10:31Z") },
        _class: "com.models.database.GeoJson",
      };
      

       

      Thank you in advance!

      Show
      In the following example, I have some stored polygons located over the Baltic sea (between Sweden and Finland). Whenever I draw a polygon over the area where the polygons lie, they are correctly detected, namely all 609 objects are found. (see query and Screenshot_1) db.geojsons.find({ location: { $geoIntersects: { $geometry: { type: "Polygon", coordinates: [ [ [17.314453, 61.648162], [17.314453, 64.434892], [26.542969, 64.434892], [26.542969, 61.648162], [17.314453, 61.648162], ], ], }, }, }, }); However, the strange behavior occurs when submitting a wider query polygon a little bit below (see Screenshot 2 and 3 with the corresponding queries). db.geojsons.find({ location: { $geoIntersects: { $geometry: { type: "Polygon", coordinates: [ [ [-4.482422, 61.93895], [46.318359, 61.93895], [46.318359, 58.585436], [-4.482422, 58.585436], [-4.482422, 61.93895], ], ], }, }, }, }); As well as: db.geojsons.find({ location: { $geoIntersects: { $geometry: { type: "Polygon", coordinates: [ [ [-4.482422, 61.93895], [36.318359, 61.93895], [36.318359, 58.585436], [-4.482422, 58.585436], [-4.482422, 61.93895], ], ], }, }, }, });   Hereby, I also attach three example GeoJSONs that I use: { type: "Feature", location: { type: "Polygon", coordinates: [ [ [20.9995991794984, 63.4348461784678], [20.9995991794984, 63.4240745387888], [21.0236395339339, 63.4240745387888], [21.0236395339339, 63.4348461784678], [20.9995991794984, 63.4348461784678], ], ], }, properties: { acquisitionDate: ISODate("2017-01-13T09:10:31Z") }, _class: "com.models.database.GeoJson", };   { type: "Feature", location: { type: "Polygon", coordinates: [ [ [20.9995993299129, 63.424076492091], [20.9995993299129, 63.413304836971], [21.0236306669723, 63.413304836971], [21.0236306669723, 63.424076492091], [20.9995993299129, 63.424076492091], ], ], }, properties: { acquisitionDate: ISODate("2017-01-13T09:10:31Z") }, _class: "com.models.database.GeoJson", };   { type: "Feature", location: { type: "Polygon", coordinates: [ [ [20.9995994802004, 63.4133067893598], [20.9995994802004, 63.4025351187936], [21.0236218074932, 63.4025351187936], [21.0236218074932, 63.4133067893598], [20.9995994802004, 63.4133067893598], ], ], }, properties: { acquisitionDate: ISODate("2017-01-13T09:10:31Z") }, _class: "com.models.database.GeoJson", };   Thank you in advance!

      Description

      Hello everyone,

      I am currently working on a project, where I store polygons using the native GeoJSON format and then perform geospatial queries to locate these based on both $geoIntersects and $geoWithin operator. Indeed, everything seemed to be working fine.

      However, yesterday I discovered a strange behavior, which I am going to reproduce with an example.

        Attachments

        1. image-2021-03-08-08-58-51-496.png
          image-2021-03-08-08-58-51-496.png
          825 kB
        2. image-2021-03-08-08-59-10-527.png
          image-2021-03-08-08-59-10-527.png
          842 kB
        3. image-2021-03-08-09-00-46-731.png
          image-2021-03-08-09-00-46-731.png
          842 kB
        4. Screen Shot 2021-03-08 at 3.45.46 PM.png
          Screen Shot 2021-03-08 at 3.45.46 PM.png
          1.03 MB

          Activity

            People

            Assignee:
            edwin.zhou Edwin Zhou
            Reporter:
            paveldushev9@gmail.com Pavel Antonov
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: