package simplify

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

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

Index

Examples

Types

type DouglasPeuckerSimplifier

type DouglasPeuckerSimplifier struct {
	Threshold float64
}

A DouglasPeuckerSimplifier wraps the DouglasPeucker function.

Example

Code:play 

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

Code:play 

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)
}

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

	// If 0 defaults to 2 for line, 3 for non-closed rings and 4 for closed rings.
	// The intent is to maintain valid geometry after simplification, however it
	// is still possible for the simplification to create self-intersections.
	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. If minPointsToKeep is 0 the algorithm will keep at least 2 points for lines, 3 for non-closed rings and 4 for closed rings. However it is still possible for the simplification to create self-intersections.

func VisvalingamKeep

func VisvalingamKeep(minPointsToKeep int) *VisvalingamSimplifier

VisvalingamKeep runs the Visvalingam-Whyatt algorithm removing triangles of minimum area until we're down to `minPointsToKeep` number of points. If minPointsToKeep is 0 the algorithm will keep at least 2 points for lines, 3 for non-closed rings and 4 for closed rings. However it is still possible for the simplification to create self-intersections.

func VisvalingamThreshold

func VisvalingamThreshold(threshold float64) *VisvalingamSimplifier

VisvalingamThreshold runs the Visvalingam-Whyatt algorithm removing triangles whose area is below the threshold. Will keep at least 2 points for lines, 3 for non-closed rings and 4 for closed rings. The intent is to maintain valid geometry after simplification, however it is still possible for the simplification to create self-intersections.

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.

Source Files

douglas_peucker.go helpers.go radial.go visvalingam.go

Version
v0.11.1 (latest)
Published
Jan 29, 2024
Platform
js/wasm
Imports
3 packages
Last checked
1 day ago

Tools for package owners.