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

Cannot insert GeoJSON polygon with colinear edges

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.22, 4.2.10
    • Component/s: Geo
    • Labels:
    • Environment:
      standalone server 3.2, Atlas 4.2.10
    • Query Integration
    • ALL
    • Hide

      db.data.createIndex(

      { "geom": "2dsphere" }

      ,

      { "2dsphereIndexVersion": 3 }

      );

      db.data.insertOne({
      geom:

      { "type": "Polygon", "coordinates": [ [ [ -157.515, 4.937 ], [ -142.529, -89.999 ], [ -142.529, -43.676 ], [ -12.529, -42.767 ], [ -142.529, -6.001 ], [ -142.529, 50.047 ], [ -157.515, 4.937 ] ] ] }

      });

      Show
      db.data.createIndex( { "geom": "2dsphere" } , { "2dsphereIndexVersion": 3 } ); db.data.insertOne({ geom: { "type": "Polygon", "coordinates": [ [ [ -157.515, 4.937 ], [ -142.529, -89.999 ], [ -142.529, -43.676 ], [ -12.529, -42.767 ], [ -142.529, -6.001 ], [ -142.529, 50.047 ], [ -157.515, 4.937 ] ] ] } });
    • Query 2021-01-11

      Inserting what seems like a perfectly valid CCW polygon (checked in QGIS, geojsonlint.com, geojson.io) results in this error:

      MongoError: Can't extract geo keys: \{ _id: ObjectId('5fb4fbe26a989905900a0f90'), geom: { type: "Polygon", coordinates: [ [ [ -157.515, 4.937 ], [ -142.529, -89.999 ], [ -142.529, -43.676 ], [ -12.529, -42.767 ], [ -142.529, -6.001 ], [ -142.529, 50.047 ], [ -157.515, 4.937 ] ] ] } } Loop is not valid: [ [ 157.515, 4.937 ], [ -142.529, -89.999 ], [ -142.529, -43.676 ], [ -12-.-529, -42.767 ], [ -142.529, -6.001 ], [ -142.529, 50.047 ], [ -157.515, 4.937 ] ] *Edges 1 and 4 cross. Edge locations in degrees: [-142.5290000, -89.9990000]**[-142.5290000, -43.6760000] and [-142.5290000, -6.0010000]-[-142.5290000, 50.0470000]*
      

      But those two offending collinear edges are not even touching.

       

      I guess it boils down to this line in the S2 library:

      https://github.com/mongodb/mongo/blob/master/src/third_party/s2/s2loop.cc#L148
       

            Assignee:
            backlog-query-integration [DO NOT USE] Backlog - Query Integration
            Reporter:
            ales.pecha@email.cz Ales Pecha
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: