在MongoDB中,我创建了一个名为“GIS”的数据库和一个名为“UTILITIES”的集合,并在集合中插入了一个BSON文档,如下所示。
{
"_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
]
}
该文档实际上是一个GeoJSON。 我尝试创建一个索引
db.UTILITIES.ensureIndex ({"features.geometry" : "2dsphere"})
返回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
}
我检查了经度和纬度顺序,这是好的。
请提供一个出路。提前谢谢。
答案 0 :(得分:1)
它不是GeoJSON。 features.geometry
字段,应该是GeoJSON,不是GeoJSON,因为你有一个带空值的额外键:
"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。
答案 1 :(得分:0)
我删除了包含空数据的字段。在我的情况下,它的“crs”:null,。 并且索引创建成功。