Skip to content
conveyalPublic

About

OpenStreetMap reader, writer, and merge tool. Written in TypeScript.

Resources

Stars

34 stars

Watchers

3 watching

Forks

Repository files navigation

Osmix

High-performance OpenStreetMap tools for TypeScript and JavaScript environments.

Ask DeepWiki

Introduction

Osmix is a collection of composable libraries for reading, querying, merging, and transforming OpenStreetMap PBF data in browsers and Node.js. Built on streaming APIs and Web Workers, Osmix handles large extracts efficiently with spatial indexing, vector tile generation, and in-browser merge workflows.

Key Features:

  • Streaming PBF parsing with minimal memory overhead
  • Spatial queries via R-tree indexes (KDBush, Flatbush)
  • Merge and deduplicate OSM extracts
  • Cross-platform – ESM-native, runs in Node.js, Bun, and browsers
  • Generate raster and vector tiles
  • Worker-based processing for responsive UIs

Limits: datasets live in memory, at about 5× the PBF file size. In a browser, files up to about 500 MB load with all features, and up to about 1 GB with reduced features. See docs/limits.md for all limits.

Try it: app.osmix.dev · Docs & examples: osmix.dev

Quick Start

pnpm add osmix

Examples

import { fromPbf, toPbfBuffer, transformOsmPbfToJson, merge, isNode } from "osmix";

// Load a PBF file
const monacoResponse = await fetch("./monaco.pbf");
const monacoPbf = new Uint8Array(await monacoResponse.arrayBuffer());
const osm = await fromPbf(monacoPbf);

// Query entities by ID
const node = osm.nodes.getById(123456);
const way = osm.ways.getById(789012);
const relation = osm.relations.getById(345678);
console.log(node, way, relation);

// Spatial queries with bounding box
const bbox: [number, number, number, number] = [7.41, 43.72, 7.43, 43.74];
const nodeResults = osm.nodes.withinBbox(bbox);
const wayResults = osm.ways.withinBbox(bbox);
console.log(`Found ${nodeResults.ids.length} nodes and ${wayResults.ids.length} ways`);

// Stream parse a PBF into JSON entities
const stream = transformOsmPbfToJson(monacoPbf.buffer);
for await (const entity of stream) {
  if ("id" in entity) {
    console.log(entity.id, entity.tags);
    if (isNode(entity)) {
      console.log(entity.lon, entity.lat);
    }
  }
}

// Serialize the PBF for a download, upload, or file-system API
const pbfBytes = await toPbfBuffer(osm);
console.log(`Serialized ${pbfBytes.byteLength} bytes`);

// Merge two OSM PBF files
const patchResponse = await fetch("./monaco-patch.pbf");
const patchPbf = new Uint8Array(await patchResponse.arrayBuffer());
const patchOsm = await fromPbf(patchPbf);
const mergedOsm = await merge(osm, patchOsm);
console.log(mergedOsm.id);

The merge-process guide is the authoritative reference for input identity, the plan's phases, defaults, matching and intersection rules, worked examples, and known limitations. merge(base, patch) uses the Merge app's defaults: identical points merge into the base, crossings connect, and matching runs only when configured. To review a merge first, use planMerge and applyPlan.

Use in a Web Worker

import { createRemote } from "osmix";

// main.ts
using remote = await createRemote();
const osm = await remote.fromPbf(monacoPbf); // Returns a dataset handle

// Operations run off the main thread
const tile = await osm.getVectorTile([9372, 12535, 15]);
console.log(tile.byteLength);

createRemote() adapts to the runtime: cross-origin isolated browsers get a multi-worker pool sharing data via SharedArrayBuffer, other browsers get a fully supported single worker, and Node/test environments can opt into running on the calling thread with inProcess: true. See the environment support matrix for details, including the COOP/COEP headers required for multi-worker mode.

Monorepo Structure

See each package's README for full API and description.

Package Description
osmix Main library packaging all tools into a unified API.
@osmix/core In-memory data structures for storing entities, building indexes, and spatial queries.
@osmix/pbf Low-level PBF protobuf parsing and writing.
@osmix/json Streaming transforms: PBF bytes ↔ typed JSON entities.
@osmix/load Load PBF into Osm indexes, geographic extracts, and PBF export.
@osmix/geojson Convert OSM entities to/from GeoJSON.
@osmix/geoparquet GeoParquet import.
@osmix/gtfs GTFS feed import.
@osmix/shapefile Shapefile import.
@osmix/change Deduplication, merging, and changeset workflows.
@osmix/raster Render OSM entities as raster bitmaps.
@osmix/cli Explore OSM PBF files in an interactive terminal map.
@osmix/vt Encode OSM entities as Mapbox Vector Tiles (MVT).
@osmix/shortbread Shortbread schema vector tiles.
@osmix/shared Utility functions and geometry helpers.
@osmix/router Experimental routing. WIP.

Development

# Install dependencies
pnpm install

# Run all apps through Portless
pnpm run dev

# Build all packages
pnpm run build

# Format, lint and type check without changing files (oxlint runs the type checker)
pnpm run check

# Apply formatting and safe lint fixes
pnpm run fix

# Run every test project: packages, apps, servers, scripts and documentation examples
pnpm run test

# Run tests for one package, or only tests affected by changes since main
pnpm exec vitest run --project @osmix/core
pnpm exec vitest run --changed origin/main

# Check, knip and test: run before committing
pnpm run verify

Workspace commands support filtering: pnpm --filter @osmix/app dev

Development servers use Portless and stable HTTPS URLs: app.osmix.localhost, bench.osmix.localhost, www.osmix.localhost, vt-server.osmix.localhost, and shortbread-server.osmix.localhost. The first run creates and trusts a local certificate authority; run pnpm exec portless trust if trust setup was skipped. pnpm run dev at the repo root runs Portless once for the whole workspace. Portless starts every app's dev script and derives each route name from the package name (@osmix/<name> → <name>.osmix.localhost). Linked worktrees on a branch other than main add the sanitized branch name as a prefix, so concurrent checkouts do not compete for routes. Detached-HEAD worktrees get no prefix; create a branch or run pnpm run dev inside the app directory instead, which starts it without Portless.

Set PORTLESS=0 to bypass the proxy and run the underlying development command directly, for example PORTLESS=0 pnpm --filter @osmix/app dev. Portless proxy and certificate state are user-level state and are not stored in this repository.

Complete TypeScript examples are marked check-docs and compiled by a test in scripts/check-docs.test.ts; partial configuration and application-wiring fragments are labeled schematic.

Routing regressions use checked-in Monaco and small generated fixtures. Reports distinguish declared route assertions from policy diagnostics and node-ID lookup from coordinate snapping. The optional local R5 comparison records its own endpoint-resolution and assertion evidence; R5 and large local datasets are not required by the normal test suite or CI.

Releasing

Releases use pnpm's built-in versioning (versioning in pnpm-workspace.yaml). A pull request that changes a published package records a change intent in .changeset/; its summary becomes the package's CHANGELOG.md entry. Packages that depend on a bumped package with workspace:* get a patch bump automatically.

# Record a change intent (use --bump none when the change needs no release)
pnpm change @osmix/core osmix --bump minor --summary "Add Osm.renumberNegativeIds"

# Show pending intents and the release plan they produce
pnpm change status

To release, run pnpm version -r on a branch from an up-to-date main. It applies the pending intents to versions and changelogs. Commit the result as "Version packages", open a pull request, and merge it. When CI passes on main, the release workflow runs pnpm publish -r, which publishes every version that is not yet on npm. It then creates a <name>@<version> tag and GitHub release for each published version that lacks one, so rerunning a failed release fills any gaps. Each package's prepack script builds it, and its publishConfig points the published entry points at dist/.

Apps

  • www – Main site with interactive examples and package overview (osmix.dev)
  • app – The Osmix app (app.osmix.dev), with three pages that share browser storage and one map:
    • Merge – reconcile an imported patch into a base dataset, reviewing every change
    • Inspect – one dataset: search, diagnose and fix duplicates, route
    • Extract – bounding-box extracts with strategy and tag filters, from a PBF file or a stored dataset
  • bench – Performance benchmarks comparing Osmix with DuckDB-wasm
  • vt-server – Example vector tile server implementation
  • shortbread – Shortbread schema vector tile server demo

Resources

About

OpenStreetMap reader, writer, and merge tool. Written in TypeScript.

Resources

Stars

34 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages