@watercolorizer/visvalingam
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

@watercolorizer/visvalingam License NPM Version NPM Downloads

Visvalingam–Whyatt algorithm for line simplification.

Getting Started

import { simplify } from '@watercolorizer/visvalingam';

type Vertex = { x: number; y: number };
const points: Vertex[] = [
  /* ...your points here */
];

const areaOfTriangle = ([v0, v1, v2]: [Vertex, Vertex, Vertex]) =>
  Math.abs((v0.x - v2.x) * (v1.y - v0.y) - (v0.x - v1.x) * (v2.y - v0.y));

// Simplify polyline in points to 10, removing the triangles that have the least area.
const sPoints = simplify(areaOfTriangle, points, 10);

This implementation is not opinionated about any particular vertex format, as long as associated the weightFn is compatible.

type LngLat = [lng: number, lat: number, elevation?: number];

const areaOf = (triangle: [LngLat, LngLat, LngLat]) =>
  spherical.computeArea(triangle);

// Simplify out half the points of a polyline
const simplifiedPoints = simplify(
  areaOf,
  geodata.lineString,
  geodata.lineString / 2,
);

More Info

Package Sidebar

Install

npm i @watercolorizer/visvalingam

Weekly Downloads

67

Version

1.1.1

License

ISC

Unpacked Size

15.4 kB

Total Files

15

Last publish

Collaborators

  • 32bitkid