【发布时间】:2021-12-16 05:20:20
【问题描述】:
您好,我正在处理一个大型 geojson 数据集,我正在尝试查看是否可以根据共享相同“User_ID”的条目合并每个条目的坐标值。
我的数据集如下所示:
{
"geometry":{
"type":"Point",
"coordinates":[
-3.231658,
51.687026
]
},
"type":"Feature",
"properties":{
"User_ID":1002848324
}
},
{
"geometry":{
"type":"Point",
"coordinates":[
-3.231659,
51.687016
]
},
"type":"Feature",
"properties":{
"User_ID":1002848324
}
}
我尝试使用 mwarren 的答案中显示的方法合并条目,网址:“https://stackoverflow.com/questions/29244116/merge-geojson-based-on-unique-id”。
然而,当我尝试运行测试时,“attr”被视为“意外标识符”。
到目前为止我对代码的测试如下:
features.map(function(feature){
var matchedArray = features2.filter(function(feature2){
return feature2.User_ID === feature.User_ID;
});
if(matchedArray && matchedArray[0]){
for(var attr in matchedArray[0].properties){
feature.properties[attr] = matchedArray[0].properties[attr];
}
}
});
想要的结果应该是这样的:
{
"geometry":{
"type":"Point",
"coordinates":[
-3.231658,
51.687026
], [
-3.231659,
51.687016
]
},
"type":"Feature",
"properties":{
"User_ID":1002848324
}
任何帮助将不胜感激。
【问题讨论】:
-
你的预期输出是什么?
-
OP 不仅需要按相同的
User_ID值分组/收集数据,还需要按相同的type和相同的User_ID值分组/收集数据
标签: javascript arrays merge geojson reduce