0
votes

I am using the geospacial feature of MongoDB.

I follow these directions to create a 2dsphere index

http://docs.mongodb.org/manual/tutorial/build-a-2dsphere-index/

However, when this polygon is in the collection, the index creation fails.

https://gist.github.com/anonymous/56345a0a96dd1e2c030e

The error is:

Can't extract geo keys from object, malformed geometry?:...

What is wrong with the polygon ?

1
You have NZ in your polygon twice. Maybe that causes the problem. make sure the polygon doesn't overlap itself. - Markus W Mahlberg

1 Answers

0
votes

There is nothing wrong with the polygon itself. The problem is that 2dsphere indexes, and related queries like $geoIntersects and $near only operate on polygons within one hemisphere, see the jira bug. It seems that the resolution to this bug was to update the documentation, see hemisphere restriction comments. There is a comment to this effect in the $geoIntersects documentation though not in the 2dsphere docs, it would seem.

Basically, the problem is that if you have a rectangle with longitude coordinates of, eg, -90, -90, 90 and 90 it is impossible to tell if this rectangle crosses in an East/West direction at 0 or 180/-180 (ie, the date line), so the results of any spatial operation would be indeterminate. In this case of your polygon, it could be inferred, and is obvious from visual inspection, but in general this is not the case, and hence the error.

You may also find this comparison from Boston GIS of spatial databases interesting. Note that Postgis, SQL Server and Oracle also have various restrictions on geometries/geographies that cross hemispheres.