How to use the h3-js.geoToH3 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
[trip.route.features[0]].forEach(ping => {
        var bin = h3.geoToH3(
          ping.geometry.coordinates[1],
          ping.geometry.coordinates[0],
          Z
        );
        bins.add(bin);
      });
      // store bin geometry
github sharedstreets / mobility-metrics / src / summarize.js View on Github external
states[vehicle_id].forEach(state => {
        if (
          state.event_type === "available" ||
          state.event_type === "unavailable"
        ) {
          var timestamp = moment(state.event_time, "X");

          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 (
github sharedstreets / mobility-metrics / src / summarize.js View on Github external
function flows(startDay, endDay, reportDay, stats, trips, privacyMinimum) {
  for (let trip of trips) {
    // check for time range
    if (
      trip.start_time >= startDay.format("X") &&
      trip.start_time <= endDay.format("X")
    ) {
      var a = h3.geoToH3(
        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 }
github sharedstreets / mobility-metrics / src / metrics.js View on Github external
trip.route.features.forEach(ping => {
    var bin = h3.geoToH3(
      ping.geometry.coordinates[1],
      ping.geometry.coordinates[0],
      Z
    );
    h3s.add(bin);
  });
github keplergl / kepler.gl / src / layers / h3-hexagon-layer / h3-utils.js View on Github external
export function getCenterHex({latitude, longitude}, resolution) {
  return geoToH3(latitude, longitude, resolution);
}
github sharedstreets / mobility-metrics / src / metrics.js View on Github external
Metrics.prototype.dropoffs = function(trip, times, provider, done) {
  var bin = 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
  );

  var qtime = queue(1);
  times.forEach(time => {
    qtime.defer(timecb => {
      var id = provider + "!dropoffs!" + time + "!" + bin;

      this.store.get(id, (err, record) => {
        if (!record) record = 1;
        else record++;

        this.store.put(id, record, err => {
          if (err) throw err;
github sharedstreets / mobility-metrics / src / matchers / trip.js View on Github external
trip.route.features.forEach(ping => {
    var bin = h3.geoToH3(
      ping.geometry.coordinates[1],
      ping.geometry.coordinates[0],
      config.Z
    );
    bins[bin] = 1;
  });
github sharedstreets / mobility-metrics / src / data / h3.ts View on Github external
function pointToH3(point:Feature):string {
    var lnglat = getCoord(point);
    return h3.geoToH3( lnglat[1], lnglat[0], BASE_H3_INDEX_LEVEL);
}
github sharedstreets / mobility-metrics / src / metrics.js View on Github external
Metrics.prototype.dropoffsvia = function(trip, times, provider, done) {
  var binA = h3.geoToH3(
    trip.route.features[0].geometry.coordinates[1],
    trip.route.features[0].geometry.coordinates[0],
    Z
  );
  var binB = 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
  );

  var qtime = queue(1);
  times.forEach(time => {
    qtime.defer(timecb => {
      var id = provider + "!dropoffsvia!" + time + "!" + binA + "!" + binB;

      this.store.get(id, (err, record) => {
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