Skip to contents

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

Usage

points_normalised(pts, grd, compactness)

Arguments

pts

tibble of geographic points (x,y) to be transformed for allocation to grid.

grd

tibble defining grid positions.

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).

Value

A tibble of transformed grid coordinates

Examples

library(tibble)
pts <- tribble(
  ~x, ~y,
  2, 4,
  1, 5,
  2, 1,
  3, 3,
  3, 4
)
grd <- grid_locations(n_row = 3, n_col = 3, spacers = list())
points_normalised(pts, grd, .6)
#> # A tibble: 5 × 2
#>       x     y
#>   <dbl> <dbl>
#> 1 2     2.75 
#> 2 0.504 3.50 
#> 3 2     0.504
#> 4 3.50  2    
#> 5 3.50  2.75