Skip to contents

From https://observablehq.com/@jwolondon/gridmap-allocation. Returns an LP solution allocating 2D points to a grid.

Usage

points_to_grid(pts, n_row, n_col, compactness = 1, spacers = list())

Arguments

pts

tibble of geographic points (x,y) to be allocated to a grid.

n_row

maximum number of rows in grid.

n_col

maximum number of columns in grid.

compactness

Optional parameter between 0 and 1 where 0 allocates towards edges, 0.5 preserves scaled geographic location and 1 allocates towards centre of grid. Default is 1 (compact cluster).

spacers

Optional list of grid cell locations defining grid location of fixed spacers which cannot be allocated points. Coordinates are in (row, column) order with origin bottom-left. Default is an empty list.

Value

A tibble of matched point and grid locations.

Examples

library(tibble)
pts <- tribble(
  ~x, ~y,
  2, 4,
  1, 5,
  2, 1,
  3, 3,
  3, 4
)
points_to_grid(pts, n_row = 3, n_col = 3, spacers = list())