# JavaScript geospatial libraries

JavaScript geospatial libraries measure, transform, and analyze geographic coordinates and shapes. A coordinate system defines how each longitude and latitude maps to a position on the Earth or on a flat map. These libraries calculate the distances, delivery zones, map projections, and boundary checks in mapping and location apps.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [d3-geo](#dthree-geo) | 205.4M | 1.1K | Nov 2026 | ISC |
| [TopoJSON Client](#topojson-client) | 44.8M | 242 | Nov 2019 | ISC |
| [Proj4js](#proj-js) | 9.1M | 2.2K | Nov 2026 | MIT |
| [cheap-ruler](#cheap-ruler) | 9.1M | 434 | Oct 2026 | ISC |
| [Turf](#turf) | 9.0M | 10.6K | Aug 2026 | MIT |
| [h3-js](#hthree-js) | 8.0M | 1.1K | Jul 2026 | Apache-2.0 |
| [JSTS](#jsts) | 7.7M | 1.6K | Nov 2024 | (EDL-1.0 OR EPL-1.0) |
| [Geolib](#geolib) | 3.1M | 4.3K | Nov 2026 | MIT |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[d3-geo](#dthree-geo) has the most monthly downloads in this comparison, at 205.4M.

## Capabilities

| Library | Spherical distance | GeoJSON geometry input |
| --- | --- | --- |
| [d3-geo](#dthree-geo) | Yes | Yes |
| [TopoJSON Client](#topojson-client) | No | No |
| [Proj4js](#proj-js) | No | No |
| [cheap-ruler](#cheap-ruler) | No | No |
| [Turf](#turf) | Yes | Yes |
| [h3-js](#hthree-js) | Yes | No |
| [JSTS](#jsts) | No | Yes |
| [Geolib](#geolib) | Yes | No |

## Libraries

### d3-geo

[GitHub](https://github.com/d3/d3-geo) · [npm](https://www.npmjs.com/package/d3-geo) · [Docs](https://d3js.org/d3-geo/math)

Calculates shapes and measurements for spherical coordinates.

- Downloads / mo: 205.4M
- Stars: 1.1K
- Last release: 3.1.2
- License: ISC
- Capabilities: [From the d3-geo docs](https://d3js.org/d3-geo/math)

**Strengths**

- **Projects onto a flat map.** Projections turn spherical polygons into planar polygons for drawing.

**Watch out for**

- **Clipped points return null.** Check for null when a point falls outside the projection's clipping bounds.

```sh
npm install d3-geo@3.1.2
```

**observablehq/plot** (5.4K stars)

[observablehq/plot](https://github.com/observablehq/plot) 

```javascript
export function projectionAspectRatio(projection) {
  if (typeof projection?.stream === "function") return defaultAspectRatio;
  if (isObject(projection)) {
    let domain, options;
    ({domain, type: projection, ...options} = projection);
    if (domain != null && projection != null) {
      const type = typeof projection === "string" ? namedProjection(projection).type : projection;
      const [[x0, y0], [x1, y1]] = geoPath(type({...options, width: 100, height: 100})).bounds(domain);
      const r = (y1 - y0) / (x1 - x0);
      return r && isFinite(r) ? (r < 0.2 ? 0.2 : r > 5 ? 5 : r) : defaultAspectRatio;
    }
  }
  if (projection == null) return;
  if (typeof projection !== "function") {
    const {aspectRatio} = namedProjection(projection);
    if (aspectRatio) return aspectRatio;
  }
  return defaultAspectRatio;
}

```

[src/projection.js](https://github.com/observablehq/plot/blob/2245188895e95ef2043f0ad12c2f900d6e48ef1a/src/projection.js#L290) · [More projects using d3-geo →](https://dashboard.exa.ai/playground/search?q=d3-geo%20GitHub%20projects)

**Quickstart**

```javascript
import { geoDistance } from "d3-geo";
console.log(geoDistance([0, 0], [1, 0]));

```

From [math docs](https://d3js.org/d3-geo/math)

### TopoJSON Client

[GitHub](https://github.com/topojson/topojson-client) · [npm](https://www.npmjs.com/package/topojson-client) · [Docs](https://raw.githubusercontent.com/topojson/topojson-client/master/README.md)

Manipulates TopoJSON and converts it to GeoJSON.

- Downloads / mo: 44.8M
- Stars: 242
- Last release: 3.1.0
- License: ISC
- Capabilities: [From the TopoJSON Client docs](https://raw.githubusercontent.com/topojson/topojson-client/master/README.md)

**Strengths**

- **Merges and quantizes shapes.** Merge shapes or quantize coordinates before converting back to GeoJSON.

```sh
npm install topojson-client@3.1.0
```

**vega/vega** (12.1K stars)

[vega/vega](https://github.com/vega/vega) 

```javascript
export default function topojson(data, format) {
  let method, object, property, filter;
  data = json(data, format);

  if (format && format.feature) {
    method = feature;
    property = format.feature;
  } else if (format && format.mesh) {
    method = mesh;
    property = format.mesh;
    filter = filters[format.filter];
  } else {
    error('Missing TopoJSON feature or mesh parameter.');
  }

  object = (object = data.objects[property])
    ? method(data, object, filter)
    : error('Invalid TopoJSON object: ' + property);

  return object && object.features || [object];
}

```

[packages/vega-loader/src/formats/topojson.js](https://github.com/vega/vega/blob/bd7261aa7b782aa6906e121c3810691661f08f41/packages/vega-loader/src/formats/topojson.js#L10) · [More projects using TopoJSON Client →](https://dashboard.exa.ai/playground/search?q=topojson-client%20GitHub%20projects)

**Quickstart**

```javascript
import { feature } from "topojson-client";
const topology = { type: "Topology", objects: { place: { type: "Point", coordinates: [0, 0] } }, arcs: [] };
console.log(feature(topology, topology.objects.place));

```

From [README.md](https://raw.githubusercontent.com/topojson/topojson-client/master/README.md)

### Proj4js

[GitHub](https://github.com/proj4js/proj4js) · [npm](https://www.npmjs.com/package/proj4) · [Docs](https://raw.githubusercontent.com/proj4js/proj4js/master/README.md)

Converts point coordinates between coordinate systems, including datum transformations.

- Downloads / mo: 9.1M
- Stars: 2.2K
- Last release: 2.23.0
- License: MIT
- Capabilities: [From the Proj4js docs](https://raw.githubusercontent.com/proj4js/proj4js/master/README.md)

**Strengths**

- **Converts between coordinate systems.** Supply source and target definitions to transform point coordinates.
- **Reuses forward and inverse converters.** Create a converter once and use both transformation directions.

**Watch out for**

- **Grid adjustments need loaded files.** Load the required grid before using its datum transformation.
- **Defaults to longitude before latitude.** Set enforceAxis when coordinates follow the definition’s different axis order.

```sh
npm install proj4@2.23.0
```

**openlayers/openlayers** (12.7K stars)

[openlayers/openlayers](https://github.com/openlayers/openlayers) 

```javascript
export function fromProjectionDefinition(def) {
  const proj4 = registered;
  if (!proj4) {
    throw new Error('Proj4 must be registered first with register(proj4)');
  }
  // Fallback code is the whole def...
  let code = JSON.stringify(def);
  proj4.defs(code, def);
  const proj4Def = proj4.defs(code);
  if (proj4Def.title) {
    // ...but use authority:code if available
    proj4.defs(code, /** @type {?} */ (null));
    code = proj4Def.title;
    const projection = getCachedProjection(code);
    if (projection) {
      return projection;
    }
    proj4.defs(code, def);
  }
  register(proj4);
  const projection = getCachedProjection(code);
  if (!projection) {
    throw new Error('Projection not found after registration');
  }
  return projection;
}

```

[src/ol/proj/proj4.js](https://github.com/openlayers/openlayers/blob/33bcbad9945b3779c5bd7bb44226e5505c088264/src/ol/proj/proj4.js#L179) · [More projects using Proj4js →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20applications%20using%20proj4%20for%20geometry%20analysis%20coordinate%20transformation%20geofencing%20and%20geographic%20calculations&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
import proj4 from "proj4";
console.log(proj4("EPSG:4326", "EPSG:3857", [0, 0]));

```

From [README.md](https://raw.githubusercontent.com/proj4js/proj4js/master/README.md)

### cheap-ruler

[GitHub](https://github.com/mapbox/cheap-ruler) · [npm](https://www.npmjs.com/package/cheap-ruler) · [Docs](https://raw.githubusercontent.com/mapbox/cheap-ruler/main/README.md)

Approximates common geographic measurements.

- Downloads / mo: 9.1M
- Stars: 434
- Last release: 4.1.1
- License: ISC
- Capabilities: [From the cheap-ruler docs](https://raw.githubusercontent.com/mapbox/cheap-ruler/main/README.md)

**Strengths**

- **Precise at city scale.** Under 500 km and away from the poles, results stay within 0.1% of Vincenty's formulae.

**Watch out for**

- **Reuse one ruler per area.** Create a ruler once for an area and reuse it across calculations.

```sh
npm install cheap-ruler@4.1.1
```

**cheeaun/busrouter-sg** (381 stars)

[cheeaun/busrouter-sg](https://github.com/cheeaun/busrouter-sg) 

```javascript
(a, b) =>
    ruler.lineDistance(a.geometry.coordinates) -
    ruler.lineDistance(b.geometry.coordinates)

```

[visualization/build-routes.mjs](https://github.com/cheeaun/busrouter-sg/blob/e414a251b898453dac58b823ef1c66eb12592132/visualization/build-routes.mjs#L28-L30) · [More projects using cheap-ruler →](https://dashboard.exa.ai/playground/search?q=cheap-ruler%20GitHub%20projects)

**Quickstart**

```javascript
import CheapRuler from "cheap-ruler";
const ruler = new CheapRuler(50.5, "meters");
console.log(ruler.distance([30.5, 50.5], [30.51, 50.51]));

```

From [README.md](https://raw.githubusercontent.com/mapbox/cheap-ruler/main/README.md)

### Turf

[GitHub](https://github.com/Turfjs/turf) · [npm](https://www.npmjs.com/package/@turf/turf) · [Docs](https://turfjs.org/docs/api/distance)

Analyzes GeoJSON features with geographic measurements, geometry operations, and spatial tests.

- Downloads / mo: 9.0M
- Stars: 10.6K
- Last release: 7.4.0
- License: MIT
- Capabilities: [From the Turf docs](https://turfjs.org/docs/api/distance)

**Strengths**

- **Works directly with GeoJSON.** Create features and analyze their geometry without a separate geometry model.
- **Tests polygons with holes.** booleanPointInPolygon handles concave shapes and polygon holes.

**Watch out for**

- **Expects longitude before latitude.** Use WGS84 coordinates in GeoJSON order before running geographic analysis.
- **Shrinking can remove features.** A large negative buffer can return fewer geometries or an empty collection.

```sh
npm install @turf/turf@7.4.0
```

**visgl/deck.gl** (14.8K stars)

[visgl/deck.gl](https://github.com/visgl/deck.gl) 

```javascript
function getLabelAtPoint<FeatureProperties>(
  line: Feature<LineString, FeatureProperties>,
  lineLength: number,
  dAlong: number,
  priority: number
): Label<FeatureProperties> {
  const offset = dAlong + 1 < lineLength ? 1 : -1;
  const point = along(line, dAlong);
  const nextPoint = along(line, dAlong + offset);
  if (booleanEqual(point, nextPoint)) return null;

  let angle = 90 - rhumbBearing(point, nextPoint);
  if (Math.abs(angle) > 90) angle += 180;

  return {
    position: point.geometry.coordinates,
    priority,
    angle,
    parent: line.properties
  };
}

```

[examples/website/collision-filter/calculate-labels.ts](https://github.com/visgl/deck.gl/blob/5d6257227a0aea0c92453cc798a683ab0d1f6ecb/examples/website/collision-filter/calculate-labels.ts#L72) · [More projects using Turf →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20applications%20using%20%40turf/turf%20for%20geometry%20analysis%20coordinate%20transformation%20geofencing%20and%20geographic%20calculations&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
import { distance } from "@turf/turf";
console.log(distance([0, 0], [1, 0], { units: "kilometers" }));

```

From [README.md](https://turfjs.org/docs/api/distance)

### h3-js

[GitHub](https://github.com/uber/h3-js) · [npm](https://www.npmjs.com/package/h3-js) · [Docs](https://raw.githubusercontent.com/uber/h3-js/master/README.md)

Provides a pure JavaScript version of H3, a hexagon-based geographic grid system.

- Downloads / mo: 8.0M
- Stars: 1.1K
- Last release: 4.5.0
- License: Apache-2.0
- Capabilities: [From the h3-js docs](https://raw.githubusercontent.com/uber/h3-js/master/README.md)

**Strengths**

- **Indexes points into hexagons.** latLngToCell turns a latitude and longitude into a hexagon index at a chosen resolution.

**Watch out for**

- **Function names changed in v4.** Code written for H3 v3 needs the renamed v4 functions.

```sh
npm install h3-js@4.5.0
```

**visgl/deck.gl** (14.8K stars)

[visgl/deck.gl](https://github.com/visgl/deck.gl) 

```javascript
export function h3ToPolygon(hexId: H3IndexInput, coverage: number = 1): number[][] {
  const vertices = cellToBoundary(hexId, true);

  if (coverage !== 1) {
    // scale and normalize vertices w.r.t to center
    scalePolygon(hexId, vertices, coverage);
  } else {
    // normalize w.r.t to start vertex
    normalizeLongitudes(vertices);
  }

  return vertices;
}

```

[modules/geo-layers/src/h3-layers/h3-utils.ts](https://github.com/visgl/deck.gl/blob/5d6257227a0aea0c92453cc798a683ab0d1f6ecb/modules/geo-layers/src/h3-layers/h3-utils.ts#L45) · [More projects using h3-js →](https://dashboard.exa.ai/playground/search?q=h3-js%20GitHub%20projects)

**Quickstart**

```javascript
import { latLngToCell } from "h3-js";
console.log(latLngToCell(37.3615593, -122.0553238, 7));

```

From [README.md](https://raw.githubusercontent.com/uber/h3-js/master/README.md)

### JSTS

[GitHub](https://github.com/bjornharrtell/jsts) · [npm](https://www.npmjs.com/package/jsts) · [Docs](https://raw.githubusercontent.com/bjornharrtell/jsts/2.12.1/src/org/locationtech/jts/io/GeoJSONReader.js)

Processes geometries and spatial relationships using the JTS geometry model.

- Downloads / mo: 7.7M
- Stars: 1.6K
- Last release: 2.12.1
- License: (EDL-1.0 OR EPL-1.0)
- Capabilities: [From the JSTS docs](https://raw.githubusercontent.com/bjornharrtell/jsts/2.12.1/src/org/locationtech/jts/io/GeoJSONReader.js)

**Strengths**

- **Connects to OpenLayers geometries.** Read and write OpenLayers geometries through its direct parser.
- **Reads WKT and GeoJSON.** Use either geometry format when exchanging shapes with other tools.

**Watch out for**

- **Precision errors can stop operations.** Validate inputs and reduce coordinate precision when geometry calculations fail.
- **Requires operation classes for methods.** Use the operation class instead of calling geometry.buffer in ES modules.

```sh
npm install jsts@2.12.1
```

**geops/openlayers-editor** (230 stars)

[geops/openlayers-editor](https://github.com/geops/openlayers-editor) 

```javascript
buffer(width) {
  const parser = new OL3Parser();
  parser.inject(
    Point,
    LineString,
    LinearRing,
    Polygon,
    MultiPoint,
    MultiLineString,
    MultiPolygon,
  );

  const features = this.selectInteraction.getFeatures().getArray();
  for (let i = 0; i < features.length; i += 1) {
    const jstsGeom = parser.read(features[i].getGeometry());
    const bo = new BufferOp(jstsGeom);
    const buffered = bo.getResultGeometry(width);
    features[i].setGeometry(parser.write(buffered));
  }
}

```

[src/control/buffer.js](https://github.com/geops/openlayers-editor/blob/ce95cf3c266e6eb9d585b8455e65500051b07c17/src/control/buffer.js#L71) · [More projects using JSTS →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20applications%20using%20jsts%20for%20geometry%20analysis%20coordinate%20transformation%20geofencing%20and%20geographic%20calculations&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
import GeoJSONReader from "jsts/org/locationtech/jts/io/GeoJSONReader.js";
const reader = new GeoJSONReader();
console.log(reader.read({ type: "Point", coordinates: [0, 0] }));

```

From [index_modules.js](https://raw.githubusercontent.com/bjornharrtell/jsts/2.12.1/src/org/locationtech/jts/io/GeoJSONReader.js)

### Geolib

[GitHub](https://github.com/manuelbieh/geolib) · [npm](https://www.npmjs.com/package/geolib) · [Docs](https://raw.githubusercontent.com/manuelbieh/geolib/master/README.md)

Calculates geographic distances, bearings, and location boundaries from coordinate pairs.

- Downloads / mo: 3.1M
- Stars: 4.3K
- Last release: 4.0.2
- License: MIT
- Capabilities: [From the Geolib docs](https://raw.githubusercontent.com/manuelbieh/geolib/master/README.md)

**Strengths**

- **Checks polygon boundaries directly.** Use isPointInPolygon to check whether a location lies inside an outline.
- **Offers ellipsoid-based distance calculations.** Use getPreciseDistance for Vincenty distance calculations on an ellipsoid.

**Watch out for**

- **Ignores altitude and elevation.** Distance and boundary calculations operate in two dimensions.
- **Polygon vertices need outline order.** Supply vertices clockwise or counterclockwise around the polygon boundary.

```sh
npm install geolib@4.0.2
```

**zachowj/node-red-contrib-home-assistant-websocket** (601 stars)

[zachowj/node-red-contrib-home-assistant-websocket](https://github.com/zachowj/node-red-contrib-home-assistant-websocket) 

```javascript
export function inZone(location: locationData, zone: locationData): boolean {
    const { radius = 0, ...zoneLatLog } = zone;
    const inZone = isPointWithinRadius(location, zoneLatLog, radius);

    return inZone;
}

```

[src/nodes/zone/helpers.ts](https://github.com/zachowj/node-red-contrib-home-assistant-websocket/blob/d678f8bb73447ec18808dac6c90c356496033897/src/nodes/zone/helpers.ts#L6) · [More projects using Geolib →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20applications%20using%20geolib%20for%20geometry%20analysis%20coordinate%20transformation%20geofencing%20and%20geographic%20calculations&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
import { getDistance } from "geolib";
console.log(getDistance({ latitude: 51.5103, longitude: 7.49347 }, { latitude: 51.525, longitude: 7.4575 }));

```

From [README.md](https://raw.githubusercontent.com/manuelbieh/geolib/master/README.md)

## FAQ

### Which JavaScript geospatial library should I use?

[Turf](#turf) fits analysis of GeoJSON features, such as distances and point-in-polygon tests. [Proj4js](#proj-js) converts coordinates between coordinate systems, and [d3-geo](#dthree-geo) projects geographic shapes onto a flat map.

### What is GeoJSON?

GeoJSON is a JSON format for geographic features such as points, lines, and polygons, each with its coordinates and properties. [Turf](#turf) and [JSTS](#jsts) read GeoJSON directly.

### What is Geolib?

[Geolib](#geolib) calculates distances, bearings, and boundary checks from plain coordinate pairs. It works in two dimensions and ignores altitude.

### What is h3-js?

[h3-js](#hthree-js) is the pure JavaScript version of Uber's hexagon-based geographic grid system. Its latLngToCell function turns a latitude and longitude into a hexagon index at a chosen resolution.

### What does Proj4js do?

[Proj4js](#proj-js) transforms point coordinates from one coordinate system to another, including datum transformations. It expects longitude before latitude unless enforceAxis is set.

### What is TopoJSON?

TopoJSON stores geographic shapes with shared borders as arcs. [TopoJSON Client](#topojson-client) converts TopoJSON back to GeoJSON for rendering with tools such as d3-geo.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript geospatial libraries Turf JSTS Proj4js Geolib code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
