[SERVER-9346] Cannot query world with 2dsphere index Created: 13/Apr/13  Updated: 09/Jul/16  Resolved: 25/Apr/13

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

Type: Bug Priority: Major - P3
Reporter: William Newman Assignee: hari.khalsa@10gen.com
Resolution: Done Votes: 0
Labels: geo
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OSX


Issue Links:
Related
is related to DOCS-1391 2dsphere bounding polygon must be <= ... Closed
Operating System: OS X
Steps To Reproduce:

db.features.insert({loc:

{type: "Point", coordinates: [10, 10] }

} );
db.features.ensureIndex(

{"loc": "2dsphere"}

);
db.features.find( {loc: { $geoWithin: { $geometry:

{ type: "Polygon", coordinates: [ [ [-180,-90], [180,-90], [180,90], [-180,90], [-180,-90] ] ] }

} } });

Participants:

 Description   

I have stored some GeoJSON points in a collection, created a 2dsphere index. When I query the world I do not get back any of the points I created. I was not sure if the polygon had to be drawn in a certain direction (clockwise, counterclockwise), I tried both ways with no luck.



 Comments   
Comment by hari.khalsa@10gen.com [ 25/Apr/13 ]

MongoDB always assumes polygons are < hemisphere. Docs updated to mention this.

Comment by William Newman [ 19/Apr/13 ]

Dan, I read the same thing I think:

4.2.3.3.
What is the longest arc you can process?

We use great circle arcs as the "interpolation line" between two points. That means any two points are actually joined up two ways, depending on which direction you travel along the great circle. All our code assumes that the points are joined by the shorter of the two paths along the great circle. As a consequence, shapes that have arcs of more than 180 degrees will not be correctly modeled.

Which lead me to check out how PostGIS handled queries. I think in this case they are referring polygons stored/indexed in the database, not bounding polygons used to query.

Its also worth noting that drawing the polygon in either direction using PostGIS resulted in the correct behavior.

The bummer is that I could find nothing in their documentation stating the direction in which a bounding polygon should be drawn.

Also thanks a ton for updating the docs!

Comment by Daniel Pasette (Inactive) [ 18/Apr/13 ]

newmanw, I pasted the wrong link in the DOCS-1391 comment for postgis. I was referring to this item in their FAQ. I guess (from your examples) they are enforcing a clockwise winding of the points, but I can't find references to this in the docs.

Comment by William Newman [ 18/Apr/13 ]

From https://jira.mongodb.org/browse/DOCS-1391.

'Neither SQL Server nor PostGIS handle > 180° bounding polygons. aka, the "hemisphere limitation"'

I do not think that is true. PostGIS may limit the size of indexed polygons but does not limit polygons when querying.

Here are a couple examples of different queries in PostGIS.

– get all rows from feature table (just one for now)
SELECT feature_id, feature_name, ST_AsText(feature_geom) FROM feature;
feature_id | feature_name | st_astext
----------------------------------------------------
1 | Feature Test 1 | POINT(71.060316 48.432044)
(1 row)

– get all rows over the world with envelope
SELECT feature_id, feature_name, ST_AsText(feature_geom) FROM feature WHERE feature.feature_geom && ST_MakeEnvelope(-180,-90,180,90, 4326);
feature_id | feature_name | st_astext
----------------------------------------------------
1 | Feature Test 1 | POINT(71.060316 48.432044)
(1 row)

– get all rows over the world with geometry
SELECT feature_id, feature_name, ST_AsText(feature_geom) FROM feature WHERE feature.feature_geom && ST_MakePolygon(ST_GeomFromText('LINESTRING(-180 -90,180 -90,180 90,-180 90, -180 -90)'));
feature_id | feature_name | st_astext
----------------------------------------------------
1 | Feature Test 1 | POINT(71.060316 48.432044)
(1 row)

– sanity check with smaller polygon
SELECT feature_id, feature_name, ST_AsText(feature_geom) FROM feature WHERE feature.feature_geom && ST_MakePolygon(ST_GeomFromText('LINESTRING(-180 -90,-170 -90,-170 90,-180 90, -180 -90)'));
feature_id | feature_name | st_astext
---------------------------------
(0 rows)

Comment by William Newman [ 18/Apr/13 ]

Thanks Hari!

Some discussion here as well:
https://groups.google.com/forum/?fromgroups=#!topic/mongodb-user/D7ZMWdUnR5U

Comment by hari.khalsa@10gen.com [ 16/Apr/13 ]

Hi!

All geometries must fit within a hemisphere. If a geometry is "bigger" than a hemisphere, we interpret the geometry as the complimentary shape that is smaller. This is why your query isn't returning any results: we think you're asking for points in a very small area, where there probably are no points.

Think about a small polygon, say a little box, on the earth. This really defines two areas: the area inside the polygon, and the area outside of it. If you make this box bigger, say, bigger than half the earth, we're not sure which area you really want, so we choose the smallest area.

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