Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simplify-geojson

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simplify-geojson

Apply Ramer-Douglas-Peucker line simplification to GeoJSON features or feature collections in JS or on the CLI

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.9K
decreased by-19.49%
Maintainers
2
Weekly downloads
 
Created
Source

simplify-geojson

Apply Ramer–Douglas–Peucker line simplification to GeoJSON features or feature collections in JS or on the CLI.

NPM

This module uses https://github.com/seabre/simplify-geometry for the simplification and wraps it in a interface for easily simplifying GeoJSON.

Install

npm install simplify-geojson

Usage

CLI

cat data.geojson | simplify-geojson -t 0.01

Tolerance is specified by either -t or --tolerance and is a number in degrees (e.g. lat/lon distance). 1 degree is roughly equivalent to 69 miles. the default is 0.001, which is around a city block long.

JS

var simplify = require('simplify-geojson')
var simplified = simplify(geojson, tolerance)

geojson can be any of the following:

  • Feature with a LineString
  • Feature with a MultiLineString
  • Feature with a Polygon
  • Feature with a MultiPolygon
  • FeatureCollection with any of the above

All segments in any of the supported types will be simplified (including holes in polygons, for instance).

Examples

Convert a CSV with lat/lon columns into geojson, then simplify that geojson, then open it in geojson.io (CSV is from my GPS logger and was my bike commute this morning):

npm install simplify-geojson geojsonio-cli csv2geojson -g
curl https://raw.github.com/maxogden/simplify-geojson/master/test-data/oakland-route.csv | \
  csv2geojson --lat "LATITUDE N/S" --lon "LONGITUDE E/W" --line true | \
  simplify-geojson -t 0.001 | \
  geojsonio

Simplify alaska's border outline and count the number of lines of the simplified geojson output (tweak -t to see how it affects length):

curl https://rawgit.com/johan/world.geo.json/master/countries/USA/AK.geo.json | \
  simplify-geojson -t 0.01 | \
  wc -l

Contributing

Contributors welcome! Please read the contributing guidelines before getting started.

License

BSD-2-Clause

Keywords

FAQs

Package last updated on 12 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc