### Install h3-js Package Source: https://github.com/uber/h3-js/blob/master/README.md Installs the h3-js library using npm. This command should be run in your project's root directory. ```bash npm install h3-js ``` -------------------------------- ### h3.cellToChildrenSize Source: https://github.com/uber/h3-js/blob/master/README.md Get the number of children for a cell at a given resolution. ```APIDOC ## h3.cellToChildrenSize(h3Index, res) ### Description Get the number of children for a cell at a given resolution. ### Method `GET` (conceptual, this is a function call) ### Endpoint `/uber/h3-js/cellToChildrenSize` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **h3Index** (`H3IndexInput`) - Required - H3 index to get child count for - **res** (`number`) - Required - Child resolution ### Request Example ```json { "h3Index": "85283082807ffff", "res": 7 } ``` ### Response #### Success Response (200) - **count** (`number`) - Number of children at res for the given cell #### Response Example ```json { "count": 7 } ``` #### Throws - `H3Error` If cell or parentRes are invalid ``` -------------------------------- ### Legacy API for h3-js v3 Compatibility Source: https://github.com/uber/h3-js/blob/master/doc-files/README.tmpl.md Provides an example of using the legacy API wrapper from 'h3-js/legacy' to maintain compatibility with older H3 v3 function names while utilizing the underlying H3 v4 functions. This is intended as a transitional tool. ```javascript import {geoToH3} from 'h3-js/legacy'; const h3Index = geoToH3(37.3615593, -122.0553238, 7); ``` -------------------------------- ### Development Commands for h3-js Source: https://github.com/uber/h3-js/blob/master/README.md Provides essential commands for developing the h3-js library, including dependency installation, linting, testing, and code formatting. These commands utilize yarn for package management. ```bash yarn yarn lint yarn test yarn prettier ``` -------------------------------- ### h3.vertexToLatLng Source: https://github.com/uber/h3-js/blob/master/README.md Gets the latitude and longitude coordinates of a given H3 vertex index. ```APIDOC ## GET /h3/vertex/to/latlng ### Description Gets the latitude and longitude coordinates of a given H3 vertex index. ### Method GET ### Endpoint /h3/vertex/to/latlng ### Parameters #### Query Parameters - **h3Index** (string | Array) - Required - The H3 index of the vertex. ### Response #### Success Response (200) - **latitude** (number) - The latitude of the vertex. - **longitude** (number) - The longitude of the vertex. #### Response Example ```json { "latitude": 37.7749, "longitude": -122.4194 } ``` ### Errors - **H3Error**: If the input is invalid. ``` -------------------------------- ### h3.cellToLatLng Source: https://github.com/uber/h3-js/blob/master/README.md Get the lat,lon center of a given hexagon (or pentagon). ```APIDOC ## h3.cellToLatLng(h3Index) ### Description Get the lat,lon center of a given hexagon (or pentagon). ### Method `GET` (conceptual, this is a function call) ### Endpoint `/uber/h3-js/cellToLatLng` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **h3Index** (`H3IndexInput`) - Required - H3 index ### Request Example ```json { "h3Index": "89283082807ffff" } ``` ### Response #### Success Response (200) - **coordinates** (`CoordPair`) - Point as a [lat, lng] pair #### Response Example ```json { "coordinates": [37.7749, -122.4194] } ``` #### Throws - `H3Error` If input is invalid ``` -------------------------------- ### h3.cellToParent Source: https://github.com/uber/h3-js/blob/master/README.md Get the parent of the given hexagon at a particular resolution. ```APIDOC ## h3.cellToParent(h3Index, res) ### Description Get the parent of the given hexagon at a particular resolution. ### Method `GET` (conceptual, this is a function call) ### Endpoint `/uber/h3-js/cellToParent` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **h3Index** (`H3IndexInput`) - Required - H3 index to get parent for - **res** (`number`) - Required - Resolution of hexagon to return ### Request Example ```json { "h3Index": "89283082807ffff", "res": 5 } ``` ### Response #### Success Response (200) - **parentIndex** (`H3Index`) - H3 index of parent, or null for invalid input #### Response Example ```json { "parentIndex": "85283082807ffff" } ``` #### Throws - `H3Error` If input is invalid ``` -------------------------------- ### h3.getIcosahedronFaces Source: https://github.com/uber/h3-js/blob/master/README.md Get the indices of all icosahedron faces intersected by a given H3 index. ```APIDOC ## h3.getIcosahedronFaces(h3Index) ### Description Get the indices of all icosahedron faces intersected by a given H3 index. ### Method `GET` (conceptual, this is a function call) ### Endpoint `/uber/h3-js/getIcosahedronFaces` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **h3Index** (`H3IndexInput`) - Required - H3 index to get faces for ### Request Example ```json { "h3Index": "89283082807ffff" } ``` ### Response #### Success Response (200) - **faces** (`Array`) - Indices (0-19) of all intersected faces #### Response Example ```json { "faces": [0, 1, 2] } ``` #### Throws - `H3Error` If input is invalid ``` -------------------------------- ### h3.cellToBoundary Source: https://github.com/uber/h3-js/blob/master/README.md Get the vertices of a given hexagon (or pentagon), as an array of [lat, lng] points. ```APIDOC ## h3.cellToBoundary(h3Index, [formatAsGeoJson]) ### Description Get the vertices of a given hexagon (or pentagon), as an array of [lat, lng] points. For pentagons and hexagons on the edge of an icosahedron face, this function may return up to 10 vertices. ### Method `GET` (conceptual, this is a function call) ### Endpoint `/uber/h3-js/cellToBoundary` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **h3Index** (`H3IndexInput`) - Required - H3 index - **formatAsGeoJson** (`boolean`) - Optional - Whether to provide GeoJSON output: [lng, lat], closed loops ### Request Example ```json { "h3Index": "89283082807ffff", "formatAsGeoJson": false } ``` ### Response #### Success Response (200) - **boundary** (`Array`) - Array of [lat, lng] pairs #### Response Example ```json { "boundary": [[37.7749, -122.4194], [37.775, -122.4195]] } ``` #### Throws - `H3Error` If input is invalid ``` -------------------------------- ### h3.cellToChildren Source: https://github.com/uber/h3-js/blob/master/README.md Get the children/descendents of the given hexagon at a particular resolution. ```APIDOC ## h3.cellToChildren(h3Index, res) ### Description Get the children/descendents of the given hexagon at a particular resolution. ### Method `GET` (conceptual, this is a function call) ### Endpoint `/uber/h3-js/cellToChildren` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **h3Index** (`H3IndexInput`) - Required - H3 index to get children for - **res** (`number`) - Required - Resolution of hexagons to return ### Request Example ```json { "h3Index": "85283082807ffff", "res": 7 } ``` ### Response #### Success Response (200) - **children** (`Array`) - H3 indexes of children, or empty array for invalid input #### Response Example ```json { "children": ["89283082807ffff", "89283082808ffff"] } ``` #### Throws - `H3Error` If resolution is invalid or output is too large for JS ``` -------------------------------- ### h3.latLngToCell Source: https://github.com/uber/h3-js/blob/master/README.md Get the hexagon (or pentagon) containing a lat,lon point. ```APIDOC ## h3.latLngToCell(lat, lng, res) ### Description Get the hexagon (or pentagon) containing a lat,lon point. ### Method `POST` (conceptual, this is a function call) ### Endpoint `/uber/h3-js/latLngToCell` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **lat** (`number`) - Required - Latitude of point - **lng** (`number`) - Required - Longtitude of point - **res** (`number`) - Required - Resolution of cell to return ### Request Example ```json { "lat": 37.7749, "lng": -122.4194, "res": 7 } ``` ### Response #### Success Response (200) - **h3Index** (`H3Index`) - H3 index #### Response Example ```json { "h3Index": "89283082807ffff" } ``` #### Throws - `H3Error` If input is invalid ``` -------------------------------- ### Useful h3-js Algorithms: Grid and Polygon Operations Source: https://github.com/uber/h3-js/blob/master/doc-files/README.tmpl.md Showcases H3 algorithms for finding neighboring hexagons within a specified distance (gridDisk) and for determining which hexagons intersect with a given polygon (polygonToCells). It also includes an example of generating a GeoJSON-style MultiPolygon outline from a set of hexagons. ```javascript // Get all neighbors within 1 step of the hexagon const disk = h3.gridDisk(h3Index, 1); // -> ['87283472bffffff', '87283472affffff', ...] // Get the set of hexagons within a polygon const polygon = [ [37.813318999983238, -122.4089866999972145], [37.7198061999978478, -122.3544736999993603], [37.8151571999998453, -122.4798767000009008] ]; const hexagons = h3.polygonToCells(polygon, 7); // -> ['872830828ffffff', '87283082effffff', ...] // Get the outline of a set of hexagons, as a GeoJSON-style MultiPolygon const coordinates = h3.cellsToMultiPolygon(hexagons, true); // -> [[[[-122.37681938644465, 37.76546768434345], [-122.3856345540363,37.776004200673846], ...]]] ``` -------------------------------- ### h3.polygonToCellsExperimental Source: https://github.com/uber/h3-js/blob/master/README.md Get all hexagons with centers contained in a given polygon. The polygon is specified with GeoJson semantics as an array of loops. ```APIDOC ## POST /h3/polygonToCellsExperimental ### Description Get all hexagons with centers contained in a given polygon. The polygon is specified with GeoJson semantics as an array of loops. Each loop is an array of [lat, lng] pairs (or [lng, lat] if isGeoJson is specified). The first loop is the perimeter of the polygon, and subsequent loops are expected to be holes. ### Method POST ### Endpoint /h3/polygonToCellsExperimental ### Parameters #### Request Body - **coordinates** (Array> | Array>>) - Required - Array of loops, or a single loop - **res** (number) - Required - Resolution of hexagons to return - **flags** (string) - Required - Value from POLYGON_TO_CELLS_FLAGS - **isGeoJson** (boolean) - Optional - Whether to expect GeoJson-style [lng, lat] pairs instead of [lat, lng] ### Response #### Success Response (200) - **Array** - H3 indexes for all hexagons in polygon #### Error Response - **H3Error** - If input is invalid or output is too large for JS ``` -------------------------------- ### Utility Functions Source: https://context7.com/uber/h3-js/llms.txt Utility functions for H3-JS, including getting the number of cells at a resolution, retrieving base cells and pentagons, and checking if an index is a pentagon. ```APIDOC ## getNumCells ### Description Returns the total number of H3 cells at a given resolution. ### Method N/A (Function calls) ### Endpoint N/A ### Parameters None ### Request Example ```javascript import { getNumCells } from 'h3-js'; console.log(getNumCells(0)); // 122 console.log(getNumCells(5)); // 2,016,842 console.log(getNumCells(10)); // 33,897,029,882 console.log(getNumCells(15)); // 569,707,381,193,162 ``` ### Response #### Success Response (200) - **numberOfCells** (number) - The total number of H3 cells at the specified resolution. #### Response Example ```json { "numberOfCells": 122 } ``` ## getRes0Cells ### Description Returns all 122 resolution 0 base cells. ### Method N/A (Function calls) ### Endpoint N/A ### Parameters None ### Request Example ```javascript import { getRes0Cells, isValidCell } from 'h3-js'; const baseCells = getRes0Cells(); console.log(baseCells.length); // 122 console.log(baseCells.every(isValidCell)); // true ``` ### Response #### Success Response (200) - **baseCells** (Array) - An array of H3 indexes for all resolution 0 cells. #### Response Example ```json [ "8009fffffffffff", "8009ffff7ffff", ... ] ``` ## getPentagons ### Description Returns the 12 pentagon cells at a given resolution. ### Method N/A (Function calls) ### Endpoint N/A ### Parameters None ### Request Example ```javascript import { getPentagons, isPentagon } from 'h3-js'; const pentagons = getPentagons(5); console.log(pentagons.length); // 12 console.log(pentagons.every(isPentagon)); // true ``` ### Response #### Success Response (200) - **pentagons** (Array) - An array of H3 indexes for all pentagon cells at the specified resolution. #### Response Example ```json [ "85283473fffffff", "85283472fffffff", ... ] ``` ## isPentagon ### Description Checks if an H3 index represents a pentagon cell (12 per resolution). ### Method N/A (Function calls) ### Endpoint N/A ### Parameters None ### Request Example ```javascript import { isPentagon } from 'h3-js'; console.log(isPentagon('8928308280fffff')); // false (hexagon) console.log(isPentagon('821c07fffffffff')); // true (pentagon) ``` ### Response #### Success Response (200) - **isPentagon** (boolean) - True if the H3 index is a pentagon, false otherwise. #### Response Example ```json { "isPentagon": true } ``` ``` -------------------------------- ### Get Vertex Indexes and Coordinates for H3 Cells Source: https://context7.com/uber/h3-js/llms.txt Functions to retrieve vertex information for H3 cells. `cellToVertexes` returns all vertex H3 indexes for a cell, while `cellToVertex` gets a specific vertex by its index (0-5). `vertexToLatLng` then converts a vertex H3 index to its geographic coordinates (latitude and longitude). `isValidVertex` can be used to check if a given index represents a valid vertex. ```javascript import { cellToVertex, cellToVertexes, isValidVertex, vertexToLatLng, cellToBoundary } from 'h3-js'; const h3Index = '823d6ffffffffff'; // Get all vertices const vertices = cellToVertexes(h3Index); console.log(vertices.length); // 6 for hexagon, 5 for pentagon console.log(vertices.every(isValidVertex)); // true // Get specific vertex (0-5 for hexagon, 0-4 for pentagon) const vertex0 = cellToVertex(h3Index, 0); console.log(vertex0); // Get coordinates for each vertex const vertexCoords = vertices.map(v => vertexToLatLng(v)); // Vertex coordinates match cell boundary vertices const boundary = cellToBoundary(h3Index); console.log(vertexCoords.length === boundary.length); // true ``` -------------------------------- ### Cell Vertices Source: https://context7.com/uber/h3-js/llms.txt Functions to get vertex information for H3 cells. ```APIDOC ## GET /h3/cell/vertices ### Description Retrieves vertex indices and their geographic coordinates for a given H3 cell. ### Method GET ### Endpoint /h3/cell/vertices ### Parameters #### Query Parameters - **h3Index** (string) - Required - The H3 index of the cell. - **vertexIndex** (integer) - Optional - The specific vertex index (0-5 for hexagons, 0-4 for pentagons) to retrieve. If not provided, all vertices are returned. ### Response #### Success Response (200) - **vertices** (array) - An array of vertex indices (if `vertexIndex` is not provided). - **vertex** (string) - The H3 index of the specified vertex (if `vertexIndex` is provided). - **latLng** (object) - An object containing the latitude and longitude of the vertex (if `vertexIndex` is provided). - **lat** (number) - Latitude. - **lng** (number) - Longitude. #### Response Example (all vertices) ```json { "vertices": [ "803d6ffffffffff", "803d6ffffffffd1", "803d6ffffffff71", "803d6ffffffffb1", "803d6ffffffff91", "803d6ffffffffd1" ] } ``` #### Response Example (specific vertex) ```json { "vertex": "803d6ffffffffd1", "latLng": { "lat": 30.41862280003655, "lng": -110.537109375 } } ``` ``` -------------------------------- ### h3.polygonToCells Source: https://github.com/uber/h3-js/blob/master/README.md Get all hexagons with centers contained in a given polygon. The polygon is specified with GeoJson semantics as an array of loops. ```APIDOC ## POST /h3/polygonToCells ### Description Get all hexagons with centers contained in a given polygon. The polygon is specified with GeoJson semantics as an array of loops. Each loop is an array of [lat, lng] pairs (or [lng, lat] if isGeoJson is specified). The first loop is the perimeter of the polygon, and subsequent loops are expected to be holes. ### Method POST ### Endpoint /h3/polygonToCells ### Parameters #### Request Body - **coordinates** (Array> | Array>>) - Required - Array of loops, or a single loop - **res** (number) - Required - Resolution of hexagons to return - **isGeoJson** (boolean) - Optional - Whether to expect GeoJson-style [lng, lat] pairs instead of [lat, lng] ### Response #### Success Response (200) - **Array** - H3 indexes for all hexagons in polygon #### Error Response - **H3Error** - If input is invalid or output is too large for JS ``` -------------------------------- ### Building h3-js Core Library with Emscripten using Docker Source: https://github.com/uber/h3-js/blob/master/README.md Instructions for building the core H3 C library for the h3-js project using Emscripten and Docker. This is the recommended method for local builds from source. ```bash yarn docker-boot yarn build-emscripten ``` -------------------------------- ### Import h3-js Library Source: https://github.com/uber/h3-js/blob/master/doc-files/README.tmpl.md Demonstrates how to import the h3-js library using different module systems (ES6, CommonJS) and how to include it via a pre-bundled script tag for browser usage. ```javascript import {latLngToCell} from "h3-js"; ``` ```javascript const h3 = require("h3-js"); ``` ```html ``` -------------------------------- ### H3 Useful Algorithms: Grid Disk and Polygon to Cells Source: https://github.com/uber/h3-js/blob/master/README.md Demonstrates advanced h3-js algorithms: `gridDisk` to find all hexagons within a specified distance (k-ring) from a given H3 index, and `polygonToCells` to identify all hexagons that intersect with a given geographic polygon. ```javascript // Get all neighbors within 1 step of the hexagon const disk = h3.gridDisk(h3Index, 1); // -> ['87283472bffffff', '87283472affffff', ...] // Get the set of hexagons within a polygon const polygon = [ [37.813318999983238, -122.4089866999972145], [37.7198061999978478, -122.3544736999993603], [37.8151571999998453, -122.4798767000009008] ]; const hexagons = h3.polygonToCells(polygon, 7); // -> ['872830828ffffff', '87283082effffff', ...] ``` -------------------------------- ### Running Benchmarks for h3-js in a Browser Source: https://github.com/uber/h3-js/blob/master/README.md Command to execute the benchmark suite for the h3-js library in a web browser environment. This allows for performance testing across different platforms. ```bash yarn benchmark-browser ``` -------------------------------- ### Running Benchmarks for h3-js in Node.js Source: https://github.com/uber/h3-js/blob/master/README.md Command to execute the benchmark suite for the h3-js library within a Node.js environment. Benchmarks are crucial for performance analysis, especially for functions used in high-frequency operations. ```bash yarn benchmark-node ``` -------------------------------- ### Import h3-js CommonJS Source: https://github.com/uber/h3-js/blob/master/README.md Shows how to import the entire h3-js library using CommonJS syntax, suitable for Node.js environments or bundlers configured for CommonJS. ```javascript const h3 = require("h3-js"); ``` -------------------------------- ### Import h3-js ES6 Modules Source: https://github.com/uber/h3-js/blob/master/README.md Demonstrates how to import specific functions from the h3-js library using ES6 module syntax. This is the recommended way for modern JavaScript projects. ```javascript import {latLngToCell} from "h3-js"; ``` -------------------------------- ### h3.cellsToMultiPolygon Source: https://github.com/uber/h3-js/blob/master/README.md Get the outlines of a set of H3 hexagons, returned in GeoJSON MultiPolygon format. ```APIDOC ## POST /h3/cellsToMultiPolygon ### Description Get the outlines of a set of H3 hexagons, returned in GeoJSON MultiPolygon format (an array of polygons, each with an array of loops, each an array of coordinates). Coordinates are returned as [lat, lng] pairs unless GeoJSON is requested. It is the responsibility of the caller to ensure that all hexagons in the set have the same resolution and that the set contains no duplicates. Behavior is undefined if duplicates or multiple resolutions are present, and the algorithm may produce unexpected or invalid polygons. ### Method POST ### Endpoint /h3/cellsToMultiPolygon ### Parameters #### Request Body - **h3Indexes** (Array) - Required - H3 indexes to get outlines for - **formatAsGeoJson** (boolean) - Optional - Whether to provide GeoJSON output: [lng, lat], closed loops ### Response #### Success Response (200) - **Array>>** - MultiPolygon-style output. #### Error Response - **H3Error** - If the input is invalid ``` -------------------------------- ### h3.getResolution Source: https://github.com/uber/h3-js/blob/master/README.md Returns the resolution of an H3 index. ```APIDOC ## h3.getResolution(h3Index) ### Description Returns the resolution of an H3 index. ### Method `GET` (conceptual, this is a function call) ### Endpoint `/uber/h3-js/getResolution` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **h3Index** (`H3IndexInput`) - Required - H3 index to get resolution ### Request Example ```json { "h3Index": "89283082807ffff" } ``` ### Response #### Success Response (200) - **resolution** (`number`) - The number (0-15) resolution, or -1 if invalid #### Response Example ```json { "resolution": 7 } ``` ``` -------------------------------- ### H3 Constants and Utilities Source: https://github.com/uber/h3-js/blob/master/README.md Provides access to H3 constants like units and polygon flags, as well as utility functions for unit conversions. ```APIDOC ## H3 Constants ### h3.UNITS Length/Area units **Properties**: - **m** (string) - **m2** (string) - **km** (string) - **km2** (string) - **rads** (string) - **rads2** (string) ### h3.POLYGON_TO_CELLS_FLAGS Mode flags for polygonToCells **Properties**: - **containmentCenter** (string) - **containmentFull** (string) - **containmentOverlapping** (string) - **containmentOverlappingBbox** (string) ## Utility Functions ### h3.degsToRads(deg) ### Description Convert degrees to radians. ### Method `h3.degsToRads` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "deg": 180 } ``` ### Response #### Success Response (200) - **rad** (number) - Radians #### Response Example ```json { "rad": 3.141592653589793 } ``` ## h3.radsToDegs(rad) ### Description Convert radians to degrees. ### Method `h3.radsToDegs` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "rad": 3.141592653589793 } ``` ### Response #### Success Response (200) - **deg** (number) - Degrees #### Response Example ```json { "deg": 180 } ``` ``` -------------------------------- ### Include h3-js via Script Tag Source: https://github.com/uber/h3-js/blob/master/README.md Illustrates how to include the h3-js library in an HTML file using a CDN link. The library will be available globally as an `h3` object. ```html ``` -------------------------------- ### gridPathCells Source: https://context7.com/uber/h3-js/llms.txt Returns an array of H3 indexes representing a path between two cells. The path includes both the start and end cells. ```APIDOC ## gridPathCells ### Description Returns an array of H3 indexes representing a path between two cells. ### Method GET (hypothetical, as this is a library function) ### Endpoint N/A (library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { gridPathCells, latLngToCell } from 'h3-js'; const start = latLngToCell(37.5, -122, 9); const end = latLngToCell(37.6, -121.9, 9); const path = gridPathCells(start, end); console.log(path); ``` ### Response #### Success Response (200) - **Array** of H3 indexes (string) representing the path. #### Response Example ```json [ "8928308280fffff", "8928308281fffff", "...", "89283093407ffff" ] ``` ``` -------------------------------- ### Core h3-js Functions: Conversion and Geometry Source: https://github.com/uber/h3-js/blob/master/doc-files/README.tmpl.md Illustrates core H3 functions for converting latitude/longitude to H3 indices, and retrieving hexagon properties like center coordinates and boundary vertices. ```javascript // Convert a lat/lng point to a hexagon index at resolution 7 const h3Index = h3.latLngToCell(37.3615593, -122.0553238, 7); // -> '87283472bffffff' // Get the center of the hexagon const hexCenterCoordinates = h3.cellToLatLng(h3Index); // -> [37.35171820183272, -122.05032565263946] // Get the vertices of the hexagon const hexBoundary = h3.cellToBoundary(h3Index); // -> [ [37.341099093235684, -122.04156135164334 ], ...] ``` -------------------------------- ### h3.constructCell Source: https://github.com/uber/h3-js/blob/master/README.md Creates a cell from its components (resolution, base cell number, and indexing digits). ```APIDOC ## h3.constructCell(baseCellNumber, digits, res) ### Description Creates a cell from its components (resolution, base cell number, and indexing digits). This is the inverse operation of `getResolution`, `getBaseCellNumber`, and `getIndexDigit`. Only allows creating valid cells. ### Method `POST` (conceptual, this is a function call) ### Endpoint `/uber/h3-js/constructCell` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **baseCellNumber** (`number`) - Required - Base cell number of cell to return - **digits** (`Array`) - Required - Indexing digits of cell to return - **res** (`number`) - Optional - Resolution of cell to return. If not specified, will be inferred from digits. ### Request Example ```json { "baseCellNumber": 1, "digits": [1, 2, 3], "res": 5 } ``` ### Response #### Success Response (200) - **h3Index** (`H3Index`) - H3 index #### Response Example ```json { "h3Index": "89283082807ffff" } ``` #### Throws - `H3Error` If input is invalid ``` -------------------------------- ### h3.getPentagons Source: https://github.com/uber/h3-js/blob/master/README.md Retrieves the twelve pentagon H3 indices at a specified resolution. ```APIDOC ## GET /h3/pentagons ### Description Retrieves the twelve pentagon H3 indices at a specified resolution. ### Method GET ### Endpoint /h3/pentagons ### Parameters #### Query Parameters - **res** (number) - Required - Hexagon resolution. ### Response #### Success Response (200) - **pentagonH3Indexes** (Array) - An array of H3 indices representing the pentagons at the specified resolution. #### Response Example ```json { "pentagonH3Indexes": [ "8009fffffffffff", "800bfffffffffff" ] } ``` ### Errors - **H3Error**: If the resolution is invalid. ``` -------------------------------- ### Get Total Number of H3 Cells with h3-js Source: https://context7.com/uber/h3-js/llms.txt Returns the total count of H3 cells at a specified resolution. This number grows exponentially with resolution. ```javascript import { getNumCells } from 'h3-js'; console.log(getNumCells(0)); // 122 console.log(getNumCells(5)); // 2,016,842 console.log(getNumCells(10)); // 33,897,029,882 console.log(getNumCells(15)); // 569,707,381,193,162 ``` -------------------------------- ### Get Resolution of H3 Cell Index (JavaScript) Source: https://context7.com/uber/h3-js/llms.txt Returns the resolution level (0-15) of an H3 index. If the provided index is invalid, it returns -1. ```javascript import { getResolution, latLngToCell } from 'h3-js'; const h3Index = latLngToCell(37.3615593, -122.0553238, 9); console.log(getResolution(h3Index)); // Output: 9 console.log(getResolution('invalid')); // Output: -1 ``` -------------------------------- ### H3 Useful Algorithms: Cells to MultiPolygon Source: https://github.com/uber/h3-js/blob/master/README.md Shows how to convert a set of H3 indices into a GeoJSON-like MultiPolygon representation. The `true` argument indicates that the output should be formatted as polygons. ```javascript // Get the outline of a set of hexagons, as a GeoJSON-style MultiPolygon const coordinates = h3.cellsToMultiPolygon(hexagons, true); // -> [[[ // MultiPolygon // [[-122.37681938644465, 37.76546768434345], // Polygon // [-122.3856345540363,37.776004200673846], // LinearRing // ... // ]]] ``` -------------------------------- ### Get Resolution 0 Base Cells with h3-js Source: https://context7.com/uber/h3-js/llms.txt Retrieves all 122 base H3 cells that exist at resolution 0. These cells form the foundation of the H3 indexing system. ```javascript import { getRes0Cells, isValidCell } from 'h3-js'; const baseCells = getRes0Cells(); console.log(baseCells.length); // 122 console.log(baseCells.every(isValidCell)); // true ``` -------------------------------- ### h3.originToDirectedEdges Source: https://github.com/uber/h3-js/blob/master/README.md Generates a list of all unidirectional H3 edge indexes originating from a given H3 hexagon index. ```APIDOC ## GET /h3/originToDirectedEdges ### Description Get all of the unidirectional edges with the given H3 index as the origin (i.e. an edge to every neighbor). ### Method GET ### Endpoint /h3/originToDirectedEdges ### Parameters #### Path Parameters None #### Query Parameters - **h3Index** (H3IndexInput) - Required - H3 index of the origin hexagon ### Request Example ``` /h3/originToDirectedEdges?h3Index=8928308280fffff ``` ### Response #### Success Response (200) - **edges** (Array<H3Index>) - List of unidirectional edges #### Response Example ```json { "edges": [ "627613346143414271", "627613346143414270", "627613346143414272", "627613346143414273", "627613346143414274", "627613346143414275" ] } ``` #### Error Response (400) - **error** (H3Error) - If the input is invalid ``` -------------------------------- ### Get Pentagon Cells with h3-js Source: https://context7.com/uber/h3-js/llms.txt Returns the 12 H3 pentagon cell indices for a given resolution. Pentagons are special cells in the H3 system that break the hexagonal grid pattern. ```javascript import { getPentagons, isPentagon } from 'h3-js'; const pentagons = getPentagons(5); console.log(pentagons.length); // 12 console.log(pentagons.every(isPentagon)); // true ``` -------------------------------- ### h3.getRes0Cells Source: https://github.com/uber/h3-js/blob/master/README.md Retrieves all H3 indices at resolution 0. ```APIDOC ## GET /h3/res0/cells ### Description Retrieves all H3 indices at resolution 0. These can be used as base cells for iterating over H3 indexes at any resolution using h3ToChildren. ### Method GET ### Endpoint /h3/res0/cells ### Response #### Success Response (200) - **h3Indexes** (Array) - An array of H3 indices at resolution 0. #### Response Example ```json { "h3Indexes": [ "8001fffffffffff", "8002fffffffffff" ] } ``` ``` -------------------------------- ### Get Average Hexagon Edge Length with h3-js Source: https://context7.com/uber/h3-js/llms.txt Computes the average edge length of a hexagon at a given H3 resolution. This metric is useful for understanding the scale of cells at different resolutions. ```javascript import { getHexagonEdgeLengthAvg, UNITS } from 'h3-js'; for (let res = 0; res <= 15; res++) { const lengthKm = getHexagonEdgeLengthAvg(res, UNITS.km); console.log(`Res ${res}: ${lengthKm.toFixed(4)} km`); } ``` -------------------------------- ### Local IJ Coordinates Source: https://context7.com/uber/h3-js/llms.txt Functions for converting between H3 indexes and local IJ coordinate space. ```APIDOC ## Local IJ Coordinate Conversion ### Description Convert between H3 indexes and local IJ coordinate space anchored to an origin cell. This is useful for grid-based operations within a local neighborhood. ### Method GET ### Endpoint /h3/localij ### Parameters #### Query Parameters - **originH3Index** (string) - Required - The H3 index of the origin cell. - **targetH3Index** (string) - Optional - The H3 index of the target cell to convert to local IJ coordinates. If not provided, the endpoint returns information for converting local IJ coordinates back to an H3 index. - **localIJCoords** (object) - Optional - An object containing `i` and `j` properties, representing local IJ coordinates. Used when converting from local IJ to H3 index. - **i** (integer) - The i-coordinate. - **j** (integer) - The j-coordinate. ### Response #### Success Response (200) - **localIJCoords** (object) - An object containing `i` and `j` properties, representing the local IJ coordinates relative to the origin (if `targetH3Index` was provided). - **h3Index** (string) - The H3 index corresponding to the provided local IJ coordinates and origin (if `localIJCoords` was provided). ### Request Example (H3 to Local IJ) `GET /h3/localij?originH3Index=8828308281fffff&targetH3Index=882830828dfffff` ### Response Example (H3 to Local IJ) ```json { "localIJCoords": { "i": 393, "j": 337 } } ``` ### Request Example (Local IJ to H3) `POST /h3/localij` with body: ```json { "originH3Index": "8828308281fffff", "localIJCoords": { "i": 393, "j": 337 } } ``` ### Response Example (Local IJ to H3) ```json { "h3Index": "882830828dfffff" } ``` ``` -------------------------------- ### Get Average Hexagon Area with h3-js Source: https://context7.com/uber/h3-js/llms.txt Calculates the average area of a hexagon at a specified H3 resolution. The area decreases significantly as the resolution increases, useful for understanding spatial density. ```javascript import { getHexagonAreaAvg, UNITS } from 'h3-js'; // Average area decreases with higher resolution for (let res = 0; res <= 15; res++) { const areaKm2 = getHexagonAreaAvg(res, UNITS.km2); console.log(`Res ${res}: ${areaKm2.toExponential(2)} km²`); } // Res 0: 4.25e+06 km² // Res 5: 2.53e+02 km² // Res 10: 1.55e-02 km² // Res 15: 9.00e-07 km² ``` -------------------------------- ### h3.directedEdgeToCells Source: https://github.com/uber/h3-js/blob/master/README.md Retrieves the origin and destination hexagon indexes from a unidirectional H3 edge index. ```APIDOC ## GET /h3/directedEdgeToCells ### Description Get the [origin, destination] pair represented by a unidirectional edge. ### Method GET ### Endpoint /h3/directedEdgeToCells ### Parameters #### Path Parameters None #### Query Parameters - **edgeIndex** (H3IndexInput) - Required - H3 index of the edge ### Request Example ``` /h3/directedEdgeToCells?edgeIndex=627613346143414271 ``` ### Response #### Success Response (200) - **cells** (Array<H3Index>) - [origin, destination] pair as H3 indexes #### Response Example ```json { "cells": [ "8928308280fffff", "8928308280dffff" ] } ``` #### Error Response (400) - **error** (H3Error) - If the input is invalid ``` -------------------------------- ### Get Directed Edge Boundary with h3-js Source: https://context7.com/uber/h3-js/llms.txt Retrieves the geographic coordinates (latitude and longitude) that define the boundary of a directed H3 edge. The output can be formatted as an array of [lat, lng] pairs or in GeoJSON format. ```javascript import { originToDirectedEdges, directedEdgeToBoundary } from 'h3-js'; const h3Index = '85283473fffffff'; const edges = originToDirectedEdges(h3Index); const edgeBoundary = directedEdgeToBoundary(edges[0]); console.log(edgeBoundary); // Output: [[lat1, lng1], [lat2, lng2]] - the two vertices of the edge // GeoJSON format const geoJsonBoundary = directedEdgeToBoundary(edges[0], true); // Output: [[lng1, lat1], [lng2, lat2]] ``` -------------------------------- ### Get Hexagons Grouped by Distance (JavaScript) Source: https://context7.com/uber/h3-js/llms.txt Returns hexagons within k rings of an origin, grouped by their distance from the origin. The output is an array of arrays, where each inner array contains hexagons at a specific distance. ```javascript import { gridDiskDistances } from 'h3-js'; const origin = '8928308280fffff'; const rings = gridDiskDistances(origin, 2); console.log(rings[0].length); // 1 (origin) console.log(rings[1].length); // 6 (immediate neighbors) console.log(rings[2].length); // 12 (second ring) // Access specific ring const immediateNeighbors = rings[1]; console.log(immediateNeighbors); ``` -------------------------------- ### Get Hexagons within K Rings (JavaScript) Source: https://context7.com/uber/h3-js/llms.txt Returns all H3 hexagons within a specified number of rings (k) from an origin hexagon, including the origin itself. The order of hexagons in the returned array is not guaranteed. ```javascript import { gridDisk } from 'h3-js'; const origin = '8928308280fffff'; // Get all cells within 1 step (origin + 6 neighbors) const neighbors = gridDisk(origin, 1); console.log(neighbors.length); // 7 // Get all cells within 2 steps const twoRings = gridDisk(origin, 2); console.log(twoRings.length); // 19 (1 + 6 + 12) // Ring size 0 returns just the origin const self = gridDisk(origin, 0); console.log(self); // ['8928308280fffff'] ``` -------------------------------- ### h3.uncompactCells Source: https://github.com/uber/h3-js/blob/master/README.md Uncompact a compacted set of hexagons to hexagons of the same resolution. ```APIDOC ## POST /h3/uncompactCells ### Description Uncompact a compacted set of hexagons to hexagons of the same resolution. ### Method POST ### Endpoint /h3/uncompactCells ### Parameters #### Request Body - **compactedSet** (Array) - Required - H3 indexes to uncompact - **res** (number) - Required - The resolution to uncompact to ### Response #### Success Response (200) - **Array** - The uncompacted H3 indexes #### Error Response - **H3Error** - If the input is invalid (e.g. invalid resolution) ``` -------------------------------- ### Get Base Cell Number for H3 Index Source: https://context7.com/uber/h3-js/llms.txt Retrieves the base cell number (an integer between 0 and 121) for a given H3 index. This function is useful for understanding the global grid structure associated with an H3 index. ```javascript import { getBaseCellNumber } from 'h3-js'; const h3Index = '8928308280fffff'; console.log(getBaseCellNumber(h3Index)); // 20 ``` -------------------------------- ### Get Directed Edges from Origin Cell with h3-js Source: https://context7.com/uber/h3-js/llms.txt Returns all directed edges originating from a specified H3 cell index and pointing to its neighbors. The number of edges returned is 6 for hexagonal cells and 5 for pentagonal cells. ```javascript import { originToDirectedEdges, isValidDirectedEdge } from 'h3-js'; const h3Index = '8928308280fffff'; const edges = originToDirectedEdges(h3Index); console.log(edges.length); // 6 for hexagon, 5 for pentagon console.log(edges.every(isValidDirectedEdge)); // true ```