[SERVER-45189] Allow strictwinding property also for inserted geometries ( or support geojson standard rfc7946) Created: 17/Dec/19  Updated: 27/Dec/23

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Damiano Barboni Assignee: Backlog - Query Integration
Resolution: Unresolved Votes: 1
Labels: qexec-team, qi-geo, query-product-urgency-3, query-product-value-2
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-15388 find 'big polygon' geo objects after ... Closed
is duplicated by SERVER-15388 find 'big polygon' geo objects after ... Closed
is duplicated by SERVER-47651 $geointersects does not work when pol... Closed
Related
is related to DOCS-12941 Clarify Big Polygon coordinates must ... Closed
Assigned Teams:
Query Integration
Sprint: 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
Participants:

 Description   

(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.



 Comments   
Comment by Xiaochen Wu [ 24/Feb/23 ]

discussed in product triage. send it to backlog

Comment by Eric Sedor [ 14/Feb/20 ]

Thanks for your patience Damiano,

After consideration we've opted to close SERVER-15388 as a duplicate of this request, and appreciate your submission. You can watch this ticket for updates as they become available.

Gratefully,
Eric

Comment by Eric Sedor [ 30/Dec/19 ]

Thanks for clarifying Damiano. I am investigating this ticket's relation to SERVER-15388. It's possible this is a duplicate but I want to make sure before proceeding with that assumption.

Comment by Damiano Barboni [ 19/Dec/19 ]

Dear Eric,

Thanks for your response

Mention the geojson standard rfc7946 introduce confusion and tickets have to be more atomic and focused.
It's my fault.

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

Damiano

Tested with MongoDB server version: 4.2.1

 

Comment by Eric Sedor [ 18/Dec/19 ]

Hi barboni@meeo.it,

I'd like to try to clarify part of this request. Are you asking for an insert option to specify a CRS?

If so, what behavior are you requesting? Given that rfc7946 specifies that "parsers SHOULD NOT reject Polygons that do not follow the right-hand rule." I'd like to understand what is missing when the currently available "urn:x-mongodb:crs:strictwinding:EPSG:4326" is provided. For example, are there specific geospatial operators that are performing incorrectly for you given counterclockwise data and counterclockwise queries?

I think part of the ambiguity is that the ordering requirement of the spec is not explicitly represented in the data. We do have DOCS-12941 open to clarify the need for clients to insert data with coordinates specified in a counterclockwise order.

What do you think?

Sincerely,
Eric

Generated at Thu Feb 08 05:08:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.