Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider buffer radius in addition to H3 resolution when counting points in the aggregated bins of H3-hexagons #174

Closed
sharmapn opened this issue Feb 17, 2023 · 2 comments

Comments

@sharmapn
Copy link

sharmapn commented Feb 17, 2023

Hello,

I am focussing on the H3-JS example from
https://observablehq.com/@nrabinowitz/h3-tutorial-using-point-layers?collection=@nrabinowitz/h3-tutorial

Within the provided code, there is a function (below) that counts the number of points in each of the hexagons after the binning and embeds these as attributes within the geoJSON.

function _countPoints(h3,h3Resolution,normalizeLayer){return(
function countPoints(geojson) {
  const layer = {};
  geojson.features.forEach(feature => {
    const [lng, lat] = feature.geometry.coordinates;
    const h3Index = h3.geoToH3(lat, lng, h3Resolution);
    layer[h3Index] = (layer[h3Index] || 0) + 1;
  });
  return normalizeLayer(layer, true);
}
)}

However, in addition to the h3Resolution, I was hoping to integrate Buffer Radius in this calculation.
You see I am fully using the example. Thus, the user can choose values for both: h3Resolution and Buffer Radius.
That means that the resulting geojson should shoe the counts after considering both the values: h3Resolution and Buffer Radius.

Finally we need a geojson which has the features, together with the h3 cells, h3 resolution, buffer radius and the number of points contained within.

I would appreciate any guidance on this small question.

@nrabinowitz
Copy link
Collaborator

I'm not clear on what's intended here. Is the Buffer Radius in grid distance? I.e. if I run countPoints(res, radius) you want the count of all points that are both in the specific h3 cell and in its neighbors at a given radius?

This could look like:

function countPoints(geojson, h3Resolution, bufferRadius) {
  const layer = {};
  geojson.features.forEach(feature => {
    const [lng, lat] = feature.geometry.coordinates;
    const h3Index = h3.geoToH3(lat, lng, h3Resolution);
    const neighbors = h3.kRing(h3Index, bufferRadius);
    for (const neighbor of neighbors) {
      layer[neighbor] = (layer[neighbor] || 0) + 1;
    }
  });
  return normalizeLayer(layer, true);
}

@sharmapn
Copy link
Author

sharmapn commented May 5, 2023

Yes, that is what I needed.
Thank you.

@sharmapn sharmapn closed this as completed May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants