forked from paulmach/orb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplify_test.go
63 lines (50 loc) · 1.34 KB
/
simplify_test.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
package mvt
import (
"testing"
"github.com/Smadarl/orb"
"github.com/Smadarl/orb/geojson"
"github.com/Smadarl/orb/simplify"
)
func TestLayerSimplify(t *testing.T) {
// should remove feature that are empty.
ls := Layers{&Layer{
Features: []*geojson.Feature{
geojson.NewFeature(orb.LineString(nil)),
geojson.NewFeature(orb.LineString{{0, 0}, {1, 1}}),
},
}}
simplifier := simplify.DouglasPeucker(10)
ls.Simplify(simplifier)
if len(ls[0].Features) != 1 {
t.Errorf("should remove empty feature")
}
if v := ls[0].Features[0].Geometry.GeoJSONType(); v != "LineString" {
t.Errorf("incorrect type: %v", v)
}
}
func TestLayerRemoveEmpty(t *testing.T) {
// should remove empty features
ls := Layers{&Layer{
Features: []*geojson.Feature{
geojson.NewFeature(orb.Ring{{0, 0}, {1, 1}, {0, 1}, {0, 0}}),
geojson.NewFeature(orb.LineString{{0, 0}, {5, 5}, {0, 0}}),
},
}}
ls.RemoveEmpty(2, 0.5)
if len(ls[0].Features) != 2 {
t.Errorf("should not remove things above the limit")
}
// remove the area
ls.RemoveEmpty(2, 15)
if len(ls[0].Features) != 1 {
t.Errorf("should remove empty feature")
}
if v := ls[0].Features[0].Geometry.GeoJSONType(); v != "LineString" {
t.Errorf("incorrect type: %v", v)
}
// remove the line
ls.RemoveEmpty(15, 2)
if len(ls[0].Features) != 0 {
t.Errorf("should remove empty feature")
}
}