-
Notifications
You must be signed in to change notification settings - Fork 2
/
process_test.go
69 lines (60 loc) · 2.28 KB
/
process_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
64
65
66
67
68
69
package osmzen
import (
"encoding/xml"
"reflect"
"testing"
"github.com/paulmach/orb/geojson"
"github.com/paulmach/orb/maptile"
"github.com/paulmach/osm"
)
func TestProcess(t *testing.T) {
// This test goes through the motions and converts a geojson building.
data := `<osm>
<way id="22942652" user="andygol" uid="94578" visible="true" version="6" changeset="46172437" timestamp="2017-02-17T18:21:11Z">
<nd ref="247139891" version="3" changeset="16969271" lat="37.8243324" lon="-122.2565497"></nd>
<nd ref="247139892" version="3" changeset="16969271" lat="37.8249618" lon="-122.2557092"></nd>
<nd ref="247139893" version="3" changeset="16969271" lat="37.8244875" lon="-122.2551399"></nd>
<nd ref="247139894" version="3" changeset="16969271" lat="37.8238958" lon="-122.25593"></nd>
<nd ref="247139895" version="3" changeset="16969271" lat="37.8241277" lon="-122.2562084"></nd>
<nd ref="247139896" version="3" changeset="16969271" lat="37.82409" lon="-122.2562588"></nd>
<nd ref="247139891" version="3" changeset="16969271" lat="37.8243324" lon="-122.2565497"></nd>
<tag k="amenity" v="parking"></tag>
<tag k="building" v="yes"></tag>
<tag k="building:levels" v="7"></tag>
<tag k="name" v="Kaiser Permanente Medical Center - Parking Garage"></tag>
<tag k="parking" v="multi-storey"></tag>
</way>
</osm>`
o := &osm.OSM{}
err := xml.Unmarshal([]byte(data), &o)
if err != nil {
t.Fatalf("unable to unmarshal xml: %v", err)
}
config, err := Load("config/queries.yaml")
if err != nil {
t.Fatalf("unable to load layer: %v", err)
}
tile, err := config.Process(o, maptile.Tile{}.Bound(), 20)
if err != nil {
t.Fatalf("unable to build geojson: %v", err)
}
feature := tile["buildings"].Features[0]
if gt := feature.Geometry.GeoJSONType(); gt != geojson.TypePolygon {
t.Errorf("incorrect geometry type: %v != %v", gt, geojson.TypePolygon)
}
expected := map[string]interface{}{
"min_zoom": 13.0,
"sort_rank": 475.0,
"scale_rank": 2.0,
"height": 23.0,
"area": 11528.0,
"volume": 265144.0,
"kind": "building",
"kind_detail": "parking_garage",
"id": 22942652,
"type": "way",
}
if !reflect.DeepEqual(feature.Properties, geojson.Properties(expected)) {
t.Errorf("incorrect properties: %v", feature.Properties)
}
}