0

In MongoDB I have created a database named 'GIS' and a collection named 'UTILITIES' and within the collection I have inserted a BSON document as below.

{ 
"_id" : ObjectId("54e6b3ca7e550c1f4c2b47f6"), 
"features" : [
    {
        "id" : "1", 
        "geometry" : {
            "coordinates" : [
                86.74957, 
                21.93157
            ], 
            "type" : "Point", 
            "crs" : null, 
            "bbox" : [
                86.74957, 
                21.93157, 
                86.74957, 
                21.93157
            ]
        }, 
        "properties" : {
            "PLACE" : "Abhoy Medical Store", 
            "LATITUDE" : "21.93157", 
            "LONGITUDE" : "86.74957", 
            "IMG" : "43400012"
        }, 
        "type" : "Feature", 
        "crs" : null, 
        "bbox" : [
            86.74957, 
            21.93157, 
            86.74957, 
            21.93157
        ]
    }, 
    {
        "id" : "2", 
        "geometry" : {
            "coordinates" : [
                86.73604, 
                21.92578
            ], 
            "type" : "Point", 
            "crs" : null, 
            "bbox" : [
                86.73604, 
                21.92578, 
                86.73604, 
                21.92578
            ]
        }, 
        "properties" : {
            "PLACE" : "Advanced Homeo Sadan", 
            "LATITUDE" : "21.92578", 
            "LONGITUDE" : "86.73604", 
            "IMG" : "43400123"
        }, 
        "type" : "Feature", 
        "crs" : null, 
        "bbox" : [
            86.73604, 
            21.92578, 
            86.73604, 
            21.92578
        ]
    }
    ], 
"type" : "FeatureCollection", 
"crs" : null, 
"bbox" : [
    86.71509, 
    21.91163, 
    86.79117, 
    21.95772
]
}

The document is actually a GeoJSON. I tried creating an index as

db.UTILITIES.ensureIndex ({"features.geometry" : "2dsphere"})

which returns errmsg

{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"ok" : 0,
"errmsg" : "Can't extract geo keys from object, malformed geometry?: { _id: ObjectId('54e6b3ca7e550c1f4c2b47f6'), features: [ { id: \"1\", geometry: { coordinates: [ 86.74957000000001, 21.93157 ], type: \"Point\", crs: null, bbox: [ 86.74957000000001, 21.93157, 86.74957000000001, 21.93157 ] }, properties: { PLACE: \"Abhoy Medical Store\", LATITUDE: \"21.93157\", LONGITUDE: \"86.74957\", IMG: \"43400012\" }, type: \"Feature\", crs: null, bbox: [ 86.74957000000001, 21.93157, 86.74957000000001, 21.93157 ] }, { id: \"2\", geometry: { coordinates: [ 86.73604, 21.92578 ], type: \"Point\", crs: null, bbox: [ 86.73604, 21.92578, 86.73604, 21.92578 ] }, properties: { PLACE: \"Advanced Homeo Sadan\", LATITUDE: \"21.92578\", LONGITUDE: \"86.73604\", IMG: \"43400123\" }, type: \"Feature\", crs: null, bbox: [ 86.73604, 21.92578, 86.73604, 21.92578 ] } ], type: \"FeatureCollection\", crs: null, bbox: [ 86.71509, 21.91163, 86.79116999999999, 21.95772 ] }",
"code" : 16755
}

I have checked the longitude and latitude order which is ok.

Kindly provide a wayout. Thanks in advance.

4

2 回答 2

1

这不是 GeoJSON。该features.geometry字段应该是 GeoJSON,但也不是 GeoJSON,因为您有一个带有 null 值的额外键:

"geometry" : {
        "coordinates" : [
            86.74957, 
            21.93157
        ], 
        "type" : "Point",
        "crs" : null,        // not valid
        "bbox" : [           
            86.74957,
            21.93157,      
            86.74957, 
            21.93157
        ]
    }

如果您从 GeoJSON 字段中删除额外的键,则地理索引的创建不会出错。

您可以使用GeoJSON Lint非常可靠地验证 GeoJSON 。

于 2015-02-20T07:45:02.057 回答
0

我删除了包含空数据的字段。在我的例子中,它的"crs" : null, . 并且索引创建成功。

于 2015-02-20T10:11:31.117 回答