Preliminary remarks

This document should be considered draft until it is thoroughly verified. It may include substantial inaccuracies.

Click here to see all streets and squares dedicated to Tito identified by this script as an overlay on Google Maps.

As of 2017-07-24:

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.

Getting OpenStreetMaps packages

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")
}

Getting the data from OpenStreetMaps

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='; '"))
  }
}

Keep only street names including reference to Tito, and presenting preliminary results

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")

Number of streets dedicated to Tito

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(), ")"))

Share of streets dedicated to Tito

options(scipen=999)
StreetsSummary %>%
  mutate(TitoShare = TitoStreets/TotalStreets) %>% 
  arrange(TitoShare) %>% 
  mutate(Country = toupper(Country)) %>% 
  mutate(Country = forcats::fct_inorder(Country)) %>% 
  ggplot(aes(x = Country, y = TitoShare, label = TitoShare)) +
  geom_col() +
  scale_y_continuous(name = "", labels = percent) +
  scale_x_discrete(name = "") +
  coord_flip() +
  theme_minimal() +
  labs(title = "Share of streets dedicated to Tito", subtitle = paste("(based on OpenStreetMaps data as of", Sys.Date(), ")"))

knitr::kable(StreetsSummary %>% arrange(desc(TitoStreets)))
Country TotalStreets TitoStreets
croatia 3862222 24
macedonia 737810 24
bosnia-herzegovina 2071858 19
serbia 2407281 15
slovenia 3213800 14
montenegro 713316 7
kosovo 666135 0

Mark on the map streets dedicated to Tito

# 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(), ")"))