# h3-to-geojson

> A lightweight utility library for converting H3 cells to GeoJSON features and geometries, along with additional tools for working with the H3 geoindexing system.

Latest version **0.1.1** (published 2026-09-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install h3-to-geojson
pnpm add h3-to-geojson
yarn add h3-to-geojson
bun add h3-to-geojson
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2026-09-23 |
| First published | 2024-12-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 26.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Alberto Rico |
| Maintainers | alrico88 |
| Keywords | h3, cell, geojson, h3 to geojson, cell |

## Links

- npm: https://www.npmjs.com/package/h3-to-geojson
- Repository: https://github.com/alrico88/h3-to-geojson
- Homepage: https://github.com/alrico88/h3-to-geojson#readme
- Issues: https://github.com/alrico88/h3-to-geojson/issues
- npm.io page: https://npm.io/package/h3-to-geojson

## Dependencies (3)

- [h3-js](https://npm.io/package/h3-js.md) ^4.5.0
- [@turf/helpers](https://npm.io/package/@turf/helpers.md) ^7.1.0
- [bbox-helper-functions](https://npm.io/package/bbox-helper-functions.md) ^3.3.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.1 (latest) — 2026-09-23
- 0.1.0 — 2024-12-06

## README

# h3-to-geojson

A lightweight utility library for converting H3 cells to GeoJSON features and geometries, along with additional tools for working with the [H3 geoindexing system](https://h3geo.org/).

## Features

- Convert H3 cells to GeoJSON Point and Polygon features or geometries.
- Convert coordinates to H3 cells and vice versa.
- Retrieve H3 cells contained within a GeoJSON Polygon or MultiPolygon.
- Calculate the bounding box (BBox) of an H3 cell.
- Get the resolution of an H3 cell.

## Installation

Install the library:

```bash
npm install h3-to-geojson
```

or

```bash
pnpm add h3-to-geojson
```

## Usage

Here is an example of how to use the library:

```javascript
import {
  coordToH3,
  h3ToCoord,
  h3ToPointFeature,
  h3ToPolygonFeature,
  getH3InsideGeoJSON,
} from 'h3-to-geojson';

// Convert coordinates to an H3 cell
const coord = [-3.6886, 40.4201]; // Madrid [longitude, latitude]
const resolution = 9;
const h3Cell = coordToH3(coord, resolution);
console.log('H3 Cell:', h3Cell);

// Convert an H3 cell back to coordinates
const backToCoord = h3ToCoord(h3Cell);
console.log('Coordinates:', backToCoord);

// Convert an H3 cell to a GeoJSON Point feature
const pointFeature = h3ToPointFeature(h3Cell);
console.log('GeoJSON Point Feature:', pointFeature);

// Convert an H3 cell to a GeoJSON Polygon feature
const polygonFeature = h3ToPolygonFeature(h3Cell);
console.log('GeoJSON Polygon Feature:', polygonFeature);

// Retrieve all H3 cells inside a GeoJSON Polygon
const geojsonPolygon = {
  type: 'Polygon',
  coordinates: [
    [
      [-3.700647, 40.404397],
      [-3.700647, 40.43498],
      [-3.667943, 40.43498],
      [-3.667943, 40.404397],
      [-3.700647, 40.404397],
    ],
  ],
};
const h3Cells = getH3InsideGeoJSON(geojsonPolygon, resolution);
console.log('H3 Cells inside the GeoJSON Polygon:', h3Cells);
```

## Documentation

See [DOCS](./docs/README.md)

## License

This project is licensed under the [MIT License](LICENSE).

## Acknowledgements

- Built on top of the [H3-js](https://github.com/uber/h3-js) library.
- GeoJSON utilities powered by [@turf/helpers](https://turfjs.org/).

---
_Source: https://npm.io/package/h3-to-geojson · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
