How to use the h3-js.h3ToGeoBoundary function in h3-js

To help you get started, we’ve selected a few h3-js 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 sharedstreets / mobility-metrics / src / summarize.js View on Github external
if (timestamp.diff(current) <= 0) {
            lastAvailable = state;
          }
        }
      });

      if (lastAvailable) {
        // onstreet hex bins
        var bin = h3.geoToH3(
          lastAvailable.event_location.geometry.coordinates[1],
          lastAvailable.event_location.geometry.coordinates[0],
          Z
        );

        // store geo
        var geo = turf.polygon([h3.h3ToGeoBoundary(bin, true)], {
          bin: bin
        });
        stats.geometry.bins[bin] = geo;

        // bootstrap bin
        if (!stats.onstreet.bins.minute[current.format(baseDay + "-HH-mm")]) {
          stats.onstreet.bins.minute[current.format(baseDay + "-HH-mm")] = {};
        }
        if (
          !stats.onstreet.bins.minute[current.format(baseDay + "-HH-mm")][bin]
        ) {
          stats.onstreet.bins.minute[current.format(baseDay + "-HH-mm")][
            bin
          ] = 1;
        } else {
          stats.onstreet.bins.minute[current.format(baseDay + "-HH-mm")][bin]++;
github sharedstreets / mobility-metrics / src / summarize.js View on Github external
if (timestamp.diff(current) <= 0) {
            lastAvailable = state;
          }
        }
      });

      if (lastAvailable) {
        // availability hex bins
        var bin = h3.geoToH3(
          lastAvailable.event_location.geometry.coordinates[1],
          lastAvailable.event_location.geometry.coordinates[0],
          Z
        );

        // store geo
        var geo = turf.polygon([h3.h3ToGeoBoundary(bin, true)], {
          bin: bin
        });
        stats.geometry.bins[bin] = geo;

        // bootstrap bin
        if (
          !stats.availability.bins.minute[current.format(baseDay + "-HH-mm")]
        ) {
          stats.availability.bins.minute[
            current.format(baseDay + "-HH-mm")
          ] = {};
        }
        if (
          !stats.availability.bins.minute[current.format(baseDay + "-HH-mm")][
            bin
          ]
github uber / deck.gl / modules / geo-layers / src / h3-layers / h3-hexagon-layer.js View on Github external
function h3ToPolygon(hexId, coverage = 1, flatten) {
  const vertices = h3ToGeoBoundary(hexId, true);

  if (coverage !== 1) {
    // scale and normalize vertices w.r.t to center
    scalePolygon(hexId, vertices, coverage);
  } else {
    // normalize w.r.t to start vertex
    normalizeLongitudes(vertices);
  }

  if (flatten) {
    const positions = new Float64Array(vertices.length * 2);
    let i = 0;
    for (const pt of vertices) {
      positions[i++] = pt[0];
      positions[i++] = pt[1];
    }
github keplergl / kepler.gl / src / layers / h3-hexagon-layer / h3-utils.js View on Github external
export function getVertices({id}) {
  // always reverse it
  return h3ToGeoBoundary(id, true);
}
github sharedstreets / mobility-metrics / src / summarize.js View on Github external
Z
      );
      var b = h3.geoToH3(
        trip.route.features[trip.route.features.length - 1].geometry
          .coordinates[1],
        trip.route.features[trip.route.features.length - 1].geometry
          .coordinates[0],
        Z
      );

      // store pair geometry
      var pair = turf.lineString(
        [
          turf.centroid(turf.polygon([h3.h3ToGeoBoundary(a, true)])).geometry
            .coordinates,
          turf.centroid(turf.polygon([h3.h3ToGeoBoundary(b, true)])).geometry
            .coordinates
        ],
        { pair: a + ">" + b }
      );
      stats.geometry.pairs[pair.properties.pair] = pair;

      var timeBins = getTimeBins(reportDay, trip.start_time);
      // populate time bins
      if (!stats.flows.pairs.day[timeBins.day]) {
        stats.flows.pairs.day[timeBins.day] = {};
      }
      if (!stats.flows.pairs.hour[timeBins.hour]) {
        stats.flows.pairs.hour[timeBins.hour] = {};
      }
      if (!stats.flows.pairs.minute[timeBins.minute]) {
        stats.flows.pairs.minute[timeBins.minute] = {};
github sharedstreets / mobility-metrics / src / summarize.js View on Github external
trip.route.features[0].geometry.coordinates[1],
        trip.route.features[0].geometry.coordinates[0],
        Z
      );
      var b = h3.geoToH3(
        trip.route.features[trip.route.features.length - 1].geometry
          .coordinates[1],
        trip.route.features[trip.route.features.length - 1].geometry
          .coordinates[0],
        Z
      );

      // store pair geometry
      var pair = turf.lineString(
        [
          turf.centroid(turf.polygon([h3.h3ToGeoBoundary(a, true)])).geometry
            .coordinates,
          turf.centroid(turf.polygon([h3.h3ToGeoBoundary(b, true)])).geometry
            .coordinates
        ],
        { pair: a + ">" + b }
      );
      stats.geometry.pairs[pair.properties.pair] = pair;

      var timeBins = getTimeBins(reportDay, trip.start_time);
      // populate time bins
      if (!stats.flows.pairs.day[timeBins.day]) {
        stats.flows.pairs.day[timeBins.day] = {};
      }
      if (!stats.flows.pairs.hour[timeBins.hour]) {
        stats.flows.pairs.hour[timeBins.hour] = {};
      }
github uber / geojson2h3 / src / geojson2h3.js View on Github external
function h3ToFeature(hexAddress, properties = {}) {
    // Wrap in an array for a single-loop polygon
    const coordinates = [h3.h3ToGeoBoundary(hexAddress, true)];
    return {
        type: FEATURE,
        id: hexAddress,
        properties,
        geometry: {
            type: POLYGON,
            coordinates
        }
    };
}
github uber / geojson2h3 / test / geojson2h3.spec.js View on Github external
test('featureToH3Set - resolution 10', assert => {
    const parentHex = '89283082837ffff';
    const vertices = h3.h3ToGeoBoundary(parentHex, true);
    const feature = {
        type: 'Feature',
        properties: {},
        geometry: {
            type: 'Polygon',
            coordinates: [
                [
                    vertices[2],
                    vertices[3],
                    vertices[4],
                    vertices[5],
                    vertices[0],
                    vertices[1],
                    vertices[2]
                ]
            ]
github hpcc-systems / Visualization / demos / h3 / src / demo05.ts View on Github external
const boundaries = this._circleMap.data().map(row => {
            const h3Idx = geoToH3(row[0], row[1], res);
            return [h3Idx, h3ToGeoBoundary(h3Idx, false).map(point => [point[1], point[0]]), 1];
        });
        this._hexMap.data(boundaries);

h3-js

Pure-Javascript version of the H3 library, a hexagon-based geographic grid system

Apache-2.0
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis