分類したいフィルター処理された 16 進グリッドがあります。
で六角形を作成しました
var hexgrid = turf.hexGrid(bbox, cellWidth, units);
で値を集計しました
var aggregated = turf.collect(hexgrid, myGeoJson, 'MyValue', 'NewCol');
ここで、myGeoJson はマルチポイント FeatureCollection であり、MyValue は null または > 0 の機能プロパティです
16進数をフィルタリングしました
var hexFiltered = L.geoJson(aggregated, {
filter: function(feature, layer) {
return feature.properties.NewCol.length > 0;
}
}).addTo(map);
各 hex オブジェクトには次のようにアクセスできます
console.log(hexFiltered["_layers"]);
output = Object { 49: Object, 51: Object, 52: Object, 53: Object...
各オブジェクトには .feature.properties.NewCol[n] があり、各配列にはインデックス (0、1、2) と値 (null、1 +) があります。
配列値の合計で各 16 進グリッドを分類するにはどうすればよいですか?
ネイティブの JavaScript でこれを試してみましたが、達成できるのは各値を持つ文字列だけです。
var counts = {};
for (var obj in hexFiltered["_layers"]) {
// Output the id of each obj (hex)
// console.log("Object: " + obj);
var cnt = 0;
for (var i in hexFiltered["_layers"][obj]["feature"]["properties"] ) {
// print values out as 1 line (i)
console.log("One line of values :" + hexFiltered["_layers"][obj]["feature"]["properties"][i]);
// output = One line of values :,,,1,,,,1,1,,1
// add values
cnt = cnt + hexFiltered["_layers"][obj]["feature"]["properties"][i];
console.log(cnt);
// output = 0,,,1,,,,1,1,,1
}
// attach cnt to counts object
counts += cnt;
}
どこが間違っていますか?もっと簡単な方法はありますか?