|
2 | 2 | ### MIT License ###
|
3 | 3 | ### Copyright 2014 ###
|
4 | 4 |
|
5 |
| -### Create list of all buildings in OSM file ### |
6 |
| -function getBuildings(street_map::LightXML.XMLDocument) |
7 |
| - |
8 |
| - xroot = LightXML.root(street_map) |
9 |
| - ways = LightXML.get_elements_by_tagname(xroot, "way") |
10 |
| - |
11 |
| - buildings = Dict{Int,Building}() |
12 |
| - |
13 |
| - for way in ways |
14 |
| - |
15 |
| - if LightXML.has_attribute(way, "visible") |
16 |
| - if LightXML.attribute(way, "visible") == "false" |
17 |
| - # Visible=false indicates historic data, which we will ignore |
18 |
| - continue |
19 |
| - end |
20 |
| - end |
21 |
| - |
22 |
| - # Search for tag with k="building" |
23 |
| - for tag in LightXML.child_elements(way) |
24 |
| - if LightXML.name(tag) == "tag" |
25 |
| - if LightXML.has_attribute(tag, "k") |
26 |
| - k = LightXML.attribute(tag, "k") |
27 |
| - if k == "building" |
28 |
| - class = "" |
29 |
| - if LightXML.has_attribute(tag, "v") |
30 |
| - class = LightXML.attribute(tag, "v") |
31 |
| - end |
32 |
| - |
33 |
| - id = int(LightXML.attribute(way, "id")) |
34 |
| - buildings[id] = getBuildingData(way, class) |
35 |
| - break |
36 |
| - end |
37 |
| - end |
38 |
| - end |
39 |
| - end |
40 |
| - end |
41 |
| - |
42 |
| - return buildings |
43 |
| -end |
44 |
| - |
45 |
| -### Gather highway data from OSM element ### |
46 |
| -function getBuildingData(building::LightXML.XMLElement, class::String="") |
47 |
| - nodes = Int[] |
48 |
| - class = "" |
49 |
| - building_name = "" |
50 |
| - |
51 |
| - # Get way ID |
52 |
| - # id = int64(LightXML.attribute(building, "id")) |
53 |
| - |
54 |
| - # Iterate over all "label" fields |
55 |
| - for label in LightXML.child_elements(building) |
56 |
| - |
57 |
| - if LightXML.name(label) == "tag" && LightXML.has_attribute(label, "k") |
58 |
| - k = LightXML.attribute(label, "k") |
59 |
| - |
60 |
| - # If not yet set, find the class type |
61 |
| - if isempty(class) && k == "building" |
62 |
| - if LightXML.has_attribute(label, "v") |
63 |
| - class = LightXML.attribute(label, "v") |
64 |
| - continue |
65 |
| - end |
66 |
| - end |
67 |
| - |
68 |
| - # Check if building has a name |
69 |
| - if isempty(building_name) && k == "name" |
70 |
| - if LightXML.has_attribute(label, "v") |
71 |
| - building_name = LightXML.attribute(label, "v") |
72 |
| - continue |
73 |
| - end |
74 |
| - end |
75 |
| - end |
76 |
| - |
77 |
| - # Collect associated nodes |
78 |
| - if LightXML.name(label) == "nd" && LightXML.has_attribute(label, "ref") |
79 |
| - push!(nodes, int64(LightXML.attribute(label, "ref"))) |
80 |
| - continue |
81 |
| - end |
82 |
| - end |
83 |
| - |
84 |
| - return Building(class, building_name, nodes) |
85 |
| -end |
86 |
| - |
87 | 5 | ### Classify buildings ###
|
88 | 6 | function classify(buildings::Dict{Int,Building})
|
89 | 7 | bdgs = Dict{Int,Int}()
|
|
0 commit comments