Skip to contents

Creates a grid of sf polygons, where traffic data for each polygon can then be queried using gt_make_raster_from_grid().

Usage

gt_make_grid(
  polygon,
  zoom,
  height_width_max = 2000,
  height = NULL,
  width = NULL,
  reduce_hw = 10
)

Arguments

polygon

Polygon (sf object or SpatialPolygonsDataframe) in WGS84 CRS the defines region to be queried.

zoom

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

height_width_max

Maximum pixel height and width to check using for each grid (pixel length depends on zoom). If the same number of grids can be made with a smaller height/width, the function will use a smaller height/width. If height and width are specified, that height and width will be used and height_width_max will be ignored. (Default: 2000)

height

Height, in pixels, for each grid (pixel length depends on zoom). Enter a height to manually specify the height; otherwise, a height of height_width_max or smaller will be used.

width

Pixel, in pixels, for each grid (pixel length depends on zoom). Enter a width to manually specify the width; otherwise, a width of height_width_max or smaller will be used.

reduce_hw

Number of pixels to reduce height/width by. Doing so creates some overlap between grids to ensure there is not blank space between grids. (Default: 10).

Value

Returns an sf dataframe with the locations to query, including parameters needed for gt_make_raster_from_grid()

Examples

## Make polygon
poly_sf <- c(xmin = -74.02426,
             xmax = -73.91048,
             ymin = 40.70042,
             ymax = 40.87858) |>
  sf::st_bbox() |>
  sf::st_as_sfc() |>
  sf::st_as_sf()

sf::st_crs(poly_sf) <- 4326

## Make grid using polygon
grid_sf <- gt_make_grid(polygon = poly_sf,
                        height  = 2000,
                        width   = 2000,
                        zoom    = 16)
#> Warning: "height_width_max" ignored; if "height", "width", and "height_width_max" are all specified, "height_width_max" will be ignored.
#> Warning: st_centroid assumes attributes are constant over geometries of x