|
1 | 1 | #' Categorises OSM's keys |
2 | 2 | #' |
3 | 3 | #' @description |
4 | | -#' Generates a hierarchical categorisation of OSM keys, based on the type of information they convey. |
| 4 | +#' Generates a hierarchical categorisation of OSM keys, based on the type of information they convey. |
5 | 5 | #' For a given dataframe, this function generates two extra columns called `top_key` and `parent_key` whose values will depend on the values from the this function. |
6 | | -#' |
| 6 | +#' |
7 | 7 | #' @param df a dataframe with keys and values generated by [extract_and_combine_tags()] |
8 | 8 | #' |
9 | 9 | #' @returns a new dataframe with the same columns and two extra ones called `top_key` and `parent_key` with values defined by this function. |
|
14 | 14 | #' key = c("wheelchair", "building:levels", "highway") |
15 | 15 | #' ) |
16 | 16 | #' categorise_keys(df) |
17 | | -#' |
| 17 | +#' |
18 | 18 | categorise_keys <- function(df) { |
19 | 19 | accessibility_keys <- c( |
20 | | - "wheelchair", "ramp", "tactile_paving", "traffic_signals:sound", |
21 | | - "traffic_signals:vibration", "bench", |
| 20 | + "wheelchair", |
| 21 | + "ramp", |
| 22 | + "tactile_paving", |
| 23 | + "traffic_signals:sound", |
| 24 | + "traffic_signals:vibration", |
| 25 | + "bench", |
22 | 26 | "handrail" |
23 | 27 | ) |
24 | | - amenity_keys <- c("cuisine", "opening_hours", "office", "phone", "website", "takeaway", "school") |
| 28 | + amenity_keys <- c( |
| 29 | + "cuisine", |
| 30 | + "opening_hours", |
| 31 | + "office", |
| 32 | + "phone", |
| 33 | + "website", |
| 34 | + "takeaway", |
| 35 | + "school" |
| 36 | + ) |
25 | 37 |
|
26 | | - boundaries_keys <- c("admin_level", "boundary", "claimed_by", "disputed", "place", "landuse") |
| 38 | + boundaries_keys <- c( |
| 39 | + "admin_level", |
| 40 | + "boundary", |
| 41 | + "claimed_by", |
| 42 | + "disputed", |
| 43 | + "place", |
| 44 | + "landuse" |
| 45 | + ) |
27 | 46 |
|
28 | | - care_keys <- c("emergency", "clinic", "emergency", "health", "hospital", "medical", "shelter", "social_facility") |
| 47 | + care_keys <- c( |
| 48 | + "emergency", |
| 49 | + "clinic", |
| 50 | + "emergency", |
| 51 | + "health", |
| 52 | + "hospital", |
| 53 | + "medical", |
| 54 | + "shelter", |
| 55 | + "social_facility" |
| 56 | + ) |
| 57 | + |
| 58 | + contact_keys <- c( |
| 59 | + "contact", |
| 60 | + "email", |
| 61 | + "fax", |
| 62 | + "opening_hours", |
| 63 | + "phone", |
| 64 | + "website" |
| 65 | + ) |
29 | 66 |
|
30 | | - contact_keys <- c("contact", "email", "fax", "opening_hours", "phone", "website") |
31 | | - |
32 | 67 | edi_keys <- c("lgbtq", "women", "refugee", "wheelchair") |
33 | | - |
| 68 | + |
34 | 69 | health_keys <- c("hospital") |
35 | 70 |
|
36 | 71 | highway_keys <- c( |
37 | | - "access", "barrier", "bench", "bin", "bridge", "handrail", "highway", "incline", "lanes", "lit", "oneway", |
38 | | - "ramp", "sac_scale", "segregated", "service", "smoothness", "tracktype", "width" |
| 72 | + "access", |
| 73 | + "barrier", |
| 74 | + "bench", |
| 75 | + "bin", |
| 76 | + "bridge", |
| 77 | + "handrail", |
| 78 | + "highway", |
| 79 | + "incline", |
| 80 | + "lanes", |
| 81 | + "lit", |
| 82 | + "oneway", |
| 83 | + "ramp", |
| 84 | + "sac_scale", |
| 85 | + "segregated", |
| 86 | + "service", |
| 87 | + "smoothness", |
| 88 | + "tracktype", |
| 89 | + "width" |
39 | 90 | ) |
40 | | - |
| 91 | + |
41 | 92 | leisure_keys <- c("sauna", "swimming_pool") |
42 | | - |
43 | | - motor_keys <- c("hov", "motor", "motorroad", "maxspeed", "traffic_calming", "vehicle", "direction", "lanes", "lane_markings") |
44 | | - |
45 | | - nature_keys <- c("crop", "ele", "water", "intermittent", "plant", "leaf_type", "wetland", "water") |
46 | | - |
47 | | - power_keys <- c("cables", "frequency", "generator", "power", "voltage", "rotor") |
48 | | - |
| 93 | + |
| 94 | + motor_keys <- c( |
| 95 | + "hov", |
| 96 | + "motor", |
| 97 | + "motorroad", |
| 98 | + "maxspeed", |
| 99 | + "traffic_calming", |
| 100 | + "vehicle", |
| 101 | + "direction", |
| 102 | + "lanes", |
| 103 | + "lane_markings" |
| 104 | + ) |
| 105 | + |
| 106 | + nature_keys <- c( |
| 107 | + "crop", |
| 108 | + "ele", |
| 109 | + "water", |
| 110 | + "intermittent", |
| 111 | + "plant", |
| 112 | + "leaf_type", |
| 113 | + "wetland", |
| 114 | + "water" |
| 115 | + ) |
| 116 | + |
| 117 | + power_keys <- c( |
| 118 | + "cables", |
| 119 | + "frequency", |
| 120 | + "generator", |
| 121 | + "power", |
| 122 | + "voltage", |
| 123 | + "rotor" |
| 124 | + ) |
| 125 | + |
49 | 126 | qa_keys <- c("fixme", "note", "ref") |
50 | | - |
| 127 | + |
51 | 128 | references_keys <- c("mappillary", "wikidata", "wikipedia") |
52 | | - |
| 129 | + |
53 | 130 | religion_keys <- c("denomination", "religion", "place_of_worship") |
54 | | - |
55 | | - transport_keys <- c("electrified", "gauge", "light_rail", "NHS", "orientation", "park_ride", "railway", "route", "shoulder", "tunnel") |
56 | | - |
| 131 | + |
| 132 | + transport_keys <- c( |
| 133 | + "electrified", |
| 134 | + "gauge", |
| 135 | + "light_rail", |
| 136 | + "NHS", |
| 137 | + "orientation", |
| 138 | + "park_ride", |
| 139 | + "railway", |
| 140 | + "route", |
| 141 | + "shoulder", |
| 142 | + "tunnel" |
| 143 | + ) |
| 144 | + |
57 | 145 | df <- df |> |
58 | 146 | dplyr::mutate( |
59 | 147 | parent_key = dplyr::case_when( |
60 | 148 | key %in% accessibility_keys ~ "Accessibility", |
61 | 149 | stringr::str_detect(key, "wheelchair") ~ "Accessibility", |
62 | 150 | stringr::str_detect(key, paste(care_keys, collapse = "|")) ~ "Care", |
63 | | - stringr::str_detect(key, paste(contact_keys, collapse ="|")) ~ "Contact", |
| 151 | + stringr::str_detect(key, paste(contact_keys, collapse = "|")) ~ |
| 152 | + "Contact", |
64 | 153 | stringr::str_detect(key, "cycle|cyclability") ~ "Cycling", |
65 | 154 | stringr::str_detect(key, "heritage") ~ "Heritage", |
66 | 155 | key %in% motor_keys ~ "motor", |
67 | | - stringr::str_detect(key, "maxspeed|vehicle|direction|fuel|lanes|parking") ~ "Motor", |
| 156 | + stringr::str_detect( |
| 157 | + key, |
| 158 | + "maxspeed|vehicle|direction|fuel|lanes|parking" |
| 159 | + ) ~ |
| 160 | + "Motor", |
68 | 161 | stringr::str_detect(key, "foot|sidewalk|kerb") ~ "pedestrian", |
69 | 162 | stringr::str_detect(key, "tourism") ~ "tourism", |
70 | | - stringr::str_detect(key, "bus|naptan|public_transport|button_operated") ~ "Public transport", |
71 | | - stringr::str_detect(key, paste(religion_keys, collapse = "|")) ~ "Religion" |
| 163 | + stringr::str_detect( |
| 164 | + key, |
| 165 | + "bus|naptan|public_transport|button_operated" |
| 166 | + ) ~ |
| 167 | + "Public transport", |
| 168 | + stringr::str_detect(key, paste(religion_keys, collapse = "|")) ~ |
| 169 | + "Religion" |
72 | 170 | ), |
73 | 171 | top_key = dplyr::case_when( |
74 | 172 | stringr::str_detect(key, "addr") ~ "Addresses", |
75 | 173 | # Amenities |
76 | 174 | key %in% amenity_keys ~ "Amenities", |
77 | 175 | stringr::str_detect(key, "amenity|brand|diet|shop") ~ "Amenities", |
78 | | - parent_key %in% c("Care", "Contact", "Tourism", "Heritage", "Religion") ~ "Amenities", |
| 176 | + parent_key %in% |
| 177 | + c("Care", "Contact", "Tourism", "Heritage", "Religion") ~ |
| 178 | + "Amenities", |
79 | 179 | # Boundaries |
80 | 180 | key %in% boundaries_keys ~ "Boundaries", |
81 | 181 | # Buildings |
82 | | - stringr::str_detect(key, "roof|building|architect|window") ~ "Buildings", |
| 182 | + stringr::str_detect(key, "roof|building|architect|window") ~ |
| 183 | + "Buildings", |
83 | 184 | # Crossings |
84 | | - stringr::str_detect(key, "crossing|juntion|traffic_signals") ~ "Crossings", |
| 185 | + stringr::str_detect(key, "crossing|juntion|traffic_signals") ~ |
| 186 | + "Crossings", |
85 | 187 | # EDI |
86 | 188 | key %in% edi_keys ~ "EDI", |
87 | 189 | # External References |
88 | | - stringr::str_detect(key, paste(references_keys, collapse = "|")) ~ "External references", |
| 190 | + stringr::str_detect(key, paste(references_keys, collapse = "|")) ~ |
| 191 | + "External references", |
89 | 192 | # Leisure |
90 | 193 | key %in% leisure_keys ~ "Leisure", |
91 | 194 | # Names |
92 | | - stringr::str_detect(key, "name") & !stringr::str_detect(key, "housename") ~ "Names", |
93 | | - stringr::str_detect(key, "leisure|sport") & !stringr::str_detect(key, "transport") ~ "Leisure", |
| 195 | + stringr::str_detect(key, "name") & |
| 196 | + !stringr::str_detect(key, "housename") ~ |
| 197 | + "Names", |
| 198 | + stringr::str_detect(key, "leisure|sport") & |
| 199 | + !stringr::str_detect(key, "transport") ~ |
| 200 | + "Leisure", |
94 | 201 | # Natural resources |
95 | 202 | key %in% nature_keys ~ "Natural Resources", |
96 | | - stringr::str_starts(key, "natural|nature|water|river|tree|grass") ~ "Natural Resources", |
| 203 | + stringr::str_starts(key, "natural|nature|water|river|tree|grass") ~ |
| 204 | + "Natural Resources", |
97 | 205 | key %in% power_keys ~ "Power", |
98 | 206 | stringr::str_detect(key, paste(power_keys, collapse = "|")) ~ "Power", |
99 | 207 | # Quality Assurance |
100 | 208 | key %in% qa_keys ~ "Quality Assurance", |
101 | | - stringr::str_starts(key, "check_date|source|survey") ~ "Quality Assurance", |
102 | | - stringr::str_detect(key, paste(qa_keys, collapse = "|")) ~ "Quality Assurance", |
| 209 | + stringr::str_starts(key, "check_date|source|survey") ~ |
| 210 | + "Quality Assurance", |
| 211 | + stringr::str_detect(key, paste(qa_keys, collapse = "|")) ~ |
| 212 | + "Quality Assurance", |
103 | 213 | # Streets |
104 | 214 | key %in% highway_keys ~ "Streets", |
105 | 215 | stringr::str_detect(parent_key, "Cycling") ~ "Streets", |
106 | | - stringr::str_detect(key, "pedestrian|kerb|sidewalk|surface|tactile_paving") ~ "Streets", |
| 216 | + stringr::str_detect( |
| 217 | + key, |
| 218 | + "pedestrian|kerb|sidewalk|surface|tactile_paving" |
| 219 | + ) ~ |
| 220 | + "Streets", |
107 | 221 | # Transport |
108 | 222 | key %in% transport_keys ~ "Transport", |
109 | 223 | parent_key == "Public transport" ~ "Transport", |
110 | 224 | stringr::str_detect(parent_key, "Motor") ~ "Transport", |
111 | 225 | stringr::str_detect(key, "railway|traffic_|passenger") ~ "Transport" |
112 | 226 | ) |
113 | 227 | ) |
114 | | - |
| 228 | + |
115 | 229 | return(df) |
116 | 230 | } |
0 commit comments