格式化并将GeoJSON文件插入MongoDB

时间:2015-03-18 19:42:16

标签: mongodb geojson

我是MongoDB和GeoJSON的新手,我正在尝试将从Census Reporter网站获得的GeoJSON文件的内容导入MongoDB集合。 这是文件的开头和结尾:

    {
    "type": "FeatureCollection",
    "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },

    "features": [
    { "type": "Feature", "properties": { "geoid": "14000US36005000100", "name": "Census Tract 1, Bronx, NY", "B19013001 - Median household income in the past 12 months (in 2013 inflation-adjusted dollars)": 0.0, "B19013001 - Median household income in the past 12 months (in 2013 inflation-adjusted dollars), Error": 0.0 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -73.897722, 40.795138 ], [ -73.89611, 40.796919 ], [ -73.892504, 40.801206 ], [ -73.872264, 40.794992 ], [ -73.866707, 40.793653 ], [ -73.870005, 40.790681 ], [ -73.87003, 40.790614 ], [ -73.871021, 40.788833 ], [ -73.8711, 40.788694 ], [ -73.871254, 40.787593 ], [ -73.870992, 40.786979 ], [ -73.872177, 40.786697 ], [ -73.873688, 40.78616 ], [ -73.878964, 40.785743 ], [ -73.881137, 40.786066 ], [ -73.882909, 40.78633 ], [ -73.884867, 40.786621 ], [ -73.88713, 40.786969 ], [ -73.889918, 40.787398 ], [ -73.890586, 40.790145 ], [ -73.892205, 40.79038 ], [ -73.892866, 40.790567 ], [ -73.899809, 40.792524 ], [ -73.897722, 40.795138 ] ] ] ] } },
    { "type": "Feature", "properties": { "geoid": "14000US36005000200", "name": "Census Tract 2, Bronx, NY", "B19013001 - Median household income in the past 12 months (in 2013 inflation-adjusted dollars)": 69514.0, "B19013001 - Median household income in the past 12 months (in 2013 inflation-adjusted dollars), Error": 16052.0 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -73.865218, 40.814529 ], [ -73.864255, 40.814658 ], [ -73.863329, 40.814782 ], [ -73.862404, 40.814906 ], [ -73.861482, 40.815029 ], [ -73.860554, 40.815155 ], [ -73.859717, 40.815269 ], [ -73.859555, 40.815114 ], [ -73.858383, 40.813997 ], [ -73.858189, 40.813812 ], [ -73.85772, 40.813362 ], [ -73.857156, 40.812824 ], [ -73.856133, 40.811415 ], [ -73.855618, 40.810608 ], [ -73.855437, 40.80987 ], [ -73.855312, 40.809329 ], [ -73.855183, 40.808751 ], [ -73.855076, 40.808303 ], [ -73.85491, 40.807614 ], [ -73.854807, 40.807259 ], [ -73.854637, 40.80666 ], [ -73.854417, 40.80578 ], [ -73.855861, 40.805671 ], [ -73.856443, 40.805679 ], [ -73.856432, 40.805578 ], [ -73.856422, 40.805476 ], [ -73.856438, 40.805341 ], [ -73.856323, 40.802619 ], [ -73.853631, 40.80296 ], [ -73.853489, 40.799993 ], [ -73.853466, 40.799581 ], [ -73.862704, 40.797276 ], [ -73.866484, 40.805901 ], [ -73.861357, 40.810837 ], [ -73.861165, 40.811127 ], [ -73.861612, 40.811359 ], [ -73.862934, 40.812047 ], [ -73.863324, 40.812265 ], [ -73.86708, 40.814441 ], [ -73.865218, 40.814529 ] ] ] ] } },
...
{ "type": "Feature", "properties": { "geoid": "16000US3651000", "name": "New York, NY", "B19013001 - Median household income in the past 12 months (in 2013 inflation-adjusted dollars)": 52259.0, "B19013001 - Median household income in the past 12 months (in 2013 inflation-adjusted dollars), Error": 253.0 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ ... ] ] ] } }
]
}

当我导入文件时(我使用MongoChef),它会在集合中创建一个单独的文档:type:" FeatureCollection"," crs":{。 ..},以及"特征"下的所有单个特征作为数组。 我希望在此集合中将每个功能都放在自己的文档中。我尝试删除封闭信息,只插入"功能"像这样的数组:

{
{ "type": "Feature", "properties": { "geoid": "14000US36005000100", "name": "Census Tract 1, Bronx, NY", "B19013001 - Median household income in the past 12 months (in 2013 inflation-adjusted dollars)": 0.0, "B19013001 - Median household income in the past 12 months (in 2013 inflation-adjusted dollars), Error": 0.0 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -73.897722, 40.795138 ], [ -73.89611, 40.796919 ], [ -73.892504, 40.801206 ], [ -73.872264, 40.794992 ], [ -73.866707, 40.793653 ], [ -73.870005, 40.790681 ], [ -73.87003, 40.790614 ], [ -73.871021, 40.788833 ], [ -73.8711, 40.788694 ], [ -73.871254, 40.787593 ], [ -73.870992, 40.786979 ], [ -73.872177, 40.786697 ], [ -73.873688, 40.78616 ], [ -73.878964, 40.785743 ], [ -73.881137, 40.786066 ], [ -73.882909, 40.78633 ], [ -73.884867, 40.786621 ], [ -73.88713, 40.786969 ], [ -73.889918, 40.787398 ], [ -73.890586, 40.790145 ], [ -73.892205, 40.79038 ], [ -73.892866, 40.790567 ], [ -73.899809, 40.792524 ], [ -73.897722, 40.795138 ] ] ] ] } },
...
{ "type": "Feature", "properties": { "geoid": "14000US36085990100", "name": "Census Tract 9901, Richmond, NY", "B19013001 - Median household income in the past 12 months (in 2013 inflation-adjusted dollars)": 0.0, "B19013001 - Median household income in the past 12 months (in 2013 inflation-adjusted dollars), Error": 0.0 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -74.259089, 40.499561 ], [ -74.259089, 40.499872 ], [ -74.259088, 40.500112 ], [ -74.258784, 40.500104 ], [ -74.255429, 40.494847 ], [ -74.254825, 40.493901 ], [ -74.25308, 40.491167 ], [ -74.233926, 40.494296 ], [ -74.233906, 40.4943 ], [ -74.220634, 40.496488 ], [ -74.205765, 40.498941 ], [ -74.20558, 40.498973 ], [ -74.173689, 40.510879 ], [ -74.15257, 40.518762 ], [ -74.13382, 40.525764 ], [ -74.133515, 40.525982 ], [ -74.108145, 40.54431 ], [ -74.108287, 40.544415 ], [ -74.103417, 40.548464 ], [ -74.094373, 40.55598 ], [ -74.089045, 40.560404 ], [ -74.084974, 40.563787 ], [ -74.078961, 40.568787 ], [ -74.070915, 40.575474 ], [ -74.059609, 40.584867 ], [ -74.055101, 40.588612 ], [ -74.054866, 40.588784 ], [ -74.050802, 40.595423 ], [ -74.047153, 40.601381 ], [ -74.046326, 40.602732 ], [ -74.043825, 40.606818 ], [ -74.042036, 40.604088 ], [ -74.041393, 40.603106 ], [ -74.037877, 40.589201 ], [ -74.034547, 40.57625 ], [ -74.035047, 40.57285 ], [ -74.035053, 40.572747 ], [ -74.035153, 40.571003 ], [ -74.035978, 40.556563 ], [ -74.036209, 40.552524 ], [ -74.036216, 40.5524 ], [ -74.036285, 40.551185 ], [ -74.036293, 40.551042 ], [ -74.036297, 40.550969 ], [ -74.036298, 40.550948 ], [ -74.0363, 40.550905 ], [ -74.036549, 40.549209 ], [ -74.036551, 40.549194 ], [ -74.03667, 40.548384 ], [ -74.036672, 40.54837 ], [ -74.037494, 40.54279 ], [ -74.038131, 40.538294 ], [ -74.042112, 40.509299 ], [ -74.057595, 40.506529 ], [ -74.057873, 40.506476 ], [ -74.071052, 40.503911 ], [ -74.078179, 40.502505 ], [ -74.082896, 40.501666 ], [ -74.091492, 40.500137 ], [ -74.09167, 40.500105 ], [ -74.092298, 40.499989 ], [ -74.094483, 40.499601 ], [ -74.098576, 40.498904 ], [ -74.107576, 40.497417 ], [ -74.124549, 40.494621 ], [ -74.131132, 40.493533 ], [ -74.137156, 40.492538 ], [ -74.143917, 40.491394 ], [ -74.149938, 40.490372 ], [ -74.152069, 40.490017 ], [ -74.160393, 40.48869 ], [ -74.162634, 40.48829 ], [ -74.163861, 40.488071 ], [ -74.200342, 40.482018 ], [ -74.200395, 40.482009 ], [ -74.206451, 40.481015 ], [ -74.217041, 40.479224 ], [ -74.228153, 40.477399 ], [ -74.237935, 40.481241 ], [ -74.240691, 40.482342 ], [ -74.243652, 40.483526 ], [ -74.248261, 40.485367 ], [ -74.248585, 40.485497 ], [ -74.249589, 40.485898 ], [ -74.249743, 40.48596 ], [ -74.249897, 40.486021 ], [ -74.249934, 40.486035 ], [ -74.252646, 40.48712 ], [ -74.253159, 40.487325 ], [ -74.253313, 40.487386 ], [ -74.254289, 40.489006 ], [ -74.25653, 40.492965 ], [ -74.256719, 40.493299 ], [ -74.257317, 40.494349 ], [ -74.259028, 40.497107 ], [ -74.25909, 40.497207 ], [ -74.259089, 40.499561 ] ] ] ] } }
}

但是我收到格式错误,说有一个意外字符':'介于"类型":"功能"。

知道如何选择要插入到集合中的原始GeoJSON文件的哪一部分,或者如何将文件重新格式化为仅包含我需要的数据?

谢谢!

0 个答案:

没有答案