-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplification_example_test.go
More file actions
170 lines (146 loc) · 4.14 KB
/
simplification_example_test.go
File metadata and controls
170 lines (146 loc) · 4.14 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package tile
import (
"fmt"
"os"
"path/filepath"
"testing"
geom "github.com/flywave/go-geom"
"github.com/flywave/go-vector-tiler/basic"
)
func Example_simplificationStrategies() {
feature := &geom.Feature{
Geometry: basic.Point{0, 0},
Properties: map[string]interface{}{
"id": 1,
"name": "test",
},
}
layer := &Layer{
Name: "buildings",
Features: []*geom.Feature{feature},
}
provider := &MockProvider{
layers: []*Layer{layer},
srid: 3857,
}
tempDir, err := os.MkdirTemp("", "simplification_example")
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
defer os.RemoveAll(tempDir)
options := MVTOptions{
GenerateMetadata: false,
}
exporter := NewMVTExporterWithOptions(options)
fmt.Println("=== Strategy 1: Conservative (Preserve Details) ===")
config1 := &Config{
Provider: provider,
Exporter: exporter,
Concurrency: 1,
MinZoom: 0,
MaxZoom: 5,
Bound: &[4]float64{-1, -1, 1, 1},
OutputDir: filepath.Join(tempDir, "conservative"),
}
for z := uint(0); z <= 5; z++ {
tolerance := GetSimplificationTolerance(z, SimplifyConservative, 2.0)
fmt.Printf(" z=%d: tolerance=%.2f pixels\n", z, tolerance)
}
fmt.Println("\n=== Strategy 2: Moderate (Balanced) ===")
for z := uint(0); z <= 5; z++ {
tolerance := GetSimplificationTolerance(z, SimplifyModerate, 2.0)
fmt.Printf(" z=%d: tolerance=%.2f pixels\n", z, tolerance)
}
fmt.Println("\n=== Strategy 3: Aggressive (Small Files) ===")
for z := uint(0); z <= 5; z++ {
tolerance := GetSimplificationTolerance(z, SimplifyAggressive, 2.0)
fmt.Printf(" z=%d: tolerance=%.2f pixels\n", z, tolerance)
}
tiler1, _ := NewTiler(config1)
_ = tiler1
}
func Example_customSimplificationByZoomLevel() {
zoomLevels := map[uint]float64{
0: 8.0,
1: 7.0,
2: 6.0,
3: 5.0,
4: 4.0,
5: 3.5,
6: 3.0,
7: 2.5,
8: 2.0,
9: 1.8,
10: 1.5,
11: 1.2,
12: 1.0,
13: 0.8,
}
fmt.Println("=== Custom Simplification by Zoom Level ===")
for z := uint(0); z <= 14; z++ {
if tolerance, ok := zoomLevels[z]; ok {
adjusted := GetGeometrySpecificTolerance("Polygon", tolerance)
fmt.Printf(" z=%2d: tolerance=%.2f pixels (Polygon: %.2f)\n",
z, tolerance, adjusted)
} else {
fmt.Printf(" z=%2d: no simplification\n", z)
}
}
}
func Example_geometrySpecificSimplification() {
fmt.Println("=== Geometry-Specific Simplification ===")
fmt.Println("Base tolerance: 2.0 pixels")
geomTypes := []string{"Point", "LineString", "Polygon"}
for _, geomType := range geomTypes {
tolerance := GetGeometrySpecificTolerance(geomType, 2.0)
fmt.Printf(" %-12s: %.2f pixels", geomType, tolerance)
switch geomType {
case "Point":
fmt.Println(" (no simplification)")
case "LineString":
fmt.Println(" (preserve more detail)")
case "Polygon":
fmt.Println(" (normal simplification)")
}
}
}
func Example_simplificationWithRealWorldScenario() {
fmt.Println("=== Real-World Scenario: City Map ===")
scenarios := []struct {
name string
strategy SimplificationStrategy
zoom uint
geomType string
}{
{"City Overview (z=5)", SimplifyAggressive, 5, "Polygon"},
{"District View (z=10)", SimplifyModerate, 10, "Polygon"},
{"Neighborhood (z=13)", SimplifyConservative, 13, "Polygon"},
{"Building Level (z=15)", SimplifyNone, 15, "Polygon"},
}
for _, scenario := range scenarios {
tolerance := GetSimplificationTolerance(
scenario.zoom,
scenario.strategy,
2.0,
)
adjusted := GetGeometrySpecificTolerance(scenario.geomType, tolerance)
fmt.Printf("%s:\n", scenario.name)
fmt.Printf(" Strategy: %s\n", scenario.strategy)
fmt.Printf(" Base tolerance: %.2f pixels\n", tolerance)
fmt.Printf(" Adjusted for %s: %.2f pixels\n", scenario.geomType, adjusted)
fmt.Println()
}
}
func TestExampleSimplificationStrategies(t *testing.T) {
Example_simplificationStrategies()
}
func TestExampleCustomSimplificationByZoomLevel(t *testing.T) {
Example_customSimplificationByZoomLevel()
}
func TestExampleGeometrySpecificSimplification(t *testing.T) {
Example_geometrySpecificSimplification()
}
func TestExampleSimplificationWithRealWorldScenario(t *testing.T) {
Example_simplificationWithRealWorldScenario()
}