50% off | Unlimited Data & AI Learning

Last chance! 50% off unlimited learning

Sale ends in


sugarbag (version 0.1.3)

allocate: Allocate polygon centroids to hexagons in a grid

Description

Chooses a hexagon centroid for each polygon in the shape file, from a grid spanning the longitudes and latitudes in the expanded bounding box.

Usage

allocate(
  centroids,
  hex_grid,
  sf_id = names(centroids)[1],
  hex_size,
  hex_filter,
  focal_points = NULL,
  order_sf_id = NULL,
  width = 30,
  verbose
)

Arguments

centroids

a data frame with centroids of non empty polygons

hex_grid

a data frame containing all possible hexagon points

sf_id

a string to indicate the column to identify individual polygons

hex_size

a float value in degrees for the diameter of the hexagons

hex_filter

amount of hexagons around centroid to consider

focal_points

a data frame of reference locations when allocating hexagons, capital cities of Australia are used in the example

order_sf_id

a string to indicate the column used to order polygons

width

a numeric indicating the angle used to filter the hexagon grid

verbose

a boolean to indicate whether to show polygon id

Value

a data frame of all allocated hexagon points

Examples

Run this code
# NOT RUN {
# Create centroids set
centroids <- create_centroids(tas_lga, sf_id = "LGA_CODE16")
# Create hexagon location grid
data(capital_cities)
grid <- create_grid(centroids = centroids, hex_size = 0.2, buffer_dist = 1.2)
# Allocate polygon centroids to hexagon grid points
hex_allocated <- allocate(
  centroids = centroids,
  hex_grid = grid,
  hex_size = 0.2, # same size used in create_grid
  hex_filter = 10,
  focal_points = capital_cities,
  width = 30, verbose = TRUE
)
# same column used in create_centroids
# create a set of hexagon points for plotting
fort_hex <- fortify_hexagon(data = hex_allocated, sf_id = "LGA_CODE16", hex_size = 0.2)
# plot the hexagons
# }

Run the code above in your browser using DataLab