[SERVER-14590] GeoQuery with BBOX near borders doesn't work Created: 17/Jul/14  Updated: 24/Jan/15  Resolved: 23/Jan/15

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

Type: Bug Priority: Major - P3
Reporter: Michael Quacinella [X] Assignee: Thomas Rueckstiess
Resolution: Incomplete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 14.04 , Mongo 2.6.3


Operating System: Linux
Steps To Reproduce:

1) create 2dsphere index (mine is a composite index, I didn't try with simple 2dsphere)
2) Populate your DB with a grid of rects like the classic long lat grid, e.g: a grid of rect with 1 unit side going from x=0,1,2,..180 , y=0,1..90 (my grid is not so regular but I think that won't effect the test)
3) execute geoquery like this. It should get all the geoJSON (here i use 179.5 and 89.5 as limits):

db.mycoll.find( { 
	geometry :{ 
		$geoIntersects : { 
			$geometry :  { 
				type : "Polygon" ,
				coordinates : [ [ [-179.5, -89.5] , [ -179.5, 89.5 ] ,[179.5,-89.5] , [ 179.5, -89.5 ], [-179.5, -89.5]   ] ]                       
			} 
		} 
	} 
} ).count()

5) compare it with db.mycoll.find().count()
6) also $geoWithin query doesn't work as expected
7) try on NE part of the world [0,0] , [179.9, 89.9] and look at the results.

Participants:

 Description   

If you try to find docs inside sphere limits (|x|<=179.9, |y|<89.9 as documentation says) you won't get expected results.
This bug affects also "borders query", like if you want query for NE side of the world you get wrong results. bbox ( [0,0] , [179.9, 89.9] )

Indexs:

db.mycoll.getIndexes()
[
	{
		"v" : 1,
		"key" : {
			"_id" : 1
		},
		"name" : "_id_",
		"ns" : "grid_cluster.mycoll"
	},
	{
		"v" : 1,
		"key" : {
			"geometry" : "2dsphere",
			"properties.rank" : -1
		},
		"name" : "geometry_2dsphere_properties.rank_-1",
		"ns" : "grid_cluster.mycoll",
		"2dsphereIndexVersion" : 2
	}
]

One of my geoJSON docs:

{ "_id" : ObjectId("53c11c778bfd09820bdc997c"), "type" : "Feature",  "geometry" : { "type" : "Polygon", "coordinates" : [ [ [ 180, -33.75 ], [ 168.75, -33.75 ], [ 168.75, -28.125 ], [ 180, -28.125 ], [ 180, -33.75 ] ] ] }, "properties" : {  "rank" : 0 } }



 Comments   
Comment by Ramon Fernandez Marina [ 07/Nov/14 ]

MikeQuaci, we haven't heard back from you for a while. If this is still an issue for you, can you please review Thomas' question above and provide the additional information he requested?

Thanks,
Ramón.

Comment by Thomas Rueckstiess [ 24/Jul/14 ]

Hi Michael,

I'm sorry, but I am not sure I understand what the issue is. Are you expecting more results back than you get? Please note that this is a 2dsphere index, so your queries are on a spherical surface. The lines are not straight but geodesics, therefore you won't get back exactly the grid objects as you would on a flat surface. If this is what you need, you can use a "2d" index instead of "2dsphere".

If this is not the issue you're describing, can you please add another example of what you expect and what you get back? You can also attach a drawing / sketch to the ticket (More - Attach File) if you have something handy.

Thanks,
Thomas

Comment by Michael Quacinella [X] [ 18/Jul/14 ]

Hi Thomas,

Yes, 1) is a writing error. Sorry.

I just reproduced the bug with this bbox:
[-123.0,31.0],[-123.0,66.0],[39.0,66.0],[39.0,31.0],[-123.0,31.0]
and also with this:
[-100,37],[-100,56],[-19,56],[-19,37],[-100,37]

It's all north hemisphere, and lines are shorter than 180 degrees.

If you need more details ask me everything you need,
Mike

Comment by Thomas Rueckstiess [ 17/Jul/14 ]

Hi Michael,

There are a few issues with your example.

  1. I suppose your query should cover the entire world, but there is a mistake in the 3rd coordinate, which is [179.5,-89.5] (same as 4th). I think you meant [179.5, 89.5], but even then, there are some more problems, see below.
  2. Lines > 180 degrees in a spherical CRS (i.e. GeoJSON default) are defined as shortest-path and therefore wrap the other way around the globe.
  3. You are trying to do a flat rectangle search across huge regions of the globe - this will be massively distorted and won't return the results you'd expect from a flat euclidian point of view
  4. GeoJSON doesn't have winding order defined, and so we can't search shapes > 1 hemisphere currently

Are you able to reproduce the problem in a small area of the world that doesn't span more than 1 hemisphere?

Regards,
Thomas

Comment by Michael Quacinella [X] [ 17/Jul/14 ]

There is an error in step 2, this would explain better the grid for testing:

for (x = -180, x < 180; x++) {
	minx=x; //west
	maxx=x+1; //east
	for (y = -90, y < 90; y++){
		miny=y; //south
		maxy=y+1; //north
 
		geoJSON= { 	"type": "Feature",
					"bbox": [minx, miny, maxx, maxy],
			        "geometry": {
			           "type": "Polygon",
			           "coordinates": [
			             [ [maxx, miny], [minx, miny], [minx, maxy],
	              		 [maxx, maxy], [maxx, miny] ]
	            		 ]
	            	}
	         };
     }
 
}

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