Skip to contents

Converts PNG of Google traffic data to raster and translates color values to traffic values

Usage

gt_load_png_as_traffic_raster(
  filename,
  location,
  height,
  width,
  zoom,
  traffic_color_dist_thresh = 4.6,
  traffic_color_dist_metric = "CIEDE2000"
)

Arguments

filename

Filename of PNG file

location

Vector of latitude and longitude used to create PNG file using gt_make_png()

height

Height (in pixels; pixel length depends on zoom) used to create PNG file using gt_make_png()

width

Width (in pixels; pixel length depends on zoom) used to create PNG file using gt_make_png()

zoom

Zoom level used to create PNG file using gt_make_png()

traffic_color_dist_thresh

Google traffic relies on four main base colors: #63D668 for no traffic, #FF974D for medium traffic, #F23C32 for high traffic, and #811F1F for heavy traffic. Slight variations of these colors can also represent traffic. By default, the base colors and all colors within a 4.6 color distance of each base color are used to define traffic; by default, the CIEDE2000 metric is used to determine color distance. A value of 2.3 is one threshold used to define a "just noticeable distance" (JND) between colors (by default, 2 X JND is used). This parameter changes the color distance from the base colors used to define colors as traffic. For more information, see here.

traffic_color_dist_metric

See above; this parameter changes the metric used to calculate distances between colors. By default, CIEDE2000 is used; CIE76 and CIE94 can also be used. For more information, see here.

Value

Returns a raster where each pixel represents traffic level (1 = no traffic, 2 = medium traffic, 3 = traffic delays, 4 = heavy traffic)

References

Markus Hilpert, Jenni A. Shearston, Jemaleddin Cole, Steven N. Chillrud, and Micaela E. Martinez. Acquisition and analysis of crowd-sourced traffic data. CoRR, abs/2105.12235, 2021.

Pavel Pokorny. Determining traffic levels in cities using google maps. In 2017 Fourth International Conference on Mathematics and Computers in Sciences and in Industry (MCSI), pages 144–147, 2017.

Examples

if (FALSE) {
## Make png
gt_make_png(location     = c(40.712778, -74.006111),
            height       = 1000,
            width        = 1000,
            zoom         = 16,
            out_filename = "google_traffic.png",
            google_key   = "GOOGLE-KEY-HERE")

## Load png as traffic raster
r <- gt_load_png_as_traffic_raster(filename = "google_traffic.png",
                                   location = c(40.712778, -74.006111),
                                   height   = 1000,
                                   width    = 1000,
                                   zoom     = 16)
}