https://github.com/odlp/simplify_rb
Polyline simplification library. Ruby port of Simplify.js.
https://github.com/odlp/simplify_rb
polygon polyline polyline-simplification
Last synced: 11 months ago
JSON representation
Polyline simplification library. Ruby port of Simplify.js.
- Host: GitHub
- URL: https://github.com/odlp/simplify_rb
- Owner: odlp
- License: mit
- Created: 2014-07-24T21:56:19.000Z (almost 12 years ago)
- Default Branch: main
- Last Pushed: 2021-02-11T13:01:03.000Z (over 5 years ago)
- Last Synced: 2025-07-21T18:47:52.142Z (11 months ago)
- Topics: polygon, polyline, polyline-simplification
- Language: Ruby
- Size: 32.2 KB
- Stars: 36
- Watchers: 2
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SimplifyRb - Polyline simplification
[](https://circleci.com/gh/odlp/simplify_rb) [](https://badge.fury.io/rb/simplify_rb)
SimplifyRb is a Ruby port of [simplify.js](https://github.com/mourner/simplify-js) by Vladimir Agafonkin.
You can use this gem to reduce the number of points in a complex polyline / polygon, making use of an optimized Douglas-Peucker algorithm.
## Usage
```ruby
require 'simplify_rb'
points = [
{ x: 51.5256, y: -0.0875 },
{ x: 51.7823, y: -0.0912 }
]
tolerance = 1
high_quality = true
SimplifyRb::Simplifier.new.process(points, tolerance, high_quality)
```
```points```: An array of hashes, containing x,y coordinates.
```tolerance```: (optional, 1 by default): Affects the amount of simplification that occurs (the smaller, the less simplification).
```high_quality```: (optional, False by default): Flag to exclude the distance pre-processing. Produces higher quality results when true is passed, but runs slower.
### Custom points
You can also use custom points, such as a struct or object which responds to `:x` and `:y`, rather than hashes:
```ruby
CustomPointStruct = Struct.new(:x, :y)
custom_points = [
CustomPointStruct.new(51.5256, -0.0875),
CustomPointStruct.new(51.7823, -0.0912)
]
tolerance = 1
high_quality = true
SimplifyRb::Simplifier.new.process(custom_points, tolerance, high_quality)
```
## Installation
Add this line to your application's Gemfile:
gem 'simplify_rb'
And then execute:
$ bundle
Or install it yourself as:
$ gem install simplify_rb