MongoDB 2dsphere error (distorted geometry?)

I'm currently trying to create a 2dsphere index, but the creation seems unsuccessful.

A document in which index creation fails is valid geojson (according to geojsonlint).

Also, as far as I can see, it obeys the MongoDB "Polygon" rules.

I would appreciate any help as I cannot understand why creating the index seems unsuccessful.

Thanks in advance!

db.poly.ensureIndex( { loc: "2dsphere" } ) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "ok" : 0, "errmsg" : "Can't extract geo keys from object, malformed geometry?: { _ id: 353, loc: { type: \"Polygon\", coordinates: [ [ [ 8.090732000000001, 53.6379 766 ], [ 8.050639500000001, 53.6250853 ], [ 8.036974600000001, 53.6286108 ], [ 7 .994035500000001, 53.6016978 ], [ 8.0120927, 53.59855020000001 ], [ 8.0102720000 00001, 53.5883803 ], [ 8.023379, 53.5867745 ], [ 8.0148004, 53.5832729 ], [ 8.02 6839500000001, 53.57895840000001 ], [ 8.0271685, 53.5727671 ], [ 8.0432450000000 01, 53.57190120000001 ], [ 8.0386477, 53.565241 ], [ 8.0192488, 53.5609644 ], [ 8.030192100000001, 53.5508096 ], [ 8.037298, 53.5565769 ], [ 8.041402400000001, 53.55249540000001 ], [ 8.030647100000001, 53.53854200000001 ], [ 8.0381080000000 01, 53.5275022 ], [ 8.048501400000001, 53.5243656 ], [ 8.051459700000001, 53.509 912 ], [ 8.091510100000001, 53.50258460000001 ], [ 8.153839000000001, 53.5148059 0000001 ], [ 8.1708242, 53.53993010000001 ], [ 8.164240300000001, 53.5287913 ], [ 8.1562255, 53.531339 ], [ 8.1700993, 53.54524050000001 ], [ 8.150740200000001, 53.5596328 ], [ 8.1539377, 53.56452330000001 ], [ 8.1408203, 53.58015880000001 ], [ 8.155694800000001, 53.5858101 ], [ 8.1496093, 53.60191990000001 ], [ 8.1234 503, 53.5984032 ], [ 8.090732000000001, 53.6379766 ] ] ] } }", "code" : 16755 } 
+6
source share
4 answers

There was an intersection in the coordinates, but I could not see it through geojsonlint.com, because it was not obvious!

MongoDB does not allow you to insert a polygon whose lines will intersect.

0
source

Apply the index to "loc" (the GeoJSON field) as you did. However, make sure your coordinates are in Longitude, Latitude (not Latitude, Longitude ).

In the documentation at http://docs.mongodb.org/manual/applications/geospatial-indexes/#spherical :

Store location data as GeoJSON objects with this coordinate axis in order: longitude, latitude. The coordinate system for GeoJSON uses the WGS84 database.

Also, in the GeoJSON specification at http://geojson.org/geojson-spec.html#positions :

The position is represented by an array of numbers. There should be less than two elements, and there may be more. The order of the elements must follow the x, y, z order (east, north, height for coordinates in the predicted coordinate system or longitude, latitude, height for coordinates in the geographic coordinate system). Any number of additional elements is allowed - the interpretation and meaning of additional elements is beyond the scope of this specification.

+2
source

This error occurs if you have multiple documents in your collection, and at least one of them contains a loc field as NULL or EMPTY.

So make sure you don’t have a document where the β€œloc” field is NULL or EMPTY.

Request: db.poly.find ("loc": {$ exists: true, $ eq: ""});

Note: You need to add the index to the "loc" field, not the "loc.coordinates" field.

0
source

Thus, the solution will simply build the index on loc.coordinates instead of loc

 db.coor.ensureIndex({"loc.coordinates": "2dsphere"}) 

Note. The 2d index supports a different format, which you can find in document . While loc not one of them.

I do not understand why you have a nested array.

-2
source

Source: https://habr.com/ru/post/970015/


All Articles