-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathprequantize.go
61 lines (51 loc) · 1.4 KB
/
prequantize.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
package topojson
import geojson "github.com/paulmach/go.geojson"
func (t *Topology) preQuantize() {
if t.opts.PreQuantize == 0 {
return
}
if t.opts.PostQuantize == 0 {
t.opts.PostQuantize = t.opts.PreQuantize
}
q0 := t.opts.PreQuantize
q1 := t.opts.PostQuantize
x0 := t.BoundingBox[0]
y0 := t.BoundingBox[1]
x1 := t.BoundingBox[2]
y1 := t.BoundingBox[3]
kx := float64(1)
if x1-x0 != 0 {
kx = (q1 - 1) / (x1 - x0) * q0 / q1
}
ky := float64(1)
if y1-y0 != 0 {
ky = (q1 - 1) / (y1 - y0) * q0 / q1
}
q := newQuantize(-x0, -y0, kx, ky)
for _, f := range t.input {
t.preQuantizeGeometry(q, f.Geometry)
}
t.Transform = q.Transform
}
func (t *Topology) preQuantizeGeometry(q *quantize, g *geojson.Geometry) {
switch g.Type {
case geojson.GeometryCollection:
for _, geom := range g.Geometries {
t.preQuantizeGeometry(q, geom)
}
case geojson.GeometryPoint:
g.Point = q.quantizePoint(g.Point)
case geojson.GeometryMultiPoint:
g.MultiPoint = q.quantizeLine(g.MultiPoint, false)
case geojson.GeometryLineString:
g.LineString = q.quantizeLine(g.LineString, true)
case geojson.GeometryMultiLineString:
g.MultiLineString = q.quantizeMultiLine(g.MultiLineString, true)
case geojson.GeometryPolygon:
g.Polygon = q.quantizeMultiLine(g.Polygon, true)
case geojson.GeometryMultiPolygon:
for i, poly := range g.MultiPolygon {
g.MultiPolygon[i] = q.quantizeMultiLine(poly, true)
}
}
}