geosimplification

package module
v0.0.0-...-5dc3a2a Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: MIT Imports: 2 Imported by: 1

README

Geo Simplification

This work is based off Jason Davies Excellent blog post, it implements the Visvalingam line simplification algorithm in Golang. It's designed to work with the official golang geo library.

It's been extended to support loops

What doesn't work?

If your polygon has more than one loop this library will not work. This is due to issues with simplifying holes in polygons.

Usage

Reduce to a specific number of points

import (
	geosimplification "github.com/hcliff/geo-simplification"
)

loop := []s2.Loop{
	s2.PointFromLatLng(s2.LatLngFromDegrees(40.319325896602095, -73.14971923828125)),
	s2.PointFromLatLng(s2.LatLngFromDegrees(40.32141999593439, -73.31451416015625)),
	s2.PointFromLatLng(s2.LatLngFromDegrees(40.2313150803688, -73.4271240234375)),
	s2.PointFromLatLng(s2.LatLngFromDegrees(40.24179856487036, -73.16619873046875)),
}
# keep removing points until we reach 4 points in the loop
threshold := 0
minPointsToKeep := 4
avoidIntersections := true
simplified, err := geosimplification.SimplifyLoop(loop, threshold, minPointsToKeep, avoidIntersections)

Reduce to a specific level of detail

import (
	geosimplification "github.com/hcliff/geo-simplification"
)

loop := []s2.Loop{
	s2.PointFromLatLng(s2.LatLngFromDegrees(40.264856517201856, -73.32550048828125)),
	s2.PointFromLatLng(s2.LatLngFromDegrees(40.319325896602095, -73.14971923828125)),
	s2.PointFromLatLng(s2.LatLngFromDegrees(40.32141999593439, -73.31451416015625)),
	s2.PointFromLatLng(s2.LatLngFromDegrees(40.2313150803688, -73.4271240234375)),
	s2.PointFromLatLng(s2.LatLngFromDegrees(40.24179856487036, -73.16619873046875)),
}
# remove points that don't provide much extra detail to the shape
threshold := 0.001
minPointsToKeep := 5
avoidIntersections := true
simplified, err := geosimplification.SimplifyLoop(loop, threshold, minPointsToKeep, avoidIntersections)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SimplifyLine

func SimplifyLine(
	polyline s2.Polyline,
	threshold float64,
	minPointsToKeep int,
	avoidIntersections bool,
) (output s2.Polyline, err error)

func SimplifyLoop

func SimplifyLoop(
	loop *s2.Loop,
	threshold float64,
	minPointsToKeep int,
	avoidIntersections bool,
) (output *s2.Loop, err error)

Types

This section is empty.

Directories

Path Synopsis
The heap contains every point in the polygon Popping the heap will give you the point with the smallest angle/area a.k.a: the least significant point helper package for determining if edges cross Concrete implementation of VertexCollection for traversing "lines" Concrete implementation of VertexCollection for traversing "loops"
The heap contains every point in the polygon Popping the heap will give you the point with the smallest angle/area a.k.a: the least significant point helper package for determining if edges cross Concrete implementation of VertexCollection for traversing "lines" Concrete implementation of VertexCollection for traversing "loops"

Jump to

Keyboard shortcuts

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