本文介绍了如何将Geojson文件导入MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于Geojson是实际的json,所以我认为我可以使用mongoimport从.geojson文件将数据加载到我的MongoDB数据库中.
Since Geojson is actual json I thought i could to use mongoimport to load data into my MongoDB database from a .geojson file.
但是我遇到以下错误:
exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse: Expecting '{': offset:0
文件为25MB,它是其中的一部分:
The file is 25MB and this is a fragment of it:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": "node/2661561690",
"properties": {
"timestamp": "2014-02-08T17:58:24Z",
"version": "1",
"changeset": "20451306",
"user": "Schandlers",
"uid": "51690",
"natural": "tree",
"id": "node/2661561690"
},
"geometry": {
"type": "Point",
"coordinates": [
-66.9162255,
10.5056439
]
}
},
// ... Omitted data
{
"type": "Feature",
"id": "node/2664472516",
"properties": {
"timestamp": "2014-02-10T04:27:30Z",
"version": "2",
"changeset": "20477473",
"user": "albertoq",
"uid": "527105",
"name": "Distribuidora Brithijos (Aceites)",
"shop": "car_parts",
"id": "node/2664472516"
},
"geometry": {
"type": "Point",
"coordinates": [
-66.9388903,
10.4833647
]
}
}
]
}
推荐答案
下载 jq (类似于sed的程序,但对于JSON)
Download jq (it's sed-like program but for JSON)
然后运行:
jq --compact-output ".features" input.geojson > output.geojson
然后
mongoimport --db dbname -c collectionname --file "output.geojson" --jsonArray
这篇关于如何将Geojson文件导入MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!