h3Indexes = {
const {minLat, maxLat, minLng, maxLng} = bounds;
const height = maxLat - minLat;
const width = maxLng - minLng;
const rowCount = dem.length;
const colCount = dem[0].length;
const px2coord = (row, col) => ({
lat: maxLat - (row / rowCount) * height,
lng: (col / colCount) * width + minLng
});
const indexes = {};
for (let r = 0; r < rowCount; r++) {
for (let c = 0; c < colCount; c++) {
const {lat, lng} = px2coord(r, c);
const h3Index = h3.geoToH3(lat, lng, h3Resolution);
if (!indexes[h3Index]) {
indexes[h3Index] = {sum: 0, count: 0};
}
indexes[h3Index].sum += dem[r][c];
indexes[h3Index].count++;
}
}
return Object.keys(indexes).map(h3Index => {
const {sum, count} = indexes[h3Index];
return {h3Index, elevation: sum / count};
})
}