Appendix G — Comparative Assessment of QualoCEP and Google Geocoding API Performance

G.1 Overview

This is a simple workflow to test the QualoCEP geocoding against Google Geocoding API.

This thesis uses both services for geocoding the data. QualoCEP is a paid service that provides a large dataset of Brazillian postal codes and addresses. The aim is to compare the results of QualoCEP’s latitute e longitude values with Google’s results for consistency.

To run this notebook you will need to have a Google Geocoding API key in your .Renviron file. Learn more about it here.

G.2 Setting the enviroment

Code
source(here::here("R", "get_brazil_fu.R"))
source(here::here("R", "get_qualocep_data.R"))
source(here::here("R", "render_brazil_address.R"))
source(here::here("R", "utils.R"))

G.3 Importing QualOCep data

Code
qualocep_data <- get_qualocep_data()

G.4 Random test 1

G.4.1 QualOCep data

Code
sample_data <- dplyr::sample_n(qualocep_data, 1)

sample_data |> as.list() |> list_as_tibble()
Code
leaflet::leaflet() |> 
  leaflet::addTiles() |> 
  leaflet::addMarkers(
    lng = sample_data$longitude,
    lat = sample_data$latitude,
    popup = paste0(
      "Latitude: ", sample_data$latitude, "<br>",
      "Longitude: ", sample_data$longitude
    )
  )

G.4.2 Google Geocoding API

Code
google_data <- 
  sample_data |>
  dplyr::mutate(
    address = render_brazil_address(
      street = sample_data$street,
      complement = sample_data$complement,
      neighborhood = sample_data$neighborhood,
      municipality = sample_data$municipality,
      state = sample_data$state,
      postal_code = sample_data$postal_code
    )
  ) |>
  tidygeocoder::geocode(
    address = address,
    method = "google"
  )
#> Passing 1 address to the Google single address geocoder
#> Query completed in: 0.7 seconds

google_data |> as.list() |> list_as_tibble()
Code
leaflet::leaflet() |> 
  leaflet::addTiles() |> 
  leaflet::addMarkers(
    lng = google_data$longitude,
    lat = google_data$latitude,
    popup = paste0(
      "Latitude: ", google_data$latitude, "<br>",
      "Longitude: ", google_data$longitude
    )
  )

G.5 Random test 2

G.5.1 QualOCep data

Code
sample_data <- dplyr::sample_n(qualocep_data, 1)

sample_data |> as.list() |> list_as_tibble()
Code
leaflet::leaflet() |> 
  leaflet::addTiles() |> 
  leaflet::addMarkers(
    lng = sample_data$longitude,
    lat = sample_data$latitude,
    popup = paste0(
      "Latitude: ", sample_data$latitude, "<br>",
      "Longitude: ", sample_data$longitude
    )
  )

G.5.2 Google Geocoding API

Code
google_data <- 
  sample_data |>
  dplyr::mutate(
    address = render_brazil_address(
      street = sample_data$street,
      complement = sample_data$complement,
      neighborhood = sample_data$neighborhood,
      municipality = sample_data$municipality,
      state = sample_data$state,
      postal_code = sample_data$postal_code
    )
  ) |>
  tidygeocoder::geocode(
    address = address,
    method = "google"
  )
#> Passing 1 address to the Google single address geocoder
#> Query completed in: 0.4 seconds

google_data |> as.list() |> list_as_tibble()
Code
leaflet::leaflet() |> 
  leaflet::addTiles() |> 
  leaflet::addMarkers(
    lng = google_data$longitude,
    lat = google_data$latitude,
    popup = paste0(
      "Latitude: ", google_data$latitude, "<br>",
      "Longitude: ", google_data$longitude
    )
  )

G.6 Random test 3

G.6.1 QualOCep data

Code
sample_data <- dplyr::sample_n(qualocep_data, 1)

sample_data |> as.list() |> list_as_tibble()
Code
leaflet::leaflet() |> 
  leaflet::addTiles() |> 
  leaflet::addMarkers(
    lng = sample_data$longitude,
    lat = sample_data$latitude,
    popup = paste0(
      "Latitude: ", sample_data$latitude, "<br>",
      "Longitude: ", sample_data$longitude
    )
  )

G.6.2 Google Geocoding API

Code
google_data <- 
  sample_data |>
  dplyr::mutate(
    address = render_brazil_address(
      street = sample_data$street,
      complement = sample_data$complement,
      neighborhood = sample_data$neighborhood,
      municipality = sample_data$municipality,
      state = sample_data$state,
      postal_code = sample_data$postal_code
    )
  ) |>
  tidygeocoder::geocode(
    address = address,
    method = "google"
  )
#> Passing 1 address to the Google single address geocoder
#> Query completed in: 0.3 seconds

google_data |> as.list() |> list_as_tibble()
Code
leaflet::leaflet() |> 
  leaflet::addTiles() |> 
  leaflet::addMarkers(
    lng = google_data$longitude,
    lat = google_data$latitude,
    popup = paste0(
      "Latitude: ", google_data$latitude, "<br>",
      "Longitude: ", google_data$longitude
    )
  )