5

When I try to create 2dsphere index in mongoDB i get this error msg:

> db.mahalle.createIndex({geometry:"2dsphere"})
{
        "createdCollectionAutomatically" : false,
        "numIndexesBefore" : 1,
        "errmsg" : "exception: Can't extract geo keys: { _id: ObjectId('55b4e025a6ef7e9c50ae79cd'), type: \"Feature\", p
roperties: { ADI: \"Çelemli\", ILADI: \"Adana\", ILCEADI: \"Yüre?ir\", BUCAKADI: \"Merkez\", KOYADI: \"Çelemli\", ILKOD:
 1 }, geometry: { type: \"Polygon\", coordinates: [ [ [ 35.624498, 36.849395 ], [ 35.649357, 36.876937 ], [ 35.657724, 3
6.879572 ], [ 35.663334, 36.873718 ], [ 35.668063, 36.875857 ], [ 35.671228, 36.87511 ], [ 35.676613, 36.872193 ], [ 35.
676789, 36.86627 ], [ 35.681188, 36.865075 ], [ 35.683002, 36.864582 ], [ 35.685911, 36.858289 ], [ 35.690937, 36.856315
 ], [ 35.698809, 36.857084 ], [ 35.70811, 36.84059 ], [ 35.703934, 36.838901 ], [ 35.669599, 36.82501 ], [ 35.65748, 36.
820107 ], [ 35.63049, 36.809188 ], [ 35.639549, 36.812853 ], [ 35.625102, 36.834434 ], [ 35.624498, 36.849395 ] ] ] } }
 Loop is not valid: [ [ 35.624498, 36.849395 ], [ 35.649357, 36.876937 ], [ 35.657724, 36.879572 ], [ 35.663334, 36.8737
18 ], [ 35.668063, 36.875857 ], [ 35.671228, 36.87511 ], [ 35.676613, 36.872193 ], [ 35.676789, 36.86627 ], [ 35.681188,
 36.865075 ], [ 35.683002, 36.864582 ], [ 35.685911, 36.858289 ], [ 35.690937, 36.856315 ], [ 35.698809, 36.857084 ], [
35.70811, 36.84059 ], [ 35.703934, 36.838901 ], [ 35.669599, 36.82501 ], [ 35.65748, 36.820107 ], [ 35.63049, 36.809188
], [ 35.639549, 36.812853 ], [ 35.625102, 36.834434 ], [ 35.624498, 36.849395 ] ] Edges 16 and 18 cross. Edge locations
in degrees: [35.6574800, 36.8201070]-[35.6304900, 36.8091880] and [35.6395490, 36.8128530]-[35.6251020, 36.8344340]",
        "code" : 16755,
        "ok" : 0
}
>

collection data looks like this:

> db.mahalle.findOne()
{
        "_id" : ObjectId("55b4e025a6ef7e9c50ae792f"),
        "type" : "Feature",
        "properties" : {
                "KOYADI" : "Ömerli",
                "ILKOD" : 1,
                "ADI" : "Ömerli",
                "ILADI" : "Adana",
                "ILCEADI" : "Pozanty",
                "BUCAKADI" : "Merkez"
        },
        "geometry" : {
                "type" : "Polygon",
                "coordinates" : [
                        [
                                [
                                        34.840791,
                                        37.516416
                                ],
                                [
                                        34.843066,
                                        37.525614
                                ],
                                [
                                        34.847284,
                                        37.545556
                                ],
                                [
                                        34.849961,
                                        37.602446
                                ],
                                [
                                        34.892618,
                                        37.570159
                                ],
                                [
                                        34.8991,
                                        37.559108
                                ],
                                [
                                        34.902859,
                                        37.545415
                                ],
                                [
                                        34.887897,
                                        37.508253
                                ],
                                [
                                        34.843046,
                                        37.489936
                                ],
                                [
                                        34.842049,
                                        37.501638
                                ],
                                [
                                        34.840791,
                                        37.516416
                                ]
                        ]
                ]
        }
}

I have to create 2dsphere index in order to search coordinate in Polygonal areas. How can i fix this? Thanks

Tom
  • 173
  • 2
  • 13
  • This document is fine. But the error suggests that another document may not be and actually tells you which one and the reasons why. Fix that document. – Blakes Seven Jul 26 '15 at 14:46
  • it's very difficult to do that because i have the whole city mapinfo. Is there a different way to fix that issue? – Tom Jul 26 '15 at 15:08
  • 1
    There really is no other way to fix your data other than to fix your data. You cannot create an index on data that is invalid. That is the point here. So if your source is invalid then it isn't going to be of much use to you anyway. – Blakes Seven Jul 26 '15 at 15:12
  • 1
    I asked a similar question here: http://gis.stackexchange.com/questions/199561/error-when-creating-spatial-index-in-mongodb but I've been unable to resolve this. Interestingly, I cannot get the data into mongodb without using jq to compact the features, but after compacting with jq the .geojson is invalid and I can't create the spatial index! And the geojson is valid (works fine in QGIS) before compacting with jq. Did you modify the data at all before inserting the data into mongo? – haff Jul 05 '16 at 23:12
  • anyone ever fix this? – Jeryl Cook Nov 02 '17 at 12:36
  • if you're happy to loose invalid records then there's a solution here - https://stackoverflow.com/questions/36776633/mongodb-error-code-16755-cant-extract-geo-keys-duplicate-vertices#answer-37686553 – Aidan Ewen Dec 08 '17 at 14:26

0 Answers0