simplify

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2019 License: MIT Imports: 3 Imported by: 0

README

orb/simplify Godoc Reference

This package implements several reducing/simplifing function for orb.Geometry types.

Currently implemented:

Note: The geometry object CAN be modified, use Clone() if a copy is required.

Douglas-Peucker

Probably the most popular simplification algorithm. For algorithm details, see wikipedia.

The algorithm is a pass through for 1d geometry, e.g. Point and MultiPoint. The algorithms can modify the original geometry, use Clone() if a copy is required.

Usage:

original := orb.LineString{}
reduced := simplify.DouglasPeucker(threshold).Simplify(original.Clone())

Visvalingam

See Mike Bostock's explanation for algorithm details.

The algorithm is a pass through for 1d geometry, e.g. Point and MultiPoint. The algorithms can modify the original geometry, use Clone() if a copy is required.

Usage:

original := orb.Ring{}

// will remove all whose triangle is smaller than `threshold`
reduced := simplify.VisvalingamThreshold(threshold).Simplify(original)

// will remove points until there are only `toKeep` points left.
reduced := simplify.VisvalingamKeep(toKeep).Simplify(original)

// One can also combine the parameters.
// This will continue to remove points until:
//  - there are no more below the threshold,
//  - or the new path is of length `toKeep`
reduced := simplify.Visvalingam(threshold, toKeep).Simplify(original)

Radial

Radial reduces the path by removing points that are close together. A full algorithm description.

The algorithm is a pass through for 1d geometry, like Point and MultiPoint. The algorithms can modify the original geometry, use Clone() if a copy is required.

Usage:

original := geo.Polygon{}

// this method uses a Euclidean distance measure.
reduced := simplify.Radial(planar.Distance, threshold).Simplify(path)

// if the points are in the lng/lat space Radial Geo will
// compute the geo distance between the coordinates.
reduced:= simplify.Radial(geo.Distance, meters).Simplify(path)

Documentation

Overview

Package simplify implements several reducing/simplifying functions for `orb.Geometry` types.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DouglasPeuckerSimplifier

type DouglasPeuckerSimplifier struct {
	Threshold float64
}

A DouglasPeuckerSimplifier wraps the DouglasPeucker function.

Example
package main

import (
	"fmt"

	"github.com/paulmach/orb"
	"github.com/paulmach/orb/simplify"
)

func main() {
	//  +
	//   \
	//    \
	//     +
	//      \
	//       \
	//  +-----+
	original := orb.LineString{{0, 0}, {2, 0}, {1, 1}, {0, 2}}

	// low threshold just removes the colinear point
	reduced := simplify.DouglasPeucker(0.0).Simplify(original.Clone())
	fmt.Println(reduced)

	// high threshold just leaves start and end
	reduced = simplify.DouglasPeucker(2).Simplify(original)
	fmt.Println(reduced)

}
Output:

[[0 0] [2 0] [0 2]]
[[0 0] [0 2]]

func DouglasPeucker

func DouglasPeucker(threshold float64) *DouglasPeuckerSimplifier

DouglasPeucker creates a new DouglasPeuckerSimplifier.

func (*DouglasPeuckerSimplifier) Collection

Collection will simplify the collection using this simplifier.

func (*DouglasPeuckerSimplifier) LineString

LineString will simplify the linestring using this simplifier.

func (*DouglasPeuckerSimplifier) MultiLineString

MultiLineString will simplify the multi-linestring using this simplifier.

func (*DouglasPeuckerSimplifier) MultiPolygon

MultiPolygon will simplify the multi-polygon using this simplifier.

func (*DouglasPeuckerSimplifier) Polygon

Polygon will simplify the polygon using this simplifier.

func (*DouglasPeuckerSimplifier) Ring

Ring will simplify the ring using this simplifier.

func (*DouglasPeuckerSimplifier) Simplify

Simplify will run the simplification for any geometry type.

type RadialSimplifier

type RadialSimplifier struct {
	DistanceFunc orb.DistanceFunc
	Threshold    float64 // euclidean distance
}

A RadialSimplifier wraps the Radial functions

Example
package main

import (
	"fmt"

	"github.com/paulmach/orb"
	"github.com/paulmach/orb/planar"
	"github.com/paulmach/orb/simplify"
)

func main() {
	//  +
	//   \
	//    \
	//     +
	//     |
	//  +--+
	original := orb.LineString{{0, 0}, {1, 0}, {1, 1}, {0, 2}}

	// will remove the points within 1.0 of the previous point
	// in this case just the second point
	reduced := simplify.Radial(planar.Distance, 1.0).Simplify(original.Clone())
	fmt.Println(reduced)

	// will remove the 2nd and 3rd point since it's within 1.5 or the first point.
	reduced = simplify.Radial(planar.Distance, 1.5).Simplify(original)
	fmt.Println(reduced)
}
Output:

func Radial

func Radial(df orb.DistanceFunc, threshold float64) *RadialSimplifier

Radial creates a new RadialSimplifier.

func (*RadialSimplifier) Collection

func (s *RadialSimplifier) Collection(c orb.Collection) orb.Collection

Collection will simplify the collection using this simplifier.

func (*RadialSimplifier) LineString

func (s *RadialSimplifier) LineString(ls orb.LineString) orb.LineString

LineString will simplify the linestring using this simplifier.

func (*RadialSimplifier) MultiLineString

func (s *RadialSimplifier) MultiLineString(mls orb.MultiLineString) orb.MultiLineString

MultiLineString will simplify the multi-linestring using this simplifier.

func (*RadialSimplifier) MultiPolygon

func (s *RadialSimplifier) MultiPolygon(mp orb.MultiPolygon) orb.MultiPolygon

MultiPolygon will simplify the multi-polygon using this simplifier.

func (*RadialSimplifier) Polygon

func (s *RadialSimplifier) Polygon(p orb.Polygon) orb.Polygon

Polygon will simplify the polygon using this simplifier.

func (*RadialSimplifier) Ring

func (s *RadialSimplifier) Ring(r orb.Ring) orb.Ring

Ring will simplify the ring using this simplifier.

func (*RadialSimplifier) Simplify

func (s *RadialSimplifier) Simplify(g orb.Geometry) orb.Geometry

Simplify will run the simplification for any geometry type.

type VisvalingamSimplifier

type VisvalingamSimplifier struct {
	Threshold float64
	ToKeep    int
}

A VisvalingamSimplifier is a reducer that performs the vivalingham algorithm.

func Visvalingam

func Visvalingam(threshold float64, minPointsToKeep int) *VisvalingamSimplifier

Visvalingam creates a new VisvalingamSimplifier.

func VisvalingamKeep

func VisvalingamKeep(toKeep int) *VisvalingamSimplifier

VisvalingamKeep runs the Visvalingam-Whyatt algorithm removing triangles of minimum area until we're down to `toKeep` number of points.

func VisvalingamThreshold

func VisvalingamThreshold(threshold float64) *VisvalingamSimplifier

VisvalingamThreshold runs the Visvalingam-Whyatt algorithm removing triangles whose area is below the threshold.

func (*VisvalingamSimplifier) Collection

Collection will simplify the collection using this simplifier.

func (*VisvalingamSimplifier) LineString

LineString will simplify the linestring using this simplifier.

func (*VisvalingamSimplifier) MultiLineString

MultiLineString will simplify the multi-linestring using this simplifier.

func (*VisvalingamSimplifier) MultiPolygon

MultiPolygon will simplify the multi-polygon using this simplifier.

func (*VisvalingamSimplifier) Polygon

Polygon will simplify the polygon using this simplifier.

func (*VisvalingamSimplifier) Ring

func (s *VisvalingamSimplifier) Ring(r orb.Ring) orb.Ring

Ring will simplify the ring using this simplifier.

func (*VisvalingamSimplifier) Simplify

Simplify will run the simplification for any geometry type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL