Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

felt/simplify_ex

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simplify

Build Status Hex.pm

Implementation of the Ramer–Douglas–Peucker algorithm for reducing the number of points used to represent a curve.

Simplifying a piecewise linear curve with the Douglas–Peucker algorithm

Installation

defp deps do
  [{:simplify, "~> 1.0"}]
end

Usage

The Simplify module contains a function simplify that accepts a List of coordinates, each coordinate being a tuple {x, y}, and a tolerance. The function reduces the number of points by removing points that are less than the tolerance away from the simplified curve.

points = [{0, 0}, {0.05, 0.05}, {-0.05, 0.5}, {0, 1}, {0.05, 1.1}, {1, 1}, {0.5, 0.5}, {0, 0.0001}]

Simplify.simplify(points, 0.1) # => [{0, 0}, {0.05, 1.1}, {1, 1}, {0, 0.0001}]

The method will also take a Geo.LineString struct as created by the conversion functions in the Geo project (https://github.com/bryanjos/geo). This allows for easy import of GeoJSON or WKT/WKB formats. This version of the function returns a Geo.LineString of the simplified curve.

"{\"type\":\"LineString\":\"coordinates\":[[0,0],[0.05,0.05],[-0.05,0.5],[0,1],[0.05,1.1],[1,1],[0.5,0.5],[0,0.0001]]"
|> Jason.decode!
|> Geo.JSON.decode
|> Simplify.simplify(0.1)
|> Geo.JSON.encode
|> Jason.encode! # => "{\"coordinates\":[[0,0],[0.05,1.1],[1,1],[0,0.0001]],\"type\":\"LineString\"}"

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 100.0%