h3-js

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

H3 Geospatial Indexing — h3-js v4

H3地理空间索引 — h3-js v4

H3 is Uber's hierarchical hexagonal geospatial indexing system. It tiles the sphere with hexagons at 16 resolutions (0-15), each ~7x finer than the last. The
h3-js
library provides JavaScript bindings for the H3 C library via emscripten.
npm install h3-js
js
import * as h3 from "h3-js"; // ESM
const h3 = require("h3-js"); // CJS
H3是Uber推出的分层六边形地理空间索引系统。它使用六边形在16个分辨率(0-15)下对球体进行分块,每个后续分辨率的精细度约为前一个的7倍。
h3-js
库通过emscripten为H3 C语言库提供JavaScript绑定。
npm install h3-js
js
import * as h3 from "h3-js"; // ESM
const h3 = require("h3-js"); // CJS

When to Use H3

H3的适用场景

  • Aggregation — Bucket points into uniform cells with equidistant neighbors for heatmaps and density analysis.
  • Joining disparate datasets — Index points, lines, and polygons into H3 cells to join datasets that share no common key except location.
  • Flow modeling — Model movement between cells via directed edges. Uniform neighbor distances simplify weighting.
  • Machine learning — Apply convolution and other CV techniques to the hex grid using k-rings and IJ coordinates.
  • Multi-resolution analysis — Compact large cell sets into mixed-resolution representations, then uncompact for comparison at any resolution.
  • 数据聚合 — 将点归类到具有等距邻接单元的统一网格中,用于热力图和密度分析。
  • 异构数据集关联 — 将点、线、面索引到H3单元中,以关联除位置外无共同键的数据集。
  • 流动建模 — 通过有向边模拟单元间的移动。统一的邻接距离简化了权重计算。
  • 机器学习 — 使用k环和IJ坐标对六边形网格应用卷积等计算机视觉技术。
  • 多分辨率分析 — 将大型单元集压缩为混合分辨率表示,然后可展开为任意分辨率进行对比。

H3 vs Alternatives

H3与其他方案对比

SystemCell ShapeHierarchyIdentifiersKey Tradeoff
H3HexagonAperture 7, approximate containment64-bit intEquidistant neighbors; approximate subdivision
S2SquareAperture 4, exact containment64-bit intExact subdivision; non-equidistant neighbors
GeohashRectangleExact containmentVariable-length stringSimple encoding; severe area distortion at poles
HexbinHexagonNoneProjection-specificCheap to compute; no hierarchy, not portable
Admin boundariesIrregularNoneNames/codesHuman-meaningful; incomparable sizes, change over time
系统单元形状层级结构标识符关键权衡点
H3六边形孔径7,近似包含64位整数等距邻接单元;近似细分
S2正方形孔径4,精确包含64位整数精确细分;非等距邻接单元
Geohash矩形精确包含可变长度字符串编码简单;极地地区面积失真严重
Hexbin六边形投影相关计算成本低;无层级结构,不具备可移植性
行政边界不规则形状名称/代码具有人类可读性;大小不可比,随时间变化

Concepts

核心概念

Understand these before using the API — they affect correctness.
在使用API前请先理解这些概念,它们会影响结果的正确性。

Terminology

术语定义

  • Cell — A hexagon or pentagon in the H3 grid. Use "cell" in code; "hexagon"/"pentagon" only when the distinction matters.
  • H3Index — 64-bit integer identifying any H3 object (cell, directed edge, or vertex). Represented as a 15-16 char hex string (e.g.,
    "85283473fffffff"
    ).
  • Directed edge — H3Index (mode 2) representing traversal from one cell to an adjacent cell.
  • Vertex — H3Index representing a topological vertex of a cell.
  • Base cell — One of 122 resolution-0 cells (110 hexagons, 12 pentagons). Every cell descends from one.
  • Grid distance — Minimum number of hops across adjacent cells from one cell to another.
  • 单元(Cell) — H3网格中的六边形或五边形。在代码中使用“cell”;仅当需要区分时使用“hexagon”/“pentagon”。
  • H3Index — 64位整数,用于标识任何H3对象(单元、有向边或顶点)。以15-16位的十六进制字符串表示(例如:
    "85283473fffffff"
    )。
  • 有向边(Directed edge) — H3Index(模式2),表示从一个单元到相邻单元的遍历。
  • 顶点(Vertex) — H3Index,表示单元的拓扑顶点。
  • 基础单元(Base cell) — 122个分辨率为0的单元之一(110个六边形,12个五边形)。所有单元都由基础单元衍生而来。
  • 网格距离(Grid distance) — 从一个单元到另一个单元,经过相邻单元的最小跳数。

Pentagons

五边形

12 pentagons per resolution, centered on icosahedron vertices (all in ocean — land apps rarely hit them). Most functions handle pentagons transparently. Exceptions:
  • gridRing
    can throw near pentagons — use
    gridDisk
    as the safe alternative.
  • gridDistance
    ,
    gridPathCells
    , and
    cellToLocalIj
    may fail across pentagonal distortion.
  • Pentagon area is ~50% of hexagon area at the same resolution.
每个分辨率下有12个五边形,位于二十面体的顶点处(全部在海洋中——陆地应用很少会涉及到它们)。大多数函数会透明处理五边形。例外情况:
  • gridRing
    在五边形附近可能会抛出错误 — 使用
    gridDisk
    作为安全替代方案。
  • gridDistance
    gridPathCells
    cellToLocalIj
    可能会因五边形的变形而失效。
  • 相同分辨率下,五边形的面积约为六边形的50%。

Hierarchical Containment Is Approximate

层级包含是近似的

Child cell centers may fall outside their parent's boundary. Geographic containment is approximate; logical containment is exact. Use
cellToParent
/
cellToChildren
for logical hierarchy. For exact boundaries, combine H3 indexing with point-in-polygon checks.
compactCells
/
uncompactCells
use logical containment and are exact.
子单元的中心可能位于其父单元的边界之外。地理空间包含是近似的;逻辑包含是精确的。使用
cellToParent
/
cellToChildren
处理逻辑层级。如需精确边界,可将H3索引与点-in-多边形检查结合使用。
compactCells
/
uncompactCells
使用逻辑包含,结果是精确的。

Class II vs Class III

Class II与Class III

Resolutions alternate orientation by ~19.1 degrees. Even (0, 2, 4, ...) = Class II; odd (1, 3, 5, ...) = Class III. Matters for algorithms depending on grid alignment.
分辨率会交替改变约19.1度的方向。偶数分辨率(0、2、4...)= Class II;奇数分辨率(1、3、5...)= Class III。这对依赖网格对齐的算法很重要。

Coordinate Conventions

坐标约定

  • Default coordinate order is lat/lng. Pass
    true
    as the
    formatAsGeoJson
    /
    isGeoJson
    parameter for lng/lat (GeoJSON) order.
  • The coordinate reference system uses WGS84/EPSG:4326 with the authalic sphere radius.
  • cellToBoundary
    may return more than 6 vertices for cells that cross icosahedron face boundaries.
  • 默认坐标顺序为纬度/经度。若要使用经度/纬度(GeoJSON)顺序,需将
    formatAsGeoJson
    /
    isGeoJson
    参数设为
    true
  • 坐标参考系统使用WGS84/EPSG:4326,并采用等面积球体半径。
  • cellToBoundary
    可能会返回超过6个顶点,对于那些跨越二十面体面边界的单元。

Error Handling

错误处理

Invalid inputs throw errors. Check
.message
for details.
js
try {
  h3.cellToChildrenSize("invalid", 9);
} catch (e) {
  console.error(e.message); // "Cell argument was not valid"
}
Common causes: invalid cell/edge/vertex, incompatible resolutions, cells too far apart for grid distance, pentagon distortion.
无效输入会抛出错误。可通过
.message
查看详细信息。
js
try {
  h3.cellToChildrenSize("invalid", 9);
} catch (e) {
  console.error(e.message); // "Cell argument was not valid"
}
常见原因:无效的单元/边/顶点、不兼容的分辨率、网格距离过远的单元、五边形变形。

Resolution Guide

分辨率指南

Each finer resolution has ~7x more cells. Total cells at resolution r:
2 + 120 * 7^r
.
ResAvg Hex AreaAvg Edge LengthTotal CellsTypical Use Case
04,357,449 km21,281 km122Continental
312,393 km269 km41,162Country / state
5253 km29.9 km2,016,842Metro area
75.16 km21.4 km98,825,162Neighborhood
90.105 km2201 m4.8 billionCity block
110.00215 km228.7 m237 billionBuilding
1343.9 m24.1 m11.6 trillionRoom
150.9 m20.58 m569 trillionSub-meter
每个更精细的分辨率的单元数量约为前一个的7倍。分辨率r下的总单元数为:
2 + 120 * 7^r
分辨率平均六边形面积平均边长总单元数典型适用场景
04,357,449 km²1,281 km122大陆级别
312,393 km²69 km41,162国家/州级别
5253 km²9.9 km2,016,842都会区级别
75.16 km²1.4 km98,825,162社区级别
90.105 km²201 m48亿城市街区级别
110.00215 km²28.7 m2370亿建筑级别
1343.9 m²4.1 m11.6万亿房间级别
150.9 m²0.58 m5690万亿亚米级

Common Patterns

常见使用模式

Find all cells within a radius of a point

查找点半径范围内的所有单元

Convert a radius (km) to a k-ring step count via average edge length.
js
const origin = h3.latLngToCell(lat, lng, 8);
const radiusKm = 4;
const edgeKm = h3.getHexagonEdgeLengthAvg(8, h3.UNITS.km);
const k = Math.floor(radiusKm / (edgeKm * 2));
const nearby = h3.gridDisk(origin, k);
通过平均边长将半径(公里)转换为k环步数。
js
const origin = h3.latLngToCell(lat, lng, 8);
const radiusKm = 4;
const edgeKm = h3.getHexagonEdgeLengthAvg(8, h3.UNITS.km);
const k = Math.floor(radiusKm / (edgeKm * 2));
const nearby = h3.gridDisk(origin, k);

Aggregate points into hex bins (heatmap)

将点聚合为六边形网格单元(热力图)

Count points per cell for density visualization or analysis.
js
function aggregatePoints(points, res) {
  const counts = {};
  for (const { lat, lng } of points) {
    const cell = h3.latLngToCell(lat, lng, res);
    counts[cell] = (counts[cell] || 0) + 1;
  }
  return counts;
}
统计每个单元内的点数量,用于密度可视化或分析。
js
function aggregatePoints(points, res) {
  const counts = {};
  for (const { lat, lng } of points) {
    const cell = h3.latLngToCell(lat, lng, res);
    counts[cell] = (counts[cell] || 0) + 1;
  }
  return counts;
}

Weight points with distance falloff

带距离衰减的点权重计算

Spread each point's influence across surrounding cells with linear decay by grid distance.
js
function weightWithFalloff(points, res, kRadius) {
  const weights = {};
  const step = 1 / (kRadius + 1);
  for (const { lat, lng } of points) {
    const origin = h3.latLngToCell(lat, lng, res);
    const rings = h3.gridDiskDistances(origin, kRadius);
    rings.forEach((ring, dist) => {
      for (const cell of ring) {
        weights[cell] = (weights[cell] || 0) + 1 - dist * step;
      }
    });
  }
  return weights;
}
通过网格距离的线性衰减,将每个点的影响扩散到周围单元。
js
function weightWithFalloff(points, res, kRadius) {
  const weights = {};
  const step = 1 / (kRadius + 1);
  for (const { lat, lng } of points) {
    const origin = h3.latLngToCell(lat, lng, res);
    const rings = h3.gridDiskDistances(origin, kRadius);
    rings.forEach((ring, dist) => {
      for (const cell of ring) {
        weights[cell] = (weights[cell] || 0) + 1 - dist * step;
      }
    });
  }
  return weights;
}

Compact and uncompact cell sets

压缩与解压缩单元集

Reduce storage for large cell sets. All input cells must share the same resolution.
js
const cells = h3.polygonToCells(polygon, 9);
const compact = h3.compactCells(cells); // mixed-resolution, fewer cells
const restored = h3.uncompactCells(compact, 9); // back to uniform res 9
减少大型单元集的存储空间。所有输入单元必须具有相同的分辨率。
js
const cells = h3.polygonToCells(polygon, 9);
const compact = h3.compactCells(cells); // 混合分辨率,单元数量更少
const restored = h3.uncompactCells(compact, 9); // 恢复为统一分辨率9

GeoJSON Interop

GeoJSON互操作

Coordinate Order

坐标顺序

h3-js defaults to lat/lng (
[37.77, -122.41]
). GeoJSON requires lng/lat (
[-122.41, 37.77]
). Pass
true
for the
isGeoJson
/
formatAsGeoJson
parameter to switch. Most common integration bug: forgetting this.
h3-js默认使用纬度/经度
[37.77, -122.41]
)。GeoJSON要求使用经度/纬度
[-122.41, 37.77]
)。将
isGeoJson
/
formatAsGeoJson
参数设为
true
即可切换顺序。最常见的集成错误:忘记设置此参数。

Convert a single cell to a GeoJSON Feature

将单个单元转换为GeoJSON Feature

cellToBoundary
returns coordinate arrays, not GeoJSON objects. Wrap manually.
js
function cellToFeature(cell, properties = {}) {
  const boundary = h3.cellToBoundary(cell, true); // true = GeoJSON [lng, lat] order
  return {
    type: "Feature",
    properties: { h3index: cell, ...properties },
    geometry: {
      type: "Polygon",
      coordinates: [[...boundary, boundary[0]]], // close the ring
    },
  };
}
cellToBoundary
返回坐标数组,而非GeoJSON对象。需手动封装。
js
function cellToFeature(cell, properties = {}) {
  const boundary = h3.cellToBoundary(cell, true); // true = GeoJSON [经度, 纬度]顺序
  return {
    type: "Feature",
    properties: { h3index: cell, ...properties },
    geometry: {
      type: "Polygon",
      coordinates: [[...boundary, boundary[0]]], // 闭合环
    },
  };
}

Convert a set of cells to a GeoJSON FeatureCollection

将单元集转换为GeoJSON FeatureCollection

One polygon feature per cell — useful for choropleth styling.
js
function cellsToFeatureCollection(cells, getProperties = () => ({})) {
  return {
    type: "FeatureCollection",
    features: cells.map((cell) => cellToFeature(cell, getProperties(cell))),
  };
}
每个单元对应一个多边形Feature — 适用于分级统计图样式。
js
function cellsToFeatureCollection(cells, getProperties = () => ({})) {
  return {
    type: "FeatureCollection",
    features: cells.map((cell) => cellToFeature(cell, getProperties(cell))),
  };
}

Convert a set of cells to a merged GeoJSON outline

将单元集转换为合并的GeoJSON轮廓

cellsToMultiPolygon
merges adjacent cells into polygon outlines. All cells must share the same resolution with no duplicates — undefined behavior otherwise.
js
function cellsToOutlineFeature(cells) {
  const coordinates = h3.cellsToMultiPolygon(cells, true); // true = GeoJSON order
  return {
    type: "Feature",
    properties: {},
    geometry: { type: "MultiPolygon", coordinates },
  };
}
cellsToMultiPolygon
会将相邻单元合并为多边形轮廓。所有单元必须具有相同分辨率且无重复 — 否则行为未定义。
js
function cellsToOutlineFeature(cells) {
  const coordinates = h3.cellsToMultiPolygon(cells, true); // true = GeoJSON顺序
  return {
    type: "Feature",
    properties: {},
    geometry: { type: "MultiPolygon", coordinates },
  };
}

Convert a GeoJSON polygon to H3 cells

将GeoJSON多边形转换为H3单元

Pass
isGeoJson = true
so h3-js reads coordinates in lng/lat order.
js
function featureToCells(feature, res) {
  const coords = feature.geometry.coordinates;
  // coords[0] = outer ring, coords[1..n] = holes
  return h3.polygonToCells(coords, res, true);
}
传入
isGeoJson = true
,使h3-js以经度/纬度顺序读取坐标。
js
function featureToCells(feature, res) {
  const coords = feature.geometry.coordinates;
  // coords[0] = 外环, coords[1..n] = 内环
  return h3.polygonToCells(coords, res, true);
}

Control containment mode when filling polygons

填充多边形时控制包含模式

polygonToCells
uses center containment by default — includes a cell only if its center is inside the polygon. Use
polygonToCellsExperimental
for other modes.
js
// Include cells that overlap the polygon boundary at all (fuller coverage)
h3.polygonToCellsExperimental(
  coords,
  res,
  h3.POLYGON_TO_CELLS_FLAGS.containment_overlapping,
  true,
);

// Include only cells fully contained within the polygon (stricter)
h3.polygonToCellsExperimental(
  coords,
  res,
  h3.POLYGON_TO_CELLS_FLAGS.containment_full,
  true,
);
polygonToCells
默认使用中心包含模式 — 仅当单元中心位于多边形内部时才包含该单元。可使用
polygonToCellsExperimental
选择其他模式。
js
// 包含所有与多边形边界有重叠的单元(覆盖范围更广)
h3.polygonToCellsExperimental(
  coords,
  res,
  h3.POLYGON_TO_CELLS_FLAGS.containment_overlapping,
  true,
);

// 仅包含完全位于多边形内部的单元(更严格)
h3.polygonToCellsExperimental(
  coords,
  res,
  h3.POLYGON_TO_CELLS_FLAGS.containment_full,
  true,
);

geojson2h3 companion library

geojson2h3配套库

geojson2h3
provides higher-level conversion helpers:
npm install geojson2h3
js
import geojson2h3 from "geojson2h3";

// GeoJSON Feature → cell set
const cells = geojson2h3.featureToH3Set(geojsonFeature, res);

// Cell set → GeoJSON FeatureCollection (one Feature per cell)
const fc = geojson2h3.h3SetToFeatureCollection(cells, (cell) => ({
  value: data[cell],
}));

// Cell set → single merged GeoJSON Feature (outline)
const outline = geojson2h3.h3SetToFeature(cells);
geojson2h3
提供了更高级别的转换工具:
npm install geojson2h3
js
import geojson2h3 from "geojson2h3";

// GeoJSON Feature → 单元集
const cells = geojson2h3.featureToH3Set(geojsonFeature, res);

// 单元集 → GeoJSON FeatureCollection(每个单元对应一个Feature)
const fc = geojson2h3.h3SetToFeatureCollection(cells, (cell) => ({
  value: data[cell],
}));

// 单元集 → 单个合并的GeoJSON Feature(轮廓)
const outline = geojson2h3.h3SetToFeature(cells);

API Reference

API参考

Indexing

索引

js
h3.latLngToCell(lat, lng, resolution)    // → "85283473fffffff"
h3.cellToLatLng(cell)                     // → [lat, lng] (center point)
h3.cellToBoundary(cell, formatAsGeoJson?) // → [[lat, lng], ...] (vertices)
js
h3.latLngToCell(lat, lng, resolution)    // → "85283473fffffff"
h3.cellToLatLng(cell)                     // → [lat, lng](中心点)
h3.cellToBoundary(cell, formatAsGeoJson?) // → [[lat, lng], ...](顶点)

Inspection

检查

js
h3.getResolution(cell); // → number (0-15)
h3.isValidCell(cell); // → boolean
h3.isPentagon(cell); // → boolean
h3.isResClassIII(cell); // → boolean
h3.getBaseCellNumber(cell); // → number (0-121)
h3.getIcosahedronFaces(cell); // → [faceNum, ...]
js
h3.getResolution(cell); // → 数字(0-15)
h3.isValidCell(cell); // → 布尔值
h3.isPentagon(cell); // → 布尔值
h3.isResClassIII(cell); // → 布尔值
h3.getBaseCellNumber(cell); // → 数字(0-121)
h3.getIcosahedronFaces(cell); // → [faceNum, ...]

Hierarchy

层级

js
h3.cellToParent(cell, parentRes); // → cell
h3.cellToChildren(cell, childRes); // → [cell, ...]
h3.cellToCenterChild(cell, childRes); // → cell
h3.compactCells(cells); // → mixed-resolution compact set
h3.uncompactCells(cells, res); // → uniform-resolution expanded set
h3.cellToChildPos(child, parentRes); // → position index
h3.childPosToCell(childPos, parent, childRes); // → cell
js
h3.cellToParent(cell, parentRes); // → 单元
h3.cellToChildren(cell, childRes); // → [cell, ...]
h3.cellToCenterChild(cell, childRes); // → 单元
h3.compactCells(cells); // → 混合分辨率的压缩单元集
h3.uncompactCells(cells, res); // → 统一分辨率的展开单元集
h3.cellToChildPos(child, parentRes); // → 位置索引
h3.childPosToCell(childPos, parent, childRes); // → 单元

Traversal

遍历

js
h3.gridDisk(origin, k); // filled disk within k steps (safe near pentagons)
h3.gridDiskDistances(origin, k); // disk grouped by distance → [[ring0], [ring1], ...]
h3.gridRing(origin, k); // hollow ring at exactly k steps (may throw near pentagons)
h3.gridDistance(a, b); // grid distance (same resolution; may fail across pentagons)
h3.gridPathCells(start, end); // path of cells (inclusive; may fail across pentagons)
h3.cellToLocalIj(origin, cell); // → {i, j} (experimental; local to origin)
h3.localIjToCell(origin, { i, j }); // → cell (experimental)
js
h3.gridDisk(origin, k); // k步范围内的填充圆盘(在五边形附近安全)
h3.gridDiskDistances(origin, k); // 按距离分组的圆盘 → [[ring0], [ring1], ...]
h3.gridRing(origin, k); // 恰好k步的空心环(在五边形附近可能抛出错误)
h3.gridDistance(a, b); // 网格距离(需相同分辨率;可能因五边形变形而失效)
h3.gridPathCells(start, end); // 单元路径(包含起点和终点;可能因五边形变形而失效)
h3.cellToLocalIj(origin, cell); // → {i, j}(实验性;相对于原点的局部坐标)
h3.localIjToCell(origin, { i, j }); // → 单元(实验性)

Regions

区域

js
// polygon = array of coordinate rings; first is outer boundary, rest are holes
h3.polygonToCells(polygon, res, isGeoJson?)
h3.cellsToMultiPolygon(cells, formatAsGeoJson?)  // all cells same res, no duplicates
h3.polygonToCellsExperimental(polygon, res, flags, isGeoJson?)
// flags: containment_center (default), containment_full, containment_overlapping, containment_overlapping_bbox
js
// polygon = 坐标环数组;第一个是外边界,其余是内环
h3.polygonToCells(polygon, res, isGeoJson?)
h3.cellsToMultiPolygon(cells, formatAsGeoJson?)  // 所有单元需相同分辨率且无重复
h3.polygonToCellsExperimental(polygon, res, flags, isGeoJson?)
// flags: containment_center(默认), containment_full, containment_overlapping, containment_overlapping_bbox

Directed Edges

有向边

js
h3.areNeighborCells(a, b); // → boolean
h3.cellsToDirectedEdge(origin, dest); // → edge index
h3.getDirectedEdgeOrigin(edge); // → cell
h3.getDirectedEdgeDestination(edge); // → cell
h3.directedEdgeToCells(edge); // → [origin, dest]
h3.originToDirectedEdges(cell); // → [edge, ...] (all 6 or 5 edges)
h3.directedEdgeToBoundary(edge); // → [[lat, lng], ...]
js
h3.areNeighborCells(a, b); // → 布尔值
h3.cellsToDirectedEdge(origin, dest); // → 边索引
h3.getDirectedEdgeOrigin(edge); // → 单元
h3.getDirectedEdgeDestination(edge); // → 单元
h3.directedEdgeToCells(edge); // → [origin, dest]
h3.originToDirectedEdges(cell); // → [edge, ...](所有6条或5条边)
h3.directedEdgeToBoundary(edge); // → [[lat, lng], ...]

Vertexes

顶点

js
h3.cellToVertex(cell, vertexNum); // → vertex index (0-5 hex, 0-4 pentagon)
h3.cellToVertexes(cell); // → [vertex, ...]
h3.vertexToLatLng(vertex); // → [lat, lng]
h3.isValidVertex(vertex); // → boolean
js
h3.cellToVertex(cell, vertexNum); // → 顶点索引(六边形0-5,五边形0-4)
h3.cellToVertexes(cell); // → [vertex, ...]
h3.vertexToLatLng(vertex); // → [lat, lng]
h3.isValidVertex(vertex); // → 布尔值

Metrics & Utilities

指标与工具

js
h3.getHexagonAreaAvg(res, h3.UNITS.km2); // average hex area at resolution
h3.getHexagonEdgeLengthAvg(res, h3.UNITS.km); // average edge length at resolution
h3.cellArea(cell, h3.UNITS.km2); // exact area of a specific cell
h3.edgeLength(edge, h3.UNITS.km); // exact length of a specific edge
h3.getNumCells(res); // total cell count at resolution
h3.greatCircleDistance(point1, point2, h3.UNITS.km); // haversine distance ([lat,lng] points)
h3.getRes0Cells(); // all 122 base cells
h3.getPentagons(res); // 12 pentagons at resolution
h3.degsToRads(degrees);
h3.radsToDegs(radians);
Units:
h3.UNITS.km2
,
h3.UNITS.m2
,
h3.UNITS.rads2
,
h3.UNITS.km
,
h3.UNITS.m
,
h3.UNITS.rads
js
h3.getHexagonAreaAvg(res, h3.UNITS.km2); // 该分辨率下的平均六边形面积
h3.getHexagonEdgeLengthAvg(res, h3.UNITS.km); // 该分辨率下的平均边长
h3.cellArea(cell, h3.UNITS.km2); // 特定单元的精确面积
h3.edgeLength(edge, h3.UNITS.km); // 特定边的精确长度
h3.getNumCells(res); // 该分辨率下的总单元数
h3.greatCircleDistance(point1, point2, h3.UNITS.km); // 大圆距离([纬度,经度]点)
h3.getRes0Cells(); // 所有122个基础单元
h3.getPentagons(res); // 该分辨率下的12个五边形
h3.degsToRads(degrees);
h3.radsToDegs(radians);
单位:
h3.UNITS.km2
,
h3.UNITS.m2
,
h3.UNITS.rads2
,
h3.UNITS.km
,
h3.UNITS.m
,
h3.UNITS.rads

v3 to v4 Migration

v3到v4迁移指南

Function names changed in v4. The grid itself is unchanged — indexes from v3 are valid in v4.
v3v4
geoToH3
latLngToCell
h3ToGeo
cellToLatLng
h3ToGeoBoundary
cellToBoundary
kRing
gridDisk
hexRing
gridRing
h3Distance
gridDistance
h3ToParent
cellToParent
h3ToChildren
cellToChildren
polyfill
polygonToCells
h3SetToMultiPolygon
cellsToMultiPolygon
compact
compactCells
uncompact
uncompactCells
h3IndexesAreNeighbors
areNeighborCells
See reference.md for the complete function name mapping.
v4中函数名称已更改。网格本身未变 — v3的索引在v4中仍然有效。
v3v4
geoToH3
latLngToCell
h3ToGeo
cellToLatLng
h3ToGeoBoundary
cellToBoundary
kRing
gridDisk
hexRing
gridRing
h3Distance
gridDistance
h3ToParent
cellToParent
h3ToChildren
cellToChildren
polyfill
polygonToCells
h3SetToMultiPolygon
cellsToMultiPolygon
compact
compactCells
uncompact
uncompactCells
h3IndexesAreNeighbors
areNeighborCells
完整的函数名称映射请参考reference.md

Full Documentation

完整文档

Complete API reference, algorithm internals, community libraries, and 40+ Observable notebooks in reference.md.
完整的API参考、算法内部原理、社区库以及40多个Observable笔记本,请查看reference.md