How to use @turf/hex-grid - 2 common examples

To help you get started, we’ve selected a few @turf/hex-grid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Turfjs / turf / packages / turf-interpolate / index.js View on Github external
weight = weight || 1;

    var box = bbox(points);
    var grid;
    switch (gridType) {
    case 'point':
    case 'points':
        grid = poinGrid(box, cellSize, {units: units, bboxIsMask: true});
        break;
    case 'square':
    case 'squares':
        grid = squareGrid(box, cellSize, {units: units});
        break;
    case 'hex':
    case 'hexes':
        grid = hexGrid(box, cellSize, {units: units});
        break;
    case 'triangle':
    case 'triangles':
        grid = triangleGrid(box, cellSize, {units: units});
        break;
    default:
        throw new Error('invalid gridType');
    }
    var results = [];
    featureEach(grid, function (gridFeature) {
        var zw = 0;
        var sw = 0;
        // calculate the distance from each input point to the grid points
        featureEach(points, function (point) {
            var gridPoint = (gridType === 'point') ? gridFeature : centroid(gridFeature);
            var d = distance(gridPoint, point, units);
github google / earthengine-api / demos / cloud-functions / function.js View on Github external
ee.initialize(null, null, () => {
      // Load an image estimating number of persons per 30 arc-second grid cell.
      const image = ee.Image('CIESIN/GPWv4/population-count/2015');

      // Create a hexgrid covering the viewport, with TurfJS.
      const cellDiameter =
          200 * Math.abs(bounds[3] - bounds[1]) / DEGREES_LATITUDE_TO_MILES;
      const gridGeoJson = hexGrid(bounds, cellDiameter, 'miles');
      const gridFeatures = ee.FeatureCollection(gridGeoJson.features);

      // Compute sum of population values for each hex cell.
      const reducedFeatures =
          image.reduceRegions(gridFeatures, ee.call('Reducer.sum'));
      reducedFeatures.evaluate((geojson) => res.send(geojson));
    });
  });

@turf/hex-grid

turf hex-grid module

MIT
Latest version published 2 months ago

Package Health Score

96 / 100
Full package analysis

Popular @turf/hex-grid functions