-
Notifications
You must be signed in to change notification settings - Fork 0
/
simplify.go
68 lines (59 loc) · 1.39 KB
/
simplify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package mvt
import (
"github.com/starboard-nz/orb"
"github.com/starboard-nz/orb/planar"
)
// Simplify will run all the geometry of all the layers through the provided simplifer.
func (ls Layers) Simplify(s orb.Simplifier) {
for _, l := range ls {
l.Simplify(s)
}
}
// Simplify will run the layer geometries through the simplifier.
func (l *Layer) Simplify(s orb.Simplifier) {
count := 0
for _, f := range l.Features {
g := s.Simplify(f.Geometry)
if g == nil {
continue
}
f.Geometry = g
l.Features[count] = f
count++
}
l.Features = l.Features[:count]
}
// RemoveEmpty will remove line strings shorter/smaller than the limits.
func (ls Layers) RemoveEmpty(lineLimit, areaLimit float64) {
for _, l := range ls {
l.RemoveEmpty(lineLimit, areaLimit)
}
}
// RemoveEmpty will remove line strings shorter/smaller than the limits.
func (l *Layer) RemoveEmpty(lineLimit, areaLimit float64) {
count := 0
for i := 0; i < len(l.Features); i++ {
f := l.Features[i]
if f.Geometry == nil {
continue
}
switch f.Geometry.Dimensions() {
case 0: // point geometry
l.Features[count] = f
count++
case 1: // line geometry
length := planar.Length(f.Geometry)
if length >= lineLimit {
l.Features[count] = f
count++
}
case 2:
area := planar.Area(f.Geometry)
if area >= areaLimit {
l.Features[count] = f
count++
}
}
}
l.Features = l.Features[:count]
}