View source: R/assign_polygons.R
assign_polygons | R Documentation |
Assigns each polygon in the original file to a new location in the gridded geometry using the Hungarian algorithm.
assign_polygons(shape, new_polygons)
## S3 method for class 'SpatialPolygonsDataFrame'
assign_polygons(shape, new_polygons)
## S3 method for class 'sf'
assign_polygons(shape, new_polygons)
shape |
A "SpatialPolygonsDataFrame" or an sf object representing the original spatial polygons. |
new_polygons |
A "geogrid" object returned from
|
An object of the same class as shape
library(sf)
input_file <- system.file("extdata", "london_LA.json", package = "geogrid")
original_shapes <- st_read(input_file) %>% st_set_crs(27700)
# calculate grid
new_cells <- calculate_grid(shape = original_shapes,
grid_type = "hexagonal", seed = 1)
grid_shapes <- assign_polygons(original_shapes, new_cells)
plot(grid_shapes)
par(mfrow = c(1, 2))
plot(st_geometry(original_shapes))
plot(st_geometry(grid_shapes))
## Not run:
# look at different grids using different seeds
par(mfrow=c(2, 3), mar = c(0, 0, 2, 0))
for (i in 1:6) {
new_cells <- calculate_grid(shape = original_shapes,
grid_type = "hexagonal", seed = i)
plot(new_cells, main = paste("Seed", i, sep=" "))
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.