обработка данных: вложение json свойств в качестве ключей с использованием d3. js или javascript - PullRequest
0 голосов
/ 28 апреля 2020

Имея объект geo json в этом формате ...

[
{
  type: "Feature",
  properties: {id: "12345", a: 4196, b: 3143, c: 429},
  geometry: {type: "Polygon", coordinates: Array(1)}
}, 
{
  type: "Feature", 
  properties: {a: "12346", b: 2342, inc: 234, c: 765},
  geometry: {type: "Polygon", coordinates: Array(1)}
},
{
  type: "Feature", 
  properties: {id: "12347", a: 342, b: 87, c: 56},
  geometry: {type: "Polygon", coordinates: Array(1)}
}
]

Как я могу преобразовать данные и структурировать их таким образом? Ожидаемый результат выглядит следующим образом:

[
 {
  key: "a",
  values: {
    type: "Feature", 
    properties: {value: 4196},
    geometry: {type: "Polygon", coordinates: Array(1)}
    },
    {
    type: "Feature", 
    properties: {value: 342},
    geometry: {type: "Polygon", coordinates: Array(1)}
    },
    {
    type: "Feature", 
    properties: {value: 2342},
    geometry: {type: "Polygon", coordinates: Array(1)}
    }
 },
 {
  key: "b",
  values: {
    type: "Feature", 
    properties: {value: 3143},
    geometry: {type: "Polygon", coordinates: Array(1)}
    },
    {
    type: "Feature", 
    properties: {value: 234},
    geometry: {type: "Polygon", coordinates: Array(1)}
    },
    {
    type: "Feature", 
    properties: {value: 87},
    geometry: {type: "Polygon", coordinates: Array(1)}
    }
 },
 {
  key: "c",
  values: {
    type: "Feature", 
    properties: {value: 429},
    geometry: {type: "Polygon", coordinates: Array(1)}
    },
    {
    type: "Feature", 
    properties: {value: 765},
    geometry: {type: "Polygon", coordinates: Array(1)}
    },
    {
    type: "Feature", 
    properties: {value: 56},
    geometry: {type: "Polygon", coordinates: Array(1)}
    }
 }
]

Вложением будет вариант для решения этой проблемы. К сожалению, я попытался d3.nest(), но я не получил ожидаемый результат.

Если d3.nest() не лучший вариант для достижения этой цели, я открыт для любого другого javascript метода обработки данных.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...