我有一个关于在JavaScript中合并FeatureCollection(与地理数据)和常规JSON文件的问题。
这是文件的结构:
municipalities.json
[
{
"county": "Burgenland",
"iso": 10101,
"cityname": "Eisenstadt",
"status": "SR",
"inhabitants": 14637
},
{
"county": "Wien",
"iso": 90001,
"cityname": "Wien",
"status": "SR",
"inhabitants": 1897491
}
]
geodata.json
{"type":"FeatureCollection", "features": [
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[9.55509446207664,47.296861334859635],[9.57968997522972,47.28539997266237],[9.623675623790518,47.2685892488267],[9.627952952015853,47.25163495206236],[9.603219996624304,47.2309238791905],[9.584847921928075,47.20478469066296],[9.552236561831744,47.22410026115072],[9.567253788267898,47.24066768024787],[9.530726492185032,47.27057809372103],[9.55509446207664,47.296861334859635]]]},"properties":{"name":"Eisenstadt","iso":"10101","iso_alt":null}},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[9.817158901934487,47.21322498229595],[9.823517985999242,47.195677965801025],[9.77068824380323,47.174059587267706],[9.756480129943482,47.175372470386854],[9.750234503099112,47.17608788642722],[9.756781963878947,47.185042167339084],[9.779289971974789,47.199115883927455],[9.805174567560579,47.21233133634802],[9.817158901934487,47.21322498229595]]]},"properties":{"name":"Wien","iso":"90001","iso_alt":null}}
]}
这是我将文件加载到的方式:
var municipalities = null;
$.ajax({
'async': false,
'global': false,
'url': "municipalities.json",
'dataType': "json",
'success': function (data) {
municipalities = data;
console.log("Population data successfully loaded");
}
});
和
var geodata = null;
$.ajax({
'async': false,
'global': false,
'url': "geodata.json",
'dataType': "json",
'success': function (data) {
geodata = data;
console.log("Geodata successfully loaded");
}
});
这给了我两种不同的数据类型:数组和具有FeatureCollection类型的对象
console.log(municipalities);
console.log(geodata);
现在,我想将这两个文件加入其iso代码中,但是我找不到解决方法。结果应该是一个FeatureCollection,其中包含来自地理数据属性中的市政数据。
我查找了不同的方法(How to join two JavaScript Objects, without using JQUERY),但是我找不到解决这两种类型的方法。
非常感谢您的帮助。