### Install Dependencies and Start Local Server Source: https://github.com/uber/h3/blob/master/website/README.md Run these commands in the \'website\' directory to install dependencies and start the local development server for viewing the H3 documentation. ```bash yarn yarn start ``` -------------------------------- ### Compile and Run C Example for H3 Source: https://github.com/uber/h3/blob/master/README.md Example of compiling and running a C program that utilizes the H3 library. Assumes the H3 library is installed. ```bash cc -lh3 examples/index.c -o example ./example ``` -------------------------------- ### Live JavaScript example of polygonToCells Source: https://github.com/uber/h3/blob/master/website/docs/api/regions.mdx This live example demonstrates how to use `h3.polygonToCells` with a sample polygon and resolution to get covering H3 indexes. ```javascript function example() { const polygon = [ [37.813318999983238, -122.4089866999972145], [37.7198061999978478, -122.3544736999993603], [37.8151571999998453, -122.4798767000009008] ]; const res = 7; return h3.polygonToCells(polygon, res); } ``` -------------------------------- ### JavaScript Live Example: Get Resolution Source: https://github.com/uber/h3/blob/master/website/docs/api/inspection.mdx Demonstrates how to get the resolution of an H3 index using the JavaScript API. ```javascript function example() { const h = '85283473fffffff'; return h3.getResolution(h); } ``` -------------------------------- ### Build Example Executables Source: https://github.com/uber/h3/blob/master/examples/CMakeLists.txt Iterates through the defined examples, creating an executable for each and linking it to the H3 library. ```cmake foreach(name ${EXAMPLES}) add_executable(${name} "${name}.c") target_link_libraries(${name} PRIVATE h3::h3) endforeach() ``` -------------------------------- ### Get Average Hexagon Area (m^2) - Shell Example Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Example of using the shell command to get the average hexagon area for resolution 5 in square meters. ```bash $ h3 getHexagonAreaAvgM2 -r 5 252903858.1819452047 ``` -------------------------------- ### JavaScript Live Example: Get Index Digit Source: https://github.com/uber/h3/blob/master/website/docs/api/inspection.mdx Demonstrates how to get an indexing digit of an H3 index at a specified resolution using the JavaScript API. ```javascript function example() { const h = '85283473fffffff'; const res = 2; return h3.getIndexDigit(h, res); } ``` -------------------------------- ### Install H3 JavaScript with npm Source: https://github.com/uber/h3/blob/master/website/docs/installation.mdx Use npm to install the H3 JavaScript library. ```bash npm install h3-js ``` -------------------------------- ### Build and Install H3 from Source Source: https://context7.com/uber/h3/llms.txt Build H3 from source using CMake on Linux or macOS, followed by installation. ```bash # Build from source (Linux/macOS) git clone https://github.com/uber/h3.git && cd h3 git checkout v4.4.1 mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release .. make sudo make install ``` -------------------------------- ### Install H3 with Pip Source: https://github.com/uber/h3/blob/master/website/docs/installation.mdx Use this command to install the H3 Python library via PyPi. ```bash pip install h3 ``` -------------------------------- ### Configure Testing for Examples Source: https://github.com/uber/h3/blob/master/examples/CMakeLists.txt Includes CTest and TestWrapValgrind.cmake, enables testing, and adds each example executable as a test case, wrapping it with Valgrind if available. ```cmake include(CTest) if(BUILD_TESTING) include(../cmake/TestWrapValgrind.cmake) enable_testing() foreach(name ${EXAMPLES}) add_test(NAME ${name} COMMAND ${TEST_WRAPPER} "$<$$>") endforeach() endif() ``` -------------------------------- ### Get Exact Cell Area (radians^2) - Shell Example Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Example of using the shell command to get the exact area of a specific H3 cell in square radians. ```bash $ h3 cellAreaRads2 -c 85283473fffffff 0.0000065310 ``` -------------------------------- ### JavaScript: Live Example of gridDiskDistances Source: https://github.com/uber/h3/blob/master/website/docs/api/traversal.mdx An interactive JavaScript example demonstrating the usage of gridDiskDistances with a specific H3 index and distance. ```javascript function example() { const h = '85283473fffffff'; const k = 5; return h3.gridDiskDistances(h, k); } ``` -------------------------------- ### C Example Output for H3 Functions Source: https://github.com/uber/h3/blob/master/README.md Sample output from the C example program, demonstrating H3 index, boundary vertices, and center coordinates. ```text The index is: 8a2a1072b59ffff Boundary vertex #0: 40.690059, -74.044152 Boundary vertex #1: 40.689908, -74.045062 Boundary vertex #2: 40.689271, -74.045341 Boundary vertex #3: 40.688785, -74.044711 Boundary vertex #4: 40.688936, -74.043801 Boundary vertex #5: 40.689573, -74.043521 Center coordinates: 40.689422, -74.044431 ``` -------------------------------- ### JavaScript live example for getDirectedEdgeDestination Source: https://github.com/uber/h3/blob/master/website/docs/api/directededge.mdx This live example demonstrates how to use the getDirectedEdgeDestination function in JavaScript. ```javascript function example() { const edge = '115283473fffffff'; return h3.getDirectedEdgeDestination(edge); } ``` -------------------------------- ### JavaScript: Live gridDisk Example Source: https://github.com/uber/h3/blob/master/website/docs/api/traversal.mdx An interactive example demonstrating the `gridDisk` function in JavaScript. It takes an H3 index and a distance `k` to return cells within that disk. ```javascript function example() { const h = '85283473fffffff'; const k = 5; return h3.gridDisk(h, k); } ``` -------------------------------- ### Install H3 Extension for DuckDB Source: https://github.com/uber/h3/blob/master/website/docs/installation.mdx Install the H3 extension for DuckDB from the community extensions. ```sql INSTALL h3 FROM community; LOAD h3; ``` -------------------------------- ### Install AFL for Fuzzing Source: https://github.com/uber/h3/blob/master/src/apps/fuzzers/README.md Install the AFL fuzzer toolchain, specifically afl-clang, which is used for instrumenting the build. ```bash apt install afl-clang ``` -------------------------------- ### Install H3 on macOS using Homebrew Source: https://github.com/uber/h3/blob/master/README.md Use this command to install the H3 library on macOS if you have Homebrew installed. ```bash brew install h3 ``` -------------------------------- ### Get Pentagon Cells (Shell) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Command-line interface for retrieving pentagon H3 indexes at a specified resolution. Shows help information and an example output. ```sh $ h3 getPentagons --help h3: Returns all of the pentagons at the specified resolution H3 4.1.0 getPentagons Returns all of the pentagons at the specified resolution -r, --resolution Required. Resolution, 0-15 inclusive. -h, --help Show this help message. -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash $ h3 getPentagons -r 5 [ "85080003fffffff", "851c0003fffffff", "85300003fffffff", "854c0003fffffff", "85620003fffffff", "85740003fffffff", "857e0003fffffff", "85900003fffffff", "85a60003fffffff", "85c20003fffffff", "85d60003fffffff", "85ea0003fffffff" ] ``` -------------------------------- ### Shell: gridPathCells (Example) Source: https://github.com/uber/h3/blob/master/website/docs/api/traversal.mdx Example usage of the h3 gridPathCells command to find a path between two H3 cells. ```bash $ h3 gridPathCells -o 85283473fffffff -d 8528342bfffffff [ "85283473fffffff", "85283477fffffff", "8528342bfffffff" ] ``` -------------------------------- ### Shell: gridDisk Example Usage Source: https://github.com/uber/h3/blob/master/website/docs/api/traversal.mdx Example of using the `h3 gridDisk` command-line tool to find cells within a distance of 5 from a given H3 index. ```bash $ h3 gridDisk -k 5 -c 85283473fffffff [ "85283473fffffff", "85283447fffffff", "8528347bfffffff", "85283463fffffff", "85283477fffffff", "8528340ffffffff", "8528340bfffffff", "85283457fffffff", "85283443fffffff", "8528344ffffffff", "852836b7fffffff", "8528346bfffffff", "8528346ffffffff", "85283467fffffff", "8528342bfffffff", "8528343bfffffff", "85283407fffffff", "85283403fffffff", "8528341bfffffff", "852834cffffffff", "85283453fffffff", "8528345bfffffff", "8528344bfffffff", "852836b3fffffff", "852836a3fffffff", "852836a7fffffff", "852830d3fffffff", "852830d7fffffff", "8528309bfffffff", "85283093fffffff", "8528342ffffffff", "85283423fffffff", "85283433fffffff", "852834abfffffff", "85283417fffffff", "85283413fffffff", "852834c7fffffff", "852834c3fffffff", "852834cbfffffff", "8529a927fffffff", "8529a92ffffffff", "85283697fffffff", "85283687fffffff", "852836bbfffffff", "852836abfffffff", "852836affffffff", "852830dbfffffff", "852830c3fffffff", "852830c7fffffff", "8528308bfffffff", "85283083fffffff", "85283097fffffff", "8528355bfffffff", "85283427fffffff", "85283437fffffff", "852834affffffff", "852834a3fffffff", "852834bbfffffff", "8528348ffffffff", "8528348bfffffff", "852834d7fffffff", "852834d3fffffff", "852834dbfffffff", "8529a937fffffff", "8529a923fffffff", "8529a92bfffffff", "85283693fffffff", "85283683fffffff", "8528368ffffffff", "85283617fffffff", "85283607fffffff", "85283633fffffff", "85283637fffffff", "852830cbfffffff", "852830cffffffff", "8528301bfffffff", "85283013fffffff", "8528308ffffffff", "85283087fffffff", "8528354bfffffff", "85283543fffffff", "85283553fffffff", "852835cbfffffff", "852835dbfffffff", "852834a7fffffff", "852834b7fffffff", "852834b3fffffff", "85283487fffffff", "85283483fffffff", "8528349bfffffff", "85291a6ffffffff" ] ``` -------------------------------- ### Get Pentagon Count (Shell) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Command-line interface to retrieve the number of pentagons. Shows help information and an example of its output. ```sh $ h3 pentagonCount --help h3: Returns 12 H3 4.1.0 pentagonCount Returns 12 -h, --help Show this help message. ``` ```bash $ h3 pentagonCount 12 ``` -------------------------------- ### Get Pentagon Cells (JavaScript) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Retrieves pentagon H3 indexes for a given resolution. Includes a live example demonstrating its usage. ```javascript h3.getPentagons(res) ``` ```javascript function example() { const res = 5; return h3.getPentagons(res); } ``` -------------------------------- ### JavaScript live example for getDirectedEdgeOrigin Source: https://github.com/uber/h3/blob/master/website/docs/api/directededge.mdx This live example demonstrates how to use the getDirectedEdgeOrigin function in JavaScript. ```javascript function example() { const edge = '115283473fffffff'; return h3.getDirectedEdgeOrigin(edge); } ``` -------------------------------- ### Install H3 with Conda Source: https://github.com/uber/h3/blob/master/website/docs/installation.mdx Add the conda-forge channel and install the H3 Python library using Conda. ```bash conda config --add channels conda-forge conda install h3-py ``` -------------------------------- ### JavaScript Live Example: polygonToCellsExperimental Source: https://github.com/uber/h3/blob/master/website/docs/api/regions.mdx This live example demonstrates how to use polygonToCellsExperimental in JavaScript with a sample polygon, resolution 7, and the 'containmentOverlapping' flag. ```javascript function example() { const polygon = [ [37.813318999983238, -122.4089866999972145], [37.7198061999978478, -122.3544736999993603], [37.8151571999998453, -122.4798767000009008] ]; const res = 7; return h3.polygonToCellsExperimental(polygon, res, h3.POLYGON_TO_CELLS_FLAGS.containmentOverlapping); } ``` -------------------------------- ### Install H3 Build Requirements on FreeBSD Source: https://github.com/uber/h3/blob/master/README.md Installs the necessary build tools for H3 on FreeBSD. Includes Bash, CMake, Gmake, Doxygen, and LCOV. ```bash # Installing the build requirements sudo pkg install bash cmake gmake doxygen lcov ``` -------------------------------- ### Find H3 Library and Define Examples Source: https://github.com/uber/h3/blob/master/examples/CMakeLists.txt Locates the H3 library using find_package and defines a list of example source files to be built. ```cmake find_package(h3 CONFIG REQUIRED) set(EXAMPLES index distance neighbors compactCells edge ) ``` -------------------------------- ### Install H3 Build Dependencies on Debian/Ubuntu Source: https://github.com/uber/h3/blob/master/README.md Installs the necessary build tools for H3 on Debian/Ubuntu systems. Includes CMake, Make, GCC, and Libtool. Also installs optional development tools like clang-format, ccmake, and lcov. ```bash # Installing the bare build requirements sudo apt install cmake make gcc libtool # Installing useful tools for development sudo apt install clang-format cmake-curses-gui lcov doxygen ``` -------------------------------- ### Get Child Cells (Shell) Source: https://github.com/uber/h3/blob/master/website/docs/api/hierarchy.mdx Command-line usage for `h3 cellToChildren` to find the children H3 cells. The example shows how to specify the cell and target resolution. ```sh $ h3 cellToChildren --help h3: Returns an array of H3 indexes that are the children (or lower) of the provided cell H3 4.1.0 cellToChildren Returns an array of H3 indexes that are the children (or lower) of the provided cell -h, --help Show this help message. -c, --cell Required. H3 Cell -r, --resolution Required. Resolution, 1-15 inclusive, excluding 0 as it can never be a child -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash $ h3 cellToChildren -c 85283473fffffff -r 6 [ "862834707ffffff", "86283470fffffff", "862834717ffffff", "86283471fffffff", "862834727ffffff", "86283472fffffff", "862834737ffffff" ] ``` -------------------------------- ### Shell: gridDiskDistances Command Example Source: https://github.com/uber/h3/blob/master/website/docs/api/traversal.mdx Example usage of the 'h3 gridDiskDistances' command-line tool to find cells within a distance of 5 from a given H3 index. ```bash $ h3 gridDiskDistances -k 5 -c 85283473fffffff [["85283473fffffff"], ["85283447fffffff", "8528347bfffffff", "85283463fffffff", "85283477fffffff", "8528340ffffffff", "8528340bfffffff"], ["85283457fffffff", "85283443fffffff", "8528344ffffffff", "852836b7fffffff", "8528346bfffffff", "8528346ffffffff", "85283467fffffff", "8528342bfffffff", "8528343bfffffff", "85283407fffffff", "85283403fffffff", "8528341bfffffff"], ["852834cffffffff", "85283453fffffff", "8528345bfffffff", "8528344bfffffff", "852836b3fffffff", "852836a3fffffff", "852836a7fffffff", "852830d3fffffff", "852830d7fffffff", "8528309bfffffff", "85283093fffffff", "8528342ffffffff", "85283423fffffff", "85283433fffffff", "852834abfffffff", "85283417fffffff", "85283413fffffff", "852834c7fffffff"], ["852834c3fffffff", "852834cbfffffff", "8529a927fffffff", "8529a92ffffffff", "85283697fffffff", "85283687fffffff", "852836bbfffffff", "852836abfffffff", "852836affffffff", "852830dbfffffff", "852830c3fffffff", "852830c7fffffff", "8528308bfffffff", "85283083fffffff", "85283097fffffff", "8528355bfffffff", "85283427fffffff", "85283437fffffff", "852834affffffff", "852834a3fffffff", "852834bbfffffff", "8528348ffffffff", "8528348bfffffff", "852834d7fffffff"], ["852834d3fffffff", "852834dbfffffff", "8529a937fffffff", "8529a923fffffff", "8529a92bfffffff", "85283693fffffff", "85283683fffffff", "8528368ffffffff", "85283617fffffff", "85283607fffffff", "85283633fffffff", "85283637fffffff", "852830cbfffffff", "852830cffffffff", "8528301bfffffff", "85283013fffffff", "8528308ffffffff", "85283087fffffff", "8528354bfffffff", "85283543fffffff", "85283553fffffff", "852835cbfffffff", "852835dbfffffff", "852834a7fffffff", "852834b7fffffff", "852834b3fffffff", "85283487fffffff", "85283483fffffff", "8528349bfffffff", "85291a6ffffffff"]] ``` -------------------------------- ### JavaScript live example for isValidDirectedEdge Source: https://github.com/uber/h3/blob/master/website/docs/api/directededge.mdx This live example demonstrates how to use the isValidDirectedEdge function in JavaScript. ```javascript function example() { const edge = '115283473fffffff'; return h3.isValidDirectedEdge(edge); } ``` -------------------------------- ### Get Exact Cell Area (km^2) - Shell Example Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Example of using the shell command to get the exact area of a specific H3 cell in square kilometers. ```bash $ h3 cellAreaKm2 -c 85283473fffffff 265.0925581283 ``` -------------------------------- ### Build Production Version of Website Source: https://github.com/uber/h3/blob/master/website/README.md Execute this command in the \'website\' directory to create a production-ready build of the H3 documentation website. ```bash yarn build ``` -------------------------------- ### #define Approach: Build-time Allocator Configuration Source: https://github.com/uber/h3/blob/master/dev-docs/RFCs/v4.0.0/overrideable-allocators-rfc.md This approach configures custom allocators at build time using preprocessor directives. It offers minimal overhead for users not needing allocator replacement. ```bash # In build process: cmake -DH3_ALLOC_PREFIX=my_ ... ``` -------------------------------- ### Get Resolution 0 Cells (JavaScript) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Invoke `h3.getRes0Cells()` to get all resolution 0 H3 cells. The live example demonstrates its usage. ```js h3.getRes0Cells() ``` ```js function example() { return h3.getRes0Cells(); } ``` -------------------------------- ### Get Child Cells (JavaScript) Source: https://github.com/uber/h3/blob/master/website/docs/api/hierarchy.mdx JavaScript function to get the children H3 cells at a specified resolution. The live example demonstrates its usage. ```javascript h3.cellToChildren(cell, childRes) ``` ```javascript function example() { const cell = '85283473fffffff'; return h3.cellToChildren(cell, 6); } ``` -------------------------------- ### Build H3 with Release Type for Benchmarks Source: https://github.com/uber/h3/blob/master/README.md Build the project for performance testing. Use the Release build type and run the benchmarks target. ```bash mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release .. make make benchmarks ``` -------------------------------- ### Get Parent Cell (JavaScript) Source: https://github.com/uber/h3/blob/master/website/docs/api/hierarchy.mdx JavaScript function to get the parent H3 cell at a specified resolution. The live example demonstrates its usage. ```javascript h3.cellToParent(cell, parentRes) ``` ```javascript function example() { const cell = '85283473fffffff'; return h3.cellToParent(cell, 4); } ``` -------------------------------- ### Install H3 Build Dependencies on Alpine Source: https://github.com/uber/h3/blob/master/README.md Installs the necessary build tools for H3 on Alpine Linux. Includes CMake, Make, GCC, Libtool, and Musl development headers. ```bash # Installing the bare build requirements apk add cmake make gcc libtool musl-dev ``` -------------------------------- ### Convert Cells to Multi Polygon (Shell Example) Source: https://github.com/uber/h3/blob/master/website/docs/api/regions.mdx Example of using the H3 CLI `cellsToMultiPolygon` command to convert a set of H3 cell indices to a GeoJSON-like multi-polygon output. ```bash $ h3 cellsToMultiPolygon -c 872830828ffffff,87283082effffff [[[[37.784046, -122.427089], [37.772267, -122.434586], [37.761736, -122.425769], [37.762982, -122.409455], [37.752446, -122.400640], [37.753689, -122.384324], [37.765468, -122.376819], [37.776004, -122.385635], [37.774761, -122.401954], [37.785293, -122.410771]]]] ``` -------------------------------- ### #define Approach: Individual Function Allocator Configuration Source: https://github.com/uber/h3/blob/master/dev-docs/RFCs/v4.0.0/overrideable-allocators-rfc.md An alternative to prefix-based configuration, this allows specifying individual allocator functions via build-time options. Care must be taken to avoid partial overrides. ```bash # in source file, functions are used as before. Alternately, instead of setting a prefix, the build could accept individual options for functions, such as -DH3_MALLOC=my_malloc -DH3_CALLOC=my_calloc. (Although this could allow a user to accidentally override `malloc` but not `free`, which is generally very bad.) ``` -------------------------------- ### H3 CLI cellToChildren Example Source: https://github.com/uber/h3/blob/master/tests/cli/cellToChildren.txt Demonstrates how to use the cellToChildren command with a specific H3 cell and resolution, and shows the expected output. ```bash add_h3_cli_test( testCliCellToChildren "cellToChildren -c 85283473fffffff -r 6" "[ \"862834707ffffff\", \"86283470fffffff\", \"862834717ffffff\", \"86283471fffffff\", \"862834727ffffff\", \"86283472fffffff\", \"862834737ffffff\" ]" ) ``` -------------------------------- ### JavaScript Live Example: Get Base Cell Number Source: https://github.com/uber/h3/blob/master/website/docs/api/inspection.mdx Demonstrates how to get the base cell number of an H3 index using the JavaScript API. ```javascript function example() { const h = '85283473fffffff'; return h3.getBaseCellNumber(h); } ``` -------------------------------- ### Get Number of Children for a Cell (Shell) Source: https://github.com/uber/h3/blob/master/website/docs/api/hierarchy.mdx Shell command to get the maximum number of children for a given cell at a specified resolution. Includes usage example. ```shell $ h3 cellToChildrenSize --help h3: Returns the maximum number of children for a given cell at the specified child resolution H3 4.1.0 cellToChildrenSize Returns the maximum number of children for a given cell at the specified child resolution -h, --help Show this help message. -c, --cell Required. H3 Cell -r, --resolution Required. Resolution, 1-15 inclusive, excluding 0 as it can never be a child ``` ```bash $ h3 cellToChildrenSize -c 85283473fffffff -r 6 7 ``` -------------------------------- ### Get Center Child Cell (JavaScript) Source: https://github.com/uber/h3/blob/master/website/docs/api/hierarchy.mdx JavaScript function to find the center child cell at a specified resolution. The live example demonstrates its usage. ```javascript h3.cellToCenterChild(cell, childRes) ``` ```javascript function example() { const cell = '85283473fffffff'; return h3.cellToCenterChild(cell, 7); } ``` -------------------------------- ### Get Number of Children for a Cell (JavaScript) Source: https://github.com/uber/h3/blob/master/website/docs/api/hierarchy.mdx JavaScript function to calculate the number of children for a cell at a specified resolution. The live example demonstrates its usage. ```javascript h3.cellToChildrenSize(cell, childRes) ``` ```javascript function example() { const cell = '85283473fffffff'; return h3.cellToChildrenSize(cell, 6); } ``` -------------------------------- ### H3 CLI childPosToCell Example Source: https://github.com/uber/h3/blob/master/tests/cli/childPosToCell.txt Demonstrates converting a child cell's position to its H3 index using the 'childPosToCell' command with specific parameters. ```bash add_h3_cli_test( testCliChildPosToCell "childPosToCell -c 85283473fffffff -r 7 -p 42 -f newline" "872834730ffffff") ``` -------------------------------- ### Get All Directed Edges from Origin Cell (Python) Source: https://github.com/uber/h3/blob/master/website/docs/api/directededge.mdx Call the origin_to_directed_edges function in Python to retrieve all directed edges that start from the given H3 index. ```python h3.origin_to_directed_edges(h) ``` -------------------------------- ### Live Example: Generate Grid Ring Source: https://github.com/uber/h3/blob/master/website/docs/api/traversal.mdx Demonstrates generating a hollow ring of H3 cells at a specific distance from an origin cell using the JavaScript API. ```javascript function example() { const h = '85283473fffffff'; const k = 1; return h3.gridRing(h, k); } ``` -------------------------------- ### Shell command example for polygonToCells Source: https://github.com/uber/h3/blob/master/website/docs/api/regions.mdx This example shows how to use the `h3 polygonToCells` command-line tool to convert a polygon defined by its coordinates into H3 cells at resolution 7, outputting the result as a JSON array. ```shell $ h3 polygonToCells -r 7 -p "[[37.813318999983238, -122.4089866999972145], [37.7198061999978478, -122.3544736999993603], [37.8151571999998453, -122.4798767000009008]]" [ "87283082bffffff", "872830870ffffff", "872830820ffffff", "87283082effffff", "872830828ffffff", "87283082affffff", "872830876ffffff" ] ``` -------------------------------- ### Get Parent Cell (Shell) Source: https://github.com/uber/h3/blob/master/website/docs/api/hierarchy.mdx Command-line usage for `h3 cellToParent` to find the parent H3 cell. The example shows how to specify the cell and target resolution. ```sh $ h3 cellToParent --help h3: Returns the H3 index that is the parent (or higher) of the provided cell H3 4.1.0 cellToParent Returns the H3 index that is the parent (or higher) of the provided cell -h, --help Show this help message. -c, --cell Required. H3 Cell -r, --resolution Required. Resolution, 0-14 inclusive, excluding 15 as it can never be a parent -f, --format 'json' for "CELL"\n, 'newline' for CELL\n (Default: json) ``` ```bash $ h3 cellToParent -c 85283473fffffff -r 4 "8428347ffffffff" ``` -------------------------------- ### Get All Directed Edges from Origin Cell (JavaScript) Source: https://github.com/uber/h3/blob/master/website/docs/api/directededge.mdx Use the originToDirectedEdges function in JavaScript to find all directed edges originating from a specified H3 index. An example demonstrates its usage. ```javascript h3.originToDirectedEdges(h3Index) ``` ```javascript function example() { const h = '85283473fffffff'; return h3.originToDirectedEdges(h); } ``` -------------------------------- ### Get Number of Cells at Resolution 0 Source: https://github.com/uber/h3/blob/master/tests/cli/getNumCells.txt Use the `getNumCells` command with a resolution argument to retrieve the total number of H3 cells at that resolution. This example queries for resolution 0. ```bash getNumCells -r 0 ``` -------------------------------- ### Shell: gridDisk Help Source: https://github.com/uber/h3/blob/master/website/docs/api/traversal.mdx Help output for the `h3 gridDisk` command-line utility, detailing its purpose and options. ```sh $ h3 gridDisk --help h3: Returns an array of a H3 cells within 'k' steps of the origin cell H3 4.1.0 gridDisk Returns an array of a H3 cells within 'k' steps of the origin cell -h, --help Show this help message. -c, --cell Required. H3 Cell -k Required. Maximum grid distance for the output set -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` -------------------------------- ### Get Center Child Cell (Shell) Source: https://github.com/uber/h3/blob/master/website/docs/api/hierarchy.mdx Shell command to find the centrally-placed child cell within a given cell at a specified resolution. Includes usage example and output format options. ```shell $ h3 cellToCenterChild --help h3: Returns the H3 index that is the centrally-placed child (or lower) of the provided cell H3 4.1.0 cellToCenterChild Returns the H3 index that is the centrally-placed child (or lower) of the provided cell -h, --help Show this help message. -c, --cell Required. H3 Cell -r, --resolution Required. Resolution, 1-15 inclusive, excluding 0 as it can never be a child -f, --format 'json' for "CELL"\n, 'newline' for CELL\n (Default: json) ``` ```bash $ h3 cellToCenterChild -c 85283473fffffff -r 7 "872834700ffffff" ``` -------------------------------- ### Go: gridDiskDistances Method Call Source: https://github.com/uber/h3/blob/master/website/docs/api/traversal.mdx Example of calling the gridDiskDistances method in Go. ```go cell.GridDiskDistances(k) ``` -------------------------------- ### Get Origin and Destination Cells from Directed Edge (JavaScript) Source: https://github.com/uber/h3/blob/master/website/docs/api/directededge.mdx Use the directedEdgeToCells function in JavaScript to find the origin and destination cells of a directed edge. An example demonstrates its usage with a sample edge. ```javascript h3.directedEdgeToCells(edge) ``` ```javascript function example() { const edge = '115283473fffffff'; return h3.directedEdgeToCells(edge); } ``` -------------------------------- ### Get H3 Index Digit Source: https://github.com/uber/h3/blob/master/website/docs/api/inspection.mdx Extract an indexing digit of an H3 index at a specified resolution. Works for cells, edges, and vertexes. Digits are 1-indexed starting with the resolution 1 digit. Unused digits will be represented as 7. ```c H3Error getIndexDigit(H3Index h, int res, H3Index *out); ``` ```java int getIndexDigit(long h3, int res); int getIndexDigit(String h3Address, int res); ``` ```javascript h3.getIndexDigit(h, res) ``` ```python h3.get_index_digit(h, res) ``` ```go cell.IndexDigit(res) ``` ```duckdb h3_get_index_digit(h, res) ``` ```shell $ h3 getIndexDigit --help h3: Extracts the indexing digit (0 - 7) from the H3 cell H3 4.3.0 getIndexDigit Extracts the indexing digit (0 - 7) from the H3 cell -h, --help Show this help message. -c, --cell Required. H3 Cell -r, --res Required. Indexing resolution (1 - 15) ``` ```bash $ h3 getIndexDigit -c 85283473fffffff -r 2 7 ``` -------------------------------- ### Build H3 as a Shared Library on Windows Source: https://github.com/uber/h3/blob/master/dev-docs/build_windows.md Configure and build H3 as a shared library (DLL) on Windows. Testing is not supported in this configuration. Ensure BUILD_TESTING is set to OFF. ```bash cmake .. -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=ON msbuild ALL_BUILD.vcxproj ``` -------------------------------- ### Shell: gridPathCells (Help) Source: https://github.com/uber/h3/blob/master/website/docs/api/traversal.mdx Displays help information for the h3 gridPathCells command. ```sh $ h3 gridPathCells --help h3: Returns an array of H3 cells from the origin cell to the destination cell (inclusive) H3 4.1.0 gridPathCells Returns an array of H3 cells from the origin cell to the destination cell (inclusive) -h, --help Show this help message. -o, --origin Required. The origin H3 cell -d, --destination Required. The destination H3 cell -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` -------------------------------- ### Get Edge Length in Radians (Go) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Call this function to get the edge length in radians. ```go h3.EdgeLengthRads(edge) ``` -------------------------------- ### Get Edge Length in Meters (Go) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Call this function to get the edge length in meters. ```go h3.EdgeLengthM(edge) ``` -------------------------------- ### Get Edge Length in Kilometers (Go) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Call this function to get the edge length in kilometers. ```go h3.EdgeLengthKm(edge) ``` -------------------------------- ### Compact H3 Cells (Shell - Help) Source: https://github.com/uber/h3/blob/master/website/docs/api/hierarchy.mdx Displays help information for the h3 compactCells command. Shows available options for compacting cells from stdin or a file. ```shell $ h3 compactCells --help ``` -------------------------------- ### Build H3 Library Source: https://github.com/uber/h3/blob/master/website/docs/installation.mdx Configure and build the H3 library from source using CMake. ```bash mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release .. cmake --build . ``` -------------------------------- ### Get Resolution 0 Cells (Go) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Use `h3.Res0Cells()` to get all resolution 0 H3 cells. ```go h3.Res0Cells() ``` -------------------------------- ### Run H3 Fuzzer with AFL Source: https://github.com/uber/h3/blob/master/src/apps/fuzzers/README.md Start the AFL fuzzer. The testcase directory must contain a file with sufficient bytes, and @@ is used to specify the input file for the fuzzer. ```bash afl-fuzz -i testcase_dir -o findings_dir -- fuzzerLatLngToCell @@ ``` -------------------------------- ### Templates Approach: Macro-based Allocator Replacement Source: https://github.com/uber/h3/blob/master/dev-docs/RFCs/v4.0.0/overrideable-allocators-rfc.md This approach uses macros to simulate C++ templates, allowing users to define functions with specific allocators. It enables multiple allocator replacements but complicates the build process. ```c POLYFILL_WITH_ALLLOCATORS(my_polyfill, my_malloc, my_calloc, my_free); // Call the function created by the template my_polyfill(geoPolygon, res, out); ``` -------------------------------- ### Install H3 JavaScript with yarn Source: https://github.com/uber/h3/blob/master/website/docs/installation.mdx Use yarn to add the H3 JavaScript library to your project. ```bash yarn add h3-js ``` -------------------------------- ### Run H3 Test Suite Source: https://github.com/uber/h3/blob/master/website/docs/installation.mdx Execute the H3 test suite after building the library. ```bash ctest ``` -------------------------------- ### Convert Cells to Multi Polygon (Shell Help) Source: https://github.com/uber/h3/blob/master/website/docs/api/regions.mdx Displays help information for the `cellsToMultiPolygon` command in the H3 CLI, detailing its usage and options. ```shell $ h3 cellsToMultiPolygon --help h3: Returns a polygon (array of arrays of lat, lng points) for a set of cells H3 4.1.0 cellsToMultiPolygon Returns a polygon (array of arrays of lat, lng points) for a set of cells -h, --help Show this help message. -i, --file The file to load the cells from. Use -- to read from stdin. -c, --cells The cells to convert. Up to 100 cells if provided as hexadecimals with zero padding. -f, --format 'json' for [[[[lat, lng],...],...],...] 'wkt' for a WKT MULTIPOLYGON ``` -------------------------------- ### Get Edge Length in Radians (DuckDB) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Use the h3_edge_length function with the unit specified as 'rads' to get the edge length in radians. ```sql h3_edge_length(h, 'rads') ``` -------------------------------- ### Shell: gridDiskDistances Command Help Source: https://github.com/uber/h3/blob/master/website/docs/api/traversal.mdx Help output for the 'h3 gridDiskDistances' command-line tool, detailing its options and functionality. ```shell $ h3 gridDiskDistances --help h3: Returns an array of arrays of H3 cells, each array containing cells 'k' steps away from the origin cell, based on the outer array index H3 4.1.0 diskDiskDistances Returns an array of arrays of H3 cells, each array containing cells 'k' steps away from the origin cell, based on the outer array index -h, --help Show this help message. -c, --cell Required. H3 Cell -k Required. Maximum grid distance for the output set -f, --format 'json' for [["CELL", ...], ...], 'newline' for CELL\n with an extra newline between rings (Default: json) ``` -------------------------------- ### Get Edge Length in Meters (DuckDB) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Use the h3_edge_length function with the unit specified as 'm' to get the edge length in meters. ```sql h3_edge_length(h, 'm') ``` -------------------------------- ### Live Example: Calculate Grid Distance Source: https://github.com/uber/h3/blob/master/website/docs/api/traversal.mdx Demonstrates calculating the grid distance between two H3 cells using the JavaScript API. ```javascript function example() { const start = '85283473fffffff'; const end = '8528342bfffffff'; return h3.gridDistance(start, end); } ``` -------------------------------- ### Get Edge Length in Kilometers (DuckDB) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Use the h3_edge_length function with the unit specified as 'km' to get the edge length in kilometers. ```sql h3_edge_length(h, 'km') ``` -------------------------------- ### Get average hexagon area (Java) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Gets the average hexagon area in the specified unit at the given resolution, excluding pentagons. ```java double getHexagonAreaAvg(int res, AreaUnit unit); ``` -------------------------------- ### Test maxPolygonToCellsSize with File Input Source: https://github.com/uber/h3/blob/master/tests/cli/maxPolygonToCellsSize.txt Execute the maxPolygonToCellsSize command using a specified input file. This is useful for testing with predefined polygon data. ```bash add_h3_cli_test( testCliMaxPolygonToCellsSizeFile1 "maxPolygonToCellsSize -r 7 -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test1.txt" "100") ``` ```bash add_h3_cli_test( testCliMaxPolygonToCellsSizeFile2 "maxPolygonToCellsSize -r 7 -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test2.txt" "23") ``` ```bash add_h3_cli_test( testCliMaxPolygonToCellsSizeFile3 "maxPolygonToCellsSize -r 4 -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test3.txt" "3484") ``` -------------------------------- ### Get Number of Children for a Cell (Java) Source: https://github.com/uber/h3/blob/master/website/docs/api/hierarchy.mdx Java overloads for `cellToChildrenSize` to get the number of children for a given cell at a specified resolution. ```java long cellToChildrenSize(long cell, int childRes); long cellToChildrenSize(String cellAddress, int childRes); ``` -------------------------------- ### Set C Standard and Project Name Source: https://github.com/uber/h3/blob/master/examples/CMakeLists.txt Configures the minimum CMake version, sets the C standard to 11, and defines the project name. ```cmake cmake_minimum_required(VERSION 3.5..4.0) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD 11) project(h3examples) ``` -------------------------------- ### Get Cell Center Point Source: https://github.com/uber/h3/blob/master/website/docs/core-library/filters.md Use the `cellToLatLng` filter to get the center point coordinates (latitude and longitude) for a given H3 index. ```bash cellToLatLng --index 845ad1bffffffff ``` -------------------------------- ### Compact Cells from Command Argument Source: https://github.com/uber/h3/blob/master/tests/cli/compactCells.txt Tests compactCells by passing input directly as a command argument using command substitution. Output is formatted with newlines and then converted to comma-separated values. ```bash add_h3_cli_test( testCliCompactCellsArg1 "compactCells -c \\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt\\` -f newline | tr -s '\\r\\n' ',' | tr -s '\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff," ) ``` ```bash add_h3_cli_test( testCliCompactCellsArg2 "compactCells -c \\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt\\` -f newline | tr -s '\\r\\n' ',' | tr -s '\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff," ) ``` ```bash add_h3_cli_test( testCliCompactCellsArg3 "compactCells -c \\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt\\` -f newline | tr -s '\\r\\n' ',' | tr -s '\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff," ) ``` -------------------------------- ### H3 CLI originToDirectedEdges - Successful Execution Source: https://github.com/uber/h3/blob/master/tests/cli/originToDirectedEdges.txt Demonstrates the successful execution of the originToDirectedEdges command with a valid H3 cell and resolution. The output shows the expected list of directed edges. ```bash add_h3_cli_test( testCliOriginToDirectedEdges "originToDirectedEdges -c 85283473fffffff" "[\"115283473fffffff\", \"125283473fffffff\", \"135283473fffffff\", \"145283473fffffff\", \"155283473fffffff\", \"165283473fffffff\"]" ) ``` -------------------------------- ### Global Statics Approach: Setting Allocators Source: https://github.com/uber/h3/blob/master/dev-docs/RFCs/v4.0.0/overrideable-allocators-rfc.md This approach involves calling a function to set the global allocator functions for the H3 library. It allows runtime replacement but is not thread-safe without additional complexity. ```c h3SetAllocator(&my_alloc, &my_calloc, &my_free); // call into H3 as before polyfill(geoPolygon, res, out); ``` -------------------------------- ### Core Types and Error Handling Example Source: https://context7.com/uber/h3/llms.txt Demonstrates the usage of core H3 types such as H3Index, LatLng, and H3Error. It shows how to convert coordinates to an H3 cell index, convert the index to a string representation, and validate cell indices. Error handling by checking the return code of H3 functions and using describeH3Error is also illustrated. ```APIDOC ## Core Types and Error Handling All H3 functions use `H3Index` (uint64_t), `H3Error` (uint32_t), `LatLng` (radians), `CellBoundary`, `GeoPolygon`, and `CoordIJ`. `H3_NULL` (0) signals an invalid/missing index. Always check return codes. ```c #include

#include int main(void) { H3Error err; H3Index cell; char errStr[64]; // All coordinates are in RADIANS LatLng sf = { degsToRads(37.7749), degsToRads(-122.4194) }; err = latLngToCell(&sf, 9, &cell); if (err != E_SUCCESS) { // describeH3Error returns a static string — do NOT free it fprintf(stderr, "Error %d: %s\n", err, describeH3Error(err)); return 1; } // Convert to/from string representation (at least 17 bytes) char str[17]; h3ToString(cell, str, sizeof(str)); printf("Cell string: %s\n", str); // e.g. "8928308280fffff" H3Index fromStr = 0; stringToH3("8928308280fffff", &fromStr); printf("Valid: %d\n", isValidCell(fromStr)); // 1 // Error code table: // E_SUCCESS=0, E_FAILED=1, E_DOMAIN=2, E_LATLNG_DOMAIN=3, // E_RES_DOMAIN=4, E_CELL_INVALID=5, E_DIR_EDGE_INVALID=6, // E_UNDIR_EDGE_INVALID=7, E_VERTEX_INVALID=8, E_PENTAGON=9, // E_DUPLICATE_INPUT=10, E_NOT_NEIGHBORS=11, E_RES_MISMATCH=12, // E_MEMORY_ALLOC=13, E_MEMORY_BOUNDS=14, E_OPTION_INVALID=15, // E_INDEX_INVALID=16, E_BASE_CELL_DOMAIN=17, E_DIGIT_DOMAIN=18, // E_DELETED_DIGIT=19 printf("Error 5: %s\n", describeH3Error(E_CELL_INVALID)); return 0; } // Output: // Cell string: 8928308280fffff // Valid: 1 // Error 5: Cell argument was not valid ``` ``` -------------------------------- ### Get average hexagon area in square kilometers (Go) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Gets the average hexagon area in square kilometers at the given resolution, excluding pentagons. ```go h3.HexagonAreaAvgKm2(res) ``` -------------------------------- ### Convert degrees to radians (JavaScript) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Converts degrees to radians. This is a live example. ```javascript h3.degsToRads(degrees) ``` ```javascript function example() { const degrees = 45; return h3.degsToRads(degrees); } ``` -------------------------------- ### Install H3 Build Dependencies on macOS Source: https://github.com/uber/h3/blob/master/README.md Installs the necessary build tools for H3 on macOS using Homebrew. Requires Xcode command line tools. Includes CMake, clang-format, lcov, and doxygen. ```bash # Installing the bare build requirements brew install cmake # Installing useful tools for development brew install clang-format lcov doxygen ``` -------------------------------- ### Get average hexagon area in square kilometers (C) Source: https://github.com/uber/h3/blob/master/website/docs/api/misc.mdx Gets the average hexagon area in square kilometers at the given resolution, excluding pentagons. ```c H3Error getHexagonAreaAvgKm2(int res, double *out); ``` -------------------------------- ### Get Directed Edge Destination Source: https://github.com/uber/h3/blob/master/tests/cli/getDirectedEdgeDestination.txt Demonstrates how to get the destination H3 index for a directed edge. The -f newline flag specifies the output format. ```bash add_h3_cli_test( testCliGetDirectedEdgeDestination "getDirectedEdgeDestination -c 115283473fffffff -f newline" "85283477fffffff") ```