Skip to contents

This function will allocate tiles to their original geometries. This currently requires a 1:1 mapping of geometries to their tiles.

Usage

tile_allocate(object, tile)

Arguments

object

An sf object or geometry that was used to be tiled.

tile

An sf object produced with the hex_grid() function.

Value

An sf dataset of hexagon geometries with their original data.

Examples

library(ozmaps)
library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
australia <- abs_ste %>% filter(NAME != "Other Territories")
grid <- hex_grid(australia, n_tiles = 8)
#> Warning: attribute variables are assumed to be spatially constant throughout all geometries
grid <- tile_allocate(australia, grid)
#> Error in st_geometry(object) <- tile[tile_match]: could not find function "st_geometry<-"

library(ggplot2)
ggplot() +
  geom_sf(data = australia) +
  geom_sf(data = grid, aes(fill = NAME), alpha = 0.2)
#> Error in FUN(X[[i]], ...): object 'NAME' not found