Я извлек свойства из JSON API в разные массивы.Теперь мне нужно создать список GeoJSON только с нужными мне свойствами.У меня сейчас они в индивидуальном порядке.Как мне объединить их в правильный список GeoJSON?
В настоящее время список GeoJSON у меня выглядит следующим образом
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"station_name": East Coast
"id": EC1,
"device_id": EC1,
},
"geometry": {
"type": "Point",
"coordinates": [-73.9066122, 40.7453924]
}
},
{
"station_name": West Coast
"id": WC1,
"device_id": WC1,
},
"geometry": {
"type": "Point",
"coordinates": [-72.621322, 39.73424]
} },
{
"type": "Feature",
"properties": {
"timestamp": 1/1/19
"timestamp": 2/1/19
"timestamp": 3/1/19
},
{
"type": "Feature",
"properties": {
"value": 31
"value": 22
"value": 23
"value": 35
"value": 12
"value": 42
}
Я хочу объединить их в этот формат
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"timestamp": 1/1/19
"station_name": East Coast
"id": EC1,
"device_id": EC1,
"value": 31
},
"geometry": {
"type": "Point",
"coordinates": [-73.9066122, 40.7453924]
}
}, {
"type": "Feature",
"properties": {
"timestamp": 1/1/19
"station_name": West Coast
"id": EC1,
"device_id": EC1,
"value": 22
},
"geometry": {
"type": "Point",
"coordinates": [-72.621322, 39.73424]
}
},
{{
"type": "Feature",
"properties": {
"timestamp": 2/1/19
"station_name": East Coast
"id": EC1,
"device_id": EC1,
"value": 23
},
"geometry": {
"type": "Point",
"coordinates": [-73.9066122, 40.7453924]
}
}, {{
"type": "Feature",
"properties": {
"timestamp": 2/1/19
"station_name": West Coast
"id": EC1,
"device_id": EC1,
"value": 35
},
"geometry": {
"type": "Point",
"coordinates": [-72.621322, 39.73424]
}
},{
"type": "Feature",
"properties": {
"timestamp": 3/1/19
"station_name": East Coast
"id": EC1,
"device_id": EC1,
"value": 12
},
"geometry": {
"type": "Point",
"coordinates": [-73.9066122, 40.7453924]
}
}, {
{
"type": "Feature",
"properties": {
"timestamp": 3/1/19
"station_name": West Coast
"id": EC1,
"device_id": EC1,
"value": 42
},
"geometry": {
"type": "Point",
"coordinates": [-72.621322, 39.73424]
}
}
Ниже приведен мой код.Причина появления 3 для циклов заключается в том, что размеры массивов разные.
var apiGeo = {
type: "FeatureCollection",
features: []
};
for (var x in locname){
apiGeo.features.push({
"type":"Feature",
"properties": {
"station_name": locname[x],
"id": id[x],
"device_id": device_id[x],
},
"geometry":{
"type": "Point",
"coordinates": [loclong[x], loclat[x]]
}
});
}
for (var y in timestamp){
apiGeo.features.push({
"type":"Feature",
"properties":{
"timestamp": timestamp[y]
}
});
}
for (var z in value){
apiGeo.features.push({
"type":"Feature",
"properties":{
"value": value[0],
"items_id": value[1]
}
});
}