Skip to content

Instantly share code, notes, and snippets.

@aoles
Created October 7, 2021 10:02
Show Gist options
  • Save aoles/2e83e3fbcc44f108f6b6f3e8b53da5cb to your computer and use it in GitHub Desktop.
Save aoles/2e83e3fbcc44f108f6b6f3e8b53da5cb to your computer and use it in GitHub Desktop.
Query taginfo for barrier access values unknown to ORS
library(jsonlite)
# retrieve all possible node access values which come up at least 10 times
url <- "https://taginfo.openstreetmap.org/api/4/key/values?key=%s&filter=nodes&sortname=count&sortorder=desc&qtype=value&format=json_pretty"
key <- "access"
res <- fromJSON(sprintf(url, key))
df <- res[["data"]]
# filter out combined and rare values
values <- df$value[df$count >= 10]
values <- values[!grepl(";", values)]
# filter out values already taken into account by the car flag encoder
restricted_values <- c("agricultural", "forestry", "no", "restricted", "delivery", "military", "emergency", "private")
intended_values <- c("yes", "destination", "permissive")
known_values <- c(restricted_values, intended_values)
unknown_values <- values[-which(values %in% known_values)]
# query for nodes tagged as barrier which have an access value not known to ORS
other_key <- "barrier"
url <- "https://taginfo.openstreetmap.org/api/4/tag/combinations?key=%s&value=%s&page=1&rp=10&sortname=together_count&sortorder=desc&query=%s"
potential_barriers <- c("gate", "lift_gate", "kissing_gate", "swing_gate", "cattle_grid", "chain")
default_access_barriers <- sapply(unknown_values, function(value) {
res2 <- try(fromJSON(sprintf(url, key, value, other_key)), silent = TRUE)
if ( inherits(res2, "try-error") ) {
0
} else {
df <- res2$data
indices <- which(df$other_value %in% c("", potential_barriers))
sum(df$together_count[indices])
}
})
default_access_barriers <- default_access_barriers[which(default_access_barriers > 0)]
data.frame(default_access_barriers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment