This document should be considered draft until it is thoroughly verified. It may include substantial inaccuracies.
As of 2017-07-24:
Original OpenStreetMaps data repeated some data points multiple times. See this overlay on Google Maps to get an idea. Data points with very similar coordinates (same coordinates until the first decimal) have been removed.
Some streets may be missing: they may not be included in OpenStreetMaps, or I may have filtered them out my mistake. The data do not show any self-evident bias, but this does not mean they are correct.
Mechanically querying Google Maps for each town in the region may offer more accurate results.
Other ideas are welcome. Feel free to open an issue on the repository hosting this file https://github.com/giocomai/TitoOnTheMap/issues, or to get in touch via Twitter.
Update 2017-07-27: as anticipated, the verification of this map is progress (see this map for partial updates). The figures presented below are inaccurate, as they substantially underestimate the total number of streets dedicated to Tito, at least is some areas. This document will be updated.
Install Osmconvert and Osmfilter
# osmosis not needed? (Osmosis)[http://wiki.openstreetmap.org/wiki/Osmosis/Installation]
# following code works on linux, for other OS see:
# http://wiki.openstreetmap.org/wiki/Osmosis/Installation
dir.create(path = "osmosis", showWarnings = FALSE)
if (file.exists(file.path("osmosis", "osmosis-latest.tgz"))==FALSE) {
download.file(url = "http://bretth.dev.openstreetmap.org/osmosis-build/osmosis-latest.tgz", destfile = file.path("osmosis", "osmosis-latest.tgz"))
untar(tarfile = file.path("osmosis", "osmosis-latest.tgz"), exdir = "osmosis")
system(command = "chmod a+x osmosis/bin/osmosis")
}
# install osmfilter
if (file.exists("osmfilter")==FALSE) {
system(command = "wget -O - http://m.m.i24.cc/osmfilter.c |cc -x c - -O3 -o osmfilter")
}
# install osmconvert
if (file.exists(file.path("osmconvert64"))==FALSE) {
download.file(url = "http://m.m.i24.cc/osmconvert64", destfile = file.path("osmconvert64"))
system(command = "chmod +x osmconvert64")
}
Download all data for selected countries from available repositories.
dir.create(path = "data", showWarnings = FALSE)
dir.create(path = file.path("data", "pbf"), showWarnings = FALSE)
countries <- c("slovenia", "croatia", "bosnia-herzegovina", "serbia", "montenegro", "kosovo", "macedonia")
for (i in countries) {
if (file.exists(file.path("data", "pbf", paste0(i, "-latest.osm.pbf")))==FALSE) {
download.file(url = paste0("http://download.geofabrik.de/europe/", i, "-latest.osm.pbf"), destfile = file.path("data", "pbf", paste0(i, "-latest.osm.pbf")))
}
}
Filter only street names, and export them as CSV. (if anyone’s familiar with OSM, this is the place to check)
# convert to a format that can be read by osmfilter, and remove author data to reduce file size
dir.create(path = file.path("data", "o5m"), showWarnings = FALSE)
for (i in countries) {
if (file.exists(file.path("data", "o5m", paste0(i, "-latest.o5m")))==FALSE) {
system(paste0('./osmconvert64 data/pbf/', i, '-latest.osm.pbf --drop-version --out-o5m -o=data/o5m/', i, '-latest.o5m'))
}
}
# filter only streets
dir.create(path = file.path("data", "o5m-streets"), showWarnings = FALSE)
for (i in countries) {
if (file.exists(file.path("data", "o5m-streets", paste0(i, "-streets.o5m")))==FALSE) {
system(paste0('./osmfilter data/o5m/', i, '-latest.o5m --keep="highway=*" --drop-version > ', 'data/o5m-streets/', i, '-streets.o5m'))
}
}
# export to csv only street type, name, and lon/lat
dir.create(path = file.path("data", "csv-streets"), showWarnings = FALSE)
for (i in countries) {
if (file.exists(file.path("data", "csv-streets", paste0(i, "-streets.csv")))==FALSE) {
system(paste0('./osmconvert64 data/o5m-streets/', i, '-streets.o5m --all-to-nodes --csv="@id @lat @lon highway name" > data/csv-streets/', i, '-streets.csv', " --csv-separator='; '"))
}
}
Criteria for filters:
StreetsSummary <- data_frame(Country = countries, TotalStreets = as.integer(NA), TitoStreets = as.integer(NA))
FindTito <- "Tito$|Tita$|Titov|Титов|Тито"
tito_all <- data_frame()
for (i in countries) {
# Import from csv
temp_streets <- read_delim(file = file.path("data", "csv-streets", paste0(i, "-streets.csv")), delim = "; ", col_names = FALSE, locale = locale(decimal_mark = "."), trim_ws = TRUE)
# Store total number of streets for each country
StreetsSummary$TotalStreets[StreetsSummary$Country==i] <- nrow(temp_streets)
# Filter only Tito's streets
temp_tito <- temp_streets %>%
filter(is.na(X5)==FALSE) %>%
filter(stringr::str_detect(string = X5, pattern = stringr::regex(pattern = FindTito, ignore_case = TRUE))) %>%
transmute(lat = X2, lon = X3, streetname = X5) %>%
# remove duplicate location with which have similar coordinates (same first decimal)
mutate(lonShort = format(lon, digit = 3), latShort = format(lat, digit = 3)) %>%
distinct(lonShort, latShort, .keep_all = TRUE) %>%
select(-lonShort, -latShort) %>%
mutate(country = i)
# Store number of Tito's streets in given country
StreetsSummary$TitoStreets[StreetsSummary$Country==i] <- nrow(temp_tito)
# Merge table for each country
tito_all <- bind_rows(tito_all, temp_tito)
}
# tito_all <- tito_all %>%
# mutate(lonShort = format(lon, digit = 4), latShort = format(lat, digit = 4)) %>%
# distinct(lonShort, latShort, .keep_all = TRUE) %>%
# select(-lonShort, -latShort)
write_csv(x = tito_all %>% distinct(), path = "tito_coordinates.csv")
StreetsSummary %>%
arrange(TitoStreets) %>%
mutate(Country = toupper(Country)) %>%
mutate(Country = forcats::fct_inorder(Country)) %>%
ggplot(aes(x = Country, y = TitoStreets, label = TitoStreets)) +
geom_col() +
scale_y_continuous(name = "", limits = c(0, 30)) +
scale_x_discrete(name = "") +
geom_text(hjust = -0.1) +
coord_flip() +
theme_minimal() +
labs(title = "Number of streets dedicated to Tito", subtitle = paste("(based on OpenStreetMaps data as of", Sys.Date(), ")"))
# Setting the coordinates
wb <- c(left = 12, bottom = 40, right = 26, top = 48)
# Preparing the canvas
mapTonerLite <- get_stamenmap(bbox = wb, zoom = 6, maptype = "toner-lite") %>% ggmap()
mapTonerLite + geom_point(data=tito_all, aes(x=lon, y=lat), color="red", size=2, alpha=0.5) +
labs(x = '', y = '') + labs(title = "Streets and squares dedicated to Tito", subtitle = paste("(based on OpenStreetMaps data as of", Sys.Date(), ")"))
ggsave("TitoTonerLight.png")
# Preparing the canvas
mapG <- get_googlemap("Sarajevo", scale = 2, zoom = 6) %>% ggmap()
mapG + geom_point(data=tito_all, aes(x=lon, y=lat), color="red", size=2, alpha=0.5) +
labs(x = '', y = '') + labs(title = "Streets and squares dedicated to Tito", subtitle = paste("(based on OpenStreetMaps data as of", Sys.Date(), ")"))
ggsave("TitoGmaps.png")
# # Preparing the canvas
# mapWatercolor <- get_stamenmap(bbox = wb, zoom = 7, maptype = "watercolor") %>% ggmap()
# # Adding the dots
# mapWatercolor + geom_point(data=tito_all, aes(x=lon, y=lat), color="red", size=2, alpha=0.5) +
# labs(x = '', y = '') + ggtitle("Streets dedicated to Tito")
# ggsave("TitoWatercolor.png")
N.B. Check if something is missing and update criteria
knitr::kable(tito_all %>% select(country, streetname) %>% group_by(country, streetname) %>% count() %>% arrange(country, desc(n), streetname))
country | streetname | n |
---|---|---|
bosnia-herzegovina | Maršala Tita | 11 |
bosnia-herzegovina | Titova | 4 |
bosnia-herzegovina | Titova ili Put Oficirske Škole | 1 |
bosnia-herzegovina | Trg maršala Tita | 1 |
bosnia-herzegovina | Ul Maršala Tita | 1 |
bosnia-herzegovina | ul. Maršala Tita | 1 |
croatia | Maršala Tita | 6 |
croatia | Ulica Maršala Tita | 4 |
croatia | Obala Maršala Tita | 2 |
croatia | Titov trg | 2 |
croatia | Hodaliste marsala tita | 1 |
croatia | Josipa Broza Tita | 1 |
croatia | Obala Josipa Broza Tita | 1 |
croatia | Obala m. Tita | 1 |
croatia | Poljana maršala Tita | 1 |
croatia | Trg J. B. Tita | 1 |
croatia | Trg maršala Tita | 1 |
croatia | Trg Maršala Tita | 1 |
croatia | Ulica Josipa Broza Tita | 1 |
croatia | Ulica Josipa Broza-Tita | 1 |
macedonia | Маршал Тито | 14 |
macedonia | bul. Marsal Tito | 1 |
macedonia | Marsal Tito | 1 |
macedonia | Marshal Tito | 1 |
macedonia | ul. Marshal Tito | 1 |
macedonia | Кеј Маршал Тито | 1 |
macedonia | Титова Митровачка | 1 |
macedonia | Титовелешка | 1 |
macedonia | Титово Ужице | 1 |
macedonia | ул. Маршал Тито | 1 |
macedonia | Улица Маршал Тито | 1 |
montenegro | Marsala Tita | 2 |
montenegro | Gjergj Kastrioti - Skënderbeu / Maršal Tito | 1 |
montenegro | Josipa Broza Tita | 1 |
montenegro | Maršala Tita | 1 |
montenegro | Titove Korenice | 1 |
montenegro | trg Maršala Tita | 1 |
serbia | Maršala Tita | 5 |
serbia | Титоградска | 4 |
serbia | Aleja Maršala Tita | 1 |
serbia | Marsala Tita | 1 |
serbia | Ulica Marsala Tita | 1 |
serbia | Ктитор | 1 |
serbia | Тито Маршал | 1 |
serbia | Титова | 1 |
slovenia | Titova ulica | 3 |
slovenia | Cesta maršala Tita | 2 |
slovenia | Titova cesta | 2 |
slovenia | Trg maršala Tita | 2 |
slovenia | Titov most | 1 |
slovenia | Titov trg | 1 |
slovenia | Titov trg / Piazza Tito | 1 |
slovenia | Titova - Nasipna | 1 |
slovenia | Ulica Josipa Broza-Tita | 1 |
write_csv(x = tito_all %>% select(country, streetname) %>% group_by(country, streetname) %>% count() %>% arrange(country, desc(n), streetname), path = "tito_streetnames.csv")