From https://observablehq.com/@jwolondon/gridmap-allocation. Returns an LP solution allocating 2D points to a grid.
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).
Examples
library(sf)
library(dplyr)
pts <- london_boroughs |> st_drop_geometry() |> select(area_name, x = easting, y = northing)
grd <- grid_locations(n_row = 8, n_col = 8, spacers = list())
grd_pos <- solve_lp(points_normalised(pts, grd, 0.6), grd, 0.6)
grd_pos
#> grd pt
#> 1 37 1
#> 2 47 2
#> 3 51 3
#> 4 31 4
#> 5 43 5
#> 6 14 6
#> 7 35 7
#> 8 13 8
#> 9 34 9
#> 10 61 10
#> 11 30 11
#> 12 45 12
#> 13 27 13
#> 14 52 14
#> 15 42 15
#> 16 48 16
#> 17 33 17
#> 18 26 18
#> 19 44 19
#> 20 28 20
#> 21 11 21
#> 22 21 22
#> 23 22 23
#> 24 12 24
#> 25 46 25
#> 26 54 26
#> 27 19 27
#> 28 29 28
#> 29 4 29
#> 30 38 30
#> 31 53 31
#> 32 20 32
#> 33 36 33