Skip to contents

Make a png file of Google traffic data. The gt_load_png_as_traffic_raster() function can then be used to convert the png into a traffic raster

Usage

gt_make_png(
  location,
  height,
  width,
  zoom,
  out_filename,
  google_key,
  webshot_zoom = 1,
  webshot_delay = NULL,
  print_progress = TRUE
)

Arguments

location

Vector of latitude and longitude

height

Height (in pixels; pixel length depends on zoom)

width

Width (in pixels; pixel length depends on zoom)

zoom

Zoom level; integer from 5 to 20. For more information about how zoom levels correspond to pixel size, see here and here.

out_filename

Filename of PNG file to make

google_key

Google API key, where the Maps JavaScript API is enabled. To create a Google API key, follow these instructions.

webshot_zoom

How many pixels should be created relative to height and width values. If height and width are set to 100 and webshot_zoom is set to 2, the resulting raster will have dimensions of about 200x200 (default: 1).

webshot_delay

How long to wait for Google traffic layer to render. Larger height/widths require longer delay times. If NULL, the following delay time (in seconds) is used: delay = max(height,width)/200.

print_progress

Whether to print function progress (default: TRUE)

Value

Returns a PNG file showing traffic levels.

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