package simplify
import "github.com/paulmach/orb/simplify"
Package simplify implements several reducing/simplifying functions for `orb.Geometry` types.
Index ¶
- type DouglasPeuckerSimplifier
- func DouglasPeucker(threshold float64) *DouglasPeuckerSimplifier
- func (s *DouglasPeuckerSimplifier) Collection(c orb.Collection) orb.Collection
- func (s *DouglasPeuckerSimplifier) LineString(ls orb.LineString) orb.LineString
- func (s *DouglasPeuckerSimplifier) MultiLineString(mls orb.MultiLineString) orb.MultiLineString
- func (s *DouglasPeuckerSimplifier) MultiPolygon(mp orb.MultiPolygon) orb.MultiPolygon
- func (s *DouglasPeuckerSimplifier) Polygon(p orb.Polygon) orb.Polygon
- func (s *DouglasPeuckerSimplifier) Ring(r orb.Ring) orb.Ring
- func (s *DouglasPeuckerSimplifier) Simplify(g orb.Geometry) orb.Geometry
- type RadialSimplifier
- func Radial(df orb.DistanceFunc, threshold float64) *RadialSimplifier
- func (s *RadialSimplifier) Collection(c orb.Collection) orb.Collection
- func (s *RadialSimplifier) LineString(ls orb.LineString) orb.LineString
- func (s *RadialSimplifier) MultiLineString(mls orb.MultiLineString) orb.MultiLineString
- func (s *RadialSimplifier) MultiPolygon(mp orb.MultiPolygon) orb.MultiPolygon
- func (s *RadialSimplifier) Polygon(p orb.Polygon) orb.Polygon
- func (s *RadialSimplifier) Ring(r orb.Ring) orb.Ring
- func (s *RadialSimplifier) Simplify(g orb.Geometry) orb.Geometry
- type VisvalingamSimplifier
- func Visvalingam(threshold float64, minPointsToKeep int) *VisvalingamSimplifier
- func VisvalingamKeep(minPointsToKeep int) *VisvalingamSimplifier
- func VisvalingamThreshold(threshold float64) *VisvalingamSimplifier
- func (s *VisvalingamSimplifier) Collection(c orb.Collection) orb.Collection
- func (s *VisvalingamSimplifier) LineString(ls orb.LineString) orb.LineString
- func (s *VisvalingamSimplifier) MultiLineString(mls orb.MultiLineString) orb.MultiLineString
- func (s *VisvalingamSimplifier) MultiPolygon(mp orb.MultiPolygon) orb.MultiPolygon
- func (s *VisvalingamSimplifier) Polygon(p orb.Polygon) orb.Polygon
- func (s *VisvalingamSimplifier) Ring(r orb.Ring) orb.Ring
- func (s *VisvalingamSimplifier) Simplify(g orb.Geometry) orb.Geometry
Examples ¶
Types ¶
type DouglasPeuckerSimplifier ¶
type DouglasPeuckerSimplifier struct { Threshold float64 }
A DouglasPeuckerSimplifier wraps the DouglasPeucker function.
Code:play
Output: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)
}
[[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 ¶
func (s *DouglasPeuckerSimplifier) Collection(c orb.Collection) orb.Collection
Collection will simplify the collection using this simplifier.
func (*DouglasPeuckerSimplifier) LineString ¶
func (s *DouglasPeuckerSimplifier) LineString(ls orb.LineString) orb.LineString
LineString will simplify the linestring using this simplifier.
func (*DouglasPeuckerSimplifier) MultiLineString ¶
func (s *DouglasPeuckerSimplifier) MultiLineString(mls orb.MultiLineString) orb.MultiLineString
MultiLineString will simplify the multi-linestring using this simplifier.
func (*DouglasPeuckerSimplifier) MultiPolygon ¶
func (s *DouglasPeuckerSimplifier) MultiPolygon(mp orb.MultiPolygon) orb.MultiPolygon
MultiPolygon will simplify the multi-polygon using this simplifier.
func (*DouglasPeuckerSimplifier) Polygon ¶
func (s *DouglasPeuckerSimplifier) Polygon(p orb.Polygon) orb.Polygon
Polygon will simplify the polygon using this simplifier.
func (*DouglasPeuckerSimplifier) Ring ¶
func (s *DouglasPeuckerSimplifier) Ring(r orb.Ring) orb.Ring
Ring will simplify the ring using this simplifier.
func (*DouglasPeuckerSimplifier) Simplify ¶
func (s *DouglasPeuckerSimplifier) Simplify(g orb.Geometry) orb.Geometry
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
Code:play
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)
}
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 ¶
func (s *VisvalingamSimplifier) Collection(c orb.Collection) orb.Collection
Collection will simplify the collection using this simplifier.
func (*VisvalingamSimplifier) LineString ¶
func (s *VisvalingamSimplifier) LineString(ls orb.LineString) orb.LineString
LineString will simplify the linestring using this simplifier.
func (*VisvalingamSimplifier) MultiLineString ¶
func (s *VisvalingamSimplifier) MultiLineString(mls orb.MultiLineString) orb.MultiLineString
MultiLineString will simplify the multi-linestring using this simplifier.
func (*VisvalingamSimplifier) MultiPolygon ¶
func (s *VisvalingamSimplifier) MultiPolygon(mp orb.MultiPolygon) orb.MultiPolygon
MultiPolygon will simplify the multi-polygon using this simplifier.
func (*VisvalingamSimplifier) Polygon ¶
func (s *VisvalingamSimplifier) Polygon(p orb.Polygon) orb.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 ¶
func (s *VisvalingamSimplifier) Simplify(g orb.Geometry) orb.Geometry
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.