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

Allow strictwinding property also for inserted geometries ( or support geojson standard rfc7946)

    • Query Integration
    • Query 2020-11-30, Query 2020-12-14, Query 2020-12-28, Query 2021-01-11, Query 2021-01-25, Query Execution 2021-02-22

      (current description extracted from a comment below

      The problem is that currently  "urn:x-mongodb:crs:strictwinding:EPSG:4326" is available only for $geoWithin and $geoIntersects, as mentioned on the documentation https://docs.mongodb.com/manual/reference/operator/query/geometry/

      I can not specify this property when i insert a polygon and consequently i can not load on the database polygons larger than 180deg

      Let me provide an example of what, in my opinion, should be useful to have

      europe_asia_box=[[[-2,0], [179, 0], [179, 70],[-2, 70],[-2, 0]]]
      db.test_poly.insert({
        name: "europe_asia",
        loc: {
          type: "Polygon",
          coordinates: europe_asia_box,
          crs: { type: "name", properties: { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" } }
        }
      })
      

      Te query above return the erro:

      WriteResult({
      	"nInserted" : 0,
      	"writeError" : {
      		"code" : 16755,
      		"errmsg" : "Can't extract geo keys: { _id: ObjectId('5dfb426687f5bfdd73daa3dd'), name: \"europe_asia\", loc: { type: \"Polygon\", coordinates: [ [ [ -2.0, 0.0 ], [ 179.0, 0.0 ], [ 179.0, 70.0 ], [ -2.0, 70.0 ], [ -2.0, 0.0 ] ] ], crs: { type: \"name\", properties: { name: \"urn:x-mongodb:crs:strictwinding:EPSG:4326\" } } } }  can't index geometry with strict winding order"
      	}
      })
      

      If I omit the crs declaration the insert works but the polygon is not considered counterclockwise

      db.test_poly.insert({
        name: "big_polygon",
        loc: {
          type: "Polygon",
          coordinates: europe_asia_box 
        }
      })
      

      Example: search polygon over Europe return nothing
       

      search_europe=[[[20,40], [25,40], [25, 45],[20, 45],[20, 40]]]
      db.test_poly.find(
        {
          loc: {
            $geoIntersects: {
              $geometry: {
                type: "Polygon" ,
                coordinates: search_europe,
                crs: {
                  type: "name",
                  properties: { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" }
                }
              }
            }
          }
        }
      )
      

      Example search polygon over America return a record but is not expected, the inserter counterclockwise polygon is over aurope/asia

      search_america=[[[-105,40], [-100,40], [-100, 45],[-105, 45],[-105, 40]]]
      db.test_poly.find({
        loc: {
          $geoIntersects: {
            $geometry: {
              type: "Polygon" ,
              coordinates: search_america,
              crs: {
                type: "name",
                properties: { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" }
              }
            }
          }
        }
      }
      )
      
      { "_id" : ObjectId("5dfb42a287f5bfdd73daa3de"), "name" : "big_polygon", "loc" : { "type" : "Polygon", "coordinates" : [ [ [ -2, 0 ], [ 179, 0 ], [ 179, 70 ], [ -2, 70 ], [ -2, 0 ] ] ] } }
      

       
      For mongo the inserted polygon is "on the other side" of the globe.

      This appends every time I insert a polygon larger than 180deg. Mongo always close the ring considering the shorter way and i didn't find the possibility to force direction counterclockwise

      original description

      The latest geoJson standart rfc7946 define unambiguously how the polygon winding order have to be interpreted.

      With mongodb is not possible to insert polygon bigger than a single hemisphere and the property { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" } can be specified only for the $geoWithin and $geoIntersects operators

      It could be useful to support the rfc7946 standard and allow operators to specify this property when a new geometry is inserted or extend the existing "strictwinding" prototype also for inserted data and not only for the query operators.

            Assignee:
            backlog-query-integration [DO NOT USE] Backlog - Query Integration
            Reporter:
            barboni@meeo.it Damiano Barboni
            Votes:
            1 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: