[SERVER-26105] $geoIntersects query fails when a polygon around (0,0) is queried Created: 14/Sep/16  Updated: 14/Sep/16  Resolved: 14/Sep/16

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

Type: Bug Priority: Minor - P4
Reporter: Zohar Bar-Yehuda Assignee: Kelsey Schubert
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

Run a $geoIntersects query with a polygon circling around (0,0)

Participants:

 Description   

Running the following query on a 2dsphere index:

{ "tags.name" : { "$exists" : true} , "loc" : { "$geoIntersects" : { "$geometry" : { "type" : "Polygon" , "coordinates" : [ [ [ 1.7834514204456963E-4 , 6.102440130139471E-7] , [ 1.7488909954756064E-4 , 3.570003235196329E-5] , [ 1.646537858315228E-4 , 6.944133980362683E-5] , [ 1.4803253826253338E-4 , 1.0053750684498035E-4] , [ 1.256641020633656E-4 , 1.27793525215556E-4] , [ 9.840808369278992E-5 , 1.5016196141472382E-4] , [ 6.73119166514364E-5 , 1.6678320898371325E-4] , [ 3.3570609199772854E-5 , 1.7701852269975108E-4] , [ -1.5191791391765005E-6 , 1.8047456519676007E-4] , [ -3.660896747812585E-5 , 1.7701852269975108E-4] , [ -7.03502749297894E-5 , 1.6678320898371325E-4] , [ -1.0144644197114289E-4 , 1.5016196141472385E-4] , [ -1.287024603417186E-4 , 1.2779352521555604E-4] , [ -1.510708965408864E-4 , 1.0053750684498035E-4] , [ -1.6769214410987583E-4 , 6.944133980362686E-5] , [ -1.7792745782591366E-4 , 3.570003235196336E-5] , [ -1.8138350032292265E-4 , 6.102440130139692E-7] , [ -1.7792745782591366E-4 , -3.447954432593542E-5] , [ -1.6769214410987585E-4 , -6.822085177759893E-5] , [ -1.5107089654088643E-4 , -9.931701881895242E-5] , [ -1.2870246034171862E-4 , -1.265730371895281E-4] , [ -1.0144644197114293E-4 , -1.489414733886959E-4] , [ -7.035027492978951E-5 , -1.655627209576853E-4] , [ -3.660896747812594E-5 , -1.7579803467372316E-4] , [ -1.5191791391765446E-6 , -1.7925407717073215E-4] , [ 3.357060919977285E-5 , -1.7579803467372316E-4] , [ 6.731191665143643E-5 , -1.655627209576853E-4] , [ 9.840808369278984E-5 , -1.4894147338869593E-4] , [ 1.2566410206336554E-4 , -1.2657303718952815E-4] , [ 1.4803253826253338E-4 , -9.931701881895246E-5] , [ 1.6465378583152275E-4 , -6.822085177759905E-5] , [ 1.7488909954756064E-4 , -3.447954432593549E-5] , [ 1.7834514204456963E-4 , 6.102440130139031E-7]]]}}} , "valid" : true}

on a table with the index:

  {
                "v" : 1,
                "key" : {
                        "valid" : 1,
                        "loc" : "2dsphere"
                },
                "name" : "valid_1_loc_2dsphere",
                "ns" : "osm.osm_ways",
                "background" : true,
                "2dsphereIndexVersion" : 3
        }

Results in the following error:

com.mongodb.MongoException: Can't canonicalize query: BadValue: Loop is not closed: [ [ 0.0001783451420445696, 6.102440130139471e-07 ], [ 0.0001748890995475606, 3.570003235196329e-05 ], [ 0.0001646537858315228, 6.944133980362683e-05 ], [ 0.0001480325382625334, 0.0001005375068449803 ], [ 0.0001256641020633656, 0.000127793525215556 ], [ 9.840808369278992e-05, 0.0001501619614147238 ], [ 6.73119166514364e-05, 0.0001667832089837132 ], [ 3.357060919977285e-05, 0.0001770185226997511 ], [ -1.519179139176501e-06, 0.0001804745651967601 ], [ -3.660896747812585e-05, 0.0001770185226997511 ], [ -7.03502749297894e-05, 0.0001667832089837132 ], [ -0.0001014464419711429, 0.0001501619614147238 ], [ -0.0001287024603417186, 0.000127793525215556 ], [ -0.0001510708965408864, 0.0001005375068449803 ], [ -0.0001676921441098758, 6.944133980362686e-05 ], [ -0.0001779274578259137, 3.570003235196336e-05 ], [ -0.0001813835003229227, 6.102440130139692e-07 ], [ -0.0001779274578259137, -3.447954432593542e-05 ], [ -0.0001676921441098759, -6.822085177759893e-05 ], [ -0.0001510708965408864, -9.931701881895242e-05 ], [ -0.0001287024603417186, -0.0001265730371895281 ], [ -0.0001014464419711429, -0.0001489414733886959 ], [ -7.035027492978951e-05, -0.0001655627209576853 ], [ -3.660896747812594e-05, -0.0001757980346737232 ], [ -1.519179139176545e-06, -0.0001792540771707322 ], [ 3.357060919977285e-05, -0.0001757980346737232 ], [ 6.731191665143643e-05, -0.0001655627209576853 ], [ 9.840808369278984e-05, -0.0001489414733886959 ], [ 0.0001256641020633655, -0.0001265730371895281 ], [ 0.0001480325382625334, -9.931701881895246e-05 ], [ 0.0001646537858315227, -6.822085177759905e-05 ], [ 0.0001748890995475606, -3.447954432593549e-05 ], [ 0.0001783451420445696, 6.102440130139031e-07 ] ]

I have double checked, the polygon is closed, but what's special about it is that it's exactly around (0,0), so that both the latitude and longitude change signs. I'm guessing this is the cause for the bug.



 Comments   
Comment by Zohar Bar-Yehuda [ 14/Sep/16 ]

Real sorry...
Plotted it and looked at the coordinates but missed the tiny difference. Looks like some round-off error in my code, which is only triggered with this (0,0) scenario.

Anyway, thanks for your quick response.

Comment by Kelsey Schubert [ 14/Sep/16 ]

Hi zoharby,

Thank you for the report. A valid polygon must have first and last coordinates specify the same position. It appears that this polygon is not closed as the first position does not match the last:

  [ 1.7834514204456963E-4 , 6.102440130139471E-7]  
- [ 1.7834514204456963E-4 , 6.102440130139031E-7] 
= [ 0                     , 0.000000000000440E-7]

Kind regards,
Thomas

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