[SERVER-39657] BigPolygons $geoIntersects , areas greater than single hemisphere Created: 19/Feb/19  Updated: 27/Oct/23  Resolved: 06/Aug/19

Status: Closed
Project: Core Server
Component/s: Geo
Affects Version/s: 4.0.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: PL [X] Assignee: Danny Hatcher (Inactive)
Resolution: Works as Designed Votes: 0
Labels: query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File REGIONS.json     PNG File image (1).png     PNG File image.png    
Issue Links:
Documented
is documented by DOCS-12941 Clarify Big Polygon coordinates must ... Closed
Operating System: ALL
Sprint: Query 2019-08-12
Participants:

 Description   

Hi,
 
 
"The custom MongoDB CRS uses a counter-clockwise winding order and allows $geoIntersects to support queries with a single-ringed GeoJSON polygon whose area is greater than or equal to a single hemisphere. If the specified polygon is smaller than a single hemisphere, the behavior of $geoIntersectswith the MongoDB CRS is the same as with the default CRS. See also “Big” Polygons."

{
  <location field>: {
     $geoIntersects: {
        $geometry: {
           type: "Polygon" ,
           coordinates: [ <coordinates> ],
           crs:

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

           }
        }
     }
  }
}
 
I want to make $geoIntersects queries for Geojson kept in database that intersects the Polygon. However, the the area can be greater than a single hemisphere or not. For that I have to use the crs property highlighted above.
 
https://docs.mongodb.com/manual/reference/operator/query/geoIntersects/ says that "the behavior of $geoIntersectswith the MongoDB CRS is the same as with the default CRS", but if I keep the custom Crs property , and the area is smaller than a single hemisphere I get the intersections from the complementary area. So it seems not to keep the defautl crs behaviour for areas smaller than a single hemisphere.
 
 
 
Can you help on this issue please?



 Comments   
Comment by Danny Hatcher (Inactive) [ 06/Aug/19 ]

I've opened DOCS-12941 to clarify that all queries and data must have coordinates listed counter-clockwise for Big Polygons. As everything is working correctly, I will close this ticket as Working as Designed.

Comment by Craig Homa [ 08/Jul/19 ]

Scheduling into a sprint so someone can take a further look at what is really going on here.

Comment by PL [X] [ 12/Mar/19 ]

Hi Eric,,

your comment from 06 Mar 2019 06:39:09 PM solved my problem.

Comment by Eric Sedor [ 06/Mar/19 ]

The SERVER project is for bug reports and feature requests. Unfortunately it is not the place for clarifying how MongoDB or geospatial coordinate reference systems work.

Again, for support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-user group.

Comment by PL [X] [ 06/Mar/19 ]

Hi Eric, thank you for your answer,

 

To clarify, should I always use counter-clockwise winding order and "urn:x-mongodb:crs:strictwinding:EPSG:4326" CRS property?

Can you confirm that If  always using counter-clockwise winding order and if  it is not a big polygon, MongoDB behaves as default CRS , regardless of specifying "urn:x-mongodb:crs:strictwinding:EPSG:4326" property in the query? and if it is a big polygon it behaves as expected?

 

I have no means of identifiying correctly big polygons (areas greater than a single hemisphere).

 

Comment by Eric Sedor [ 06/Mar/19 ]

MongoDB2018PB we are not seeing anything to indicate a bug yet.

Please check out this blog for some guidance.

One thing that may be leading you to see unexpected results is that the polygons in your queries are specified in clockwise winding order. For expected results with big polygons and the "urn:x-mongodb:crs:strictwinding:EPSG:4326" CRS, queries and data should use counter-clockwise winding order.

But for support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-user group.

Comment by PL [X] [ 06/Mar/19 ]

Hi Eric,

 

Any news on this issue? It is really important as some developments depend on this MongoDB feature.

 

Best

Comment by PL [X] [ 28/Feb/19 ]

db.getCollection('App').aggregate([ { "$match" : { "version.status" : "A" , "$and" : [{ "Y" : "XXX"}, { "version.number" : "1"}]}} , { "$sort" : { "version.date" : -1}} , { "$limit" : 1} , { "$unwind" : "$region.place"} , { "$match" : { "region.place.fence" : { "$geoIntersects" : { "$geometry" :
 
{ "type" : "Polygon" , "coordinates" : [ [ [ -80.65646219998598 , 79.85312694622819] , [ 130.45321181416512 , 
79.85312694622819] , [ 130.45321181416512 , -68.52351256702978] , 
[ -80.65646219998598 , -68.52351256702978] , [ -80.65646219998598 , 79.85312694622819]]]
,
"crs":{ "type": "name", "properties": \{ "name": "urn:x-mongodb:crs:strictwinding:EPSG:4326" }}}}}}} , { "$group" : { "_id" : "$region.place"}}])

I get the same number of countries whether I use "crs" or not.

It could happen I would receive 25 countries with the polygon {{"[[[ -80.65646219998598 , 79.85312694622819] , [ 130.45321181416512 ,
79.85312694622819] , [ 130.45321181416512 , -68.52351256702978] ,
[ -80.65646219998598 , -68.52351256702978] , [ -80.65646219998598 , 79.85312694622819]]]"}} if the area would be greater than a single hemisphere. However these coordinates intersect the 180º meridian. I know that because I inserted a LineString

 "fence" :{ "type" : "LineString", "coordinates" : [ [ 180.0, 90.0 ], [ 180.0, -90.0 ] ] }

 and I get the intersection of the polygon with the LineString. So it might mean that instead of intersecting with the smallest rectangle in the map, it is intersecting with the biggest rectangle that includes the 25 countries. The thing is that if I use the crs I get the same results, 25 countries. So it does not make sense. 

Comment by Eric Sedor [ 27/Feb/19 ]

Thanks for all the information so far MongoDB2018PB. We're still investigating and appreciate your patience.

Comment by PL [X] [ 25/Feb/19 ]

I enclose the document for the queries: REGIONS.json

Comment by PL [X] [ 25/Feb/19 ]

Hi, 

 I enclose a document.

The first query returns all visible countries. The second query returns all countries (25) but the ones visible in the map.

Comment by Eric Sedor [ 25/Feb/19 ]

MongoDB CRS should behave the same as the default CRS when the polygon is smaller than a single hemisphere. To investigate the possibility of a bug, we'd want to see a specific document that you expect to be returned for both of the above queries but which is only being returned for the first.

Importantly, the SERVER project is for reporting bugs and feature requests. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-user group.

Comment by PL [X] [ 22/Feb/19 ]

If I make the following aggregation I get the intersection with all the countries visible in map:

 

[ { "$match" : { "version.status" : "A" , "$and" : [{ "Y" : "XXX"}, { "version.number" : "1"}]}} , { "$sort" : { "version.date" : -1}} , { "$limit" : 1} , { "$unwind" : "$region.place"} , { "$match" : { "region.place.fence" : { "$geoIntersects" : { "$geometry" : { "type" : "Polygon" , "coordinates" : [ [ [ -36.57112330198288 , 75.86871204077615] , [ 58.03005807101726 , 75.86871204077615] , [ 58.03005807101726 , -26.458180414737257] , [ -36.57112330198288 , -26.458180414737257] , [ -36.57112330198288 , 75.86871204077615]]]}}}}} , { "$group" : { "_id" : "$region.place"}}]

 When I rotate the map nearly 45º (using google maps) :

[ { "$match" : { "version.status" : "A" , "$and" : [{ "Y" : "XXX"}, { "version.number" : "1"}]}} , { "$sort" : { "version.date" : -1}} , { "$limit" : 1} , { "$unwind" : "$region.place"} , { "$match" : { "region.place.fence" : { "$geoIntersects" : { "$geometry" : { "type" : "Polygon" , "coordinates" : [ [ [ -80.65646219998598 , 79.85312694622819] , [ 130.45321181416512 , 79.85312694622819] , [ 130.45321181416512 , -68.52351256702978] , [ -80.65646219998598 , -68.52351256702978] , [ -80.65646219998598 , 79.85312694622819]]]}}}}} , { "$group" : { "_id" : "$region.place"}}]

I no longer get the intersections.  Why does not MongoDB identify the intersections if they are included in the coordinates

Comment by PL [X] [ 21/Feb/19 ]

Hi,

I wanted to know if the custom Crs strict winding has the same behavior as the default crs when the area is less than a single hemisphere ,i.e., if it changes the behavior to default in areas less than single hemisphere .

I am also working with google maps and if I rotate the map more than 15 degrees mongodb does not intersect the google map GeoJsonPolygon with the areas kept in database when I use geointersects.

How to know if the fence is greater than a single hemisphere ? I have an app making requests to mongodb database and if I need to know beforehand if the area exceeds an hemisphere it will not be accurate because I have no exact means is calculating the exact area of the GeoJsonPolygon.

Mongo driver 3.10.1 , dB.version() 4.0.0.

Comment by Eric Sedor [ 21/Feb/19 ]

Thanks for writing in. We have a few questions:

Can you clarify what MongoDB version you are running?

Do we understand correctly that you are observing a case in which "If the specified polygon is smaller than a single hemisphere, the behavior of $geoIntersects with the MongoDB CRS is the same as with the default CRS." is not accurate?

Are you able to provide a specific operation and the results you are observing that you don't expect?

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