tangles | R Documentation |
Performs spatial anonymisation ("tangling") of coordinates through randomized transformation sequences, preserving relative spatial relationships while obscuring true locations. Three transformation types are used: X shift, Y shift, and rotation around a random origin. The sequence and parameters used for anonymisation are recorded and returned for later disentanglement.
tangles(data = NULL, depth = 3, rasterdata = FALSE, raster_object = FALSE,
saveTangles = FALSE, exportShapefile = FALSE, path = NULL)
data |
Either a two-column |
depth |
Integer. Number of transformation steps to apply (default is 3). |
rasterdata |
Logical. If |
raster_object |
Logical. Set |
saveTangles |
Logical. If |
exportShapefile |
Logical. If |
path |
Character. Path to directory where outputs will be saved. Defaults |
A list
with two elements:
The transformed coordinates (if point input) or a terra::SpatRaster
(if raster input)
A detangler
list containing the transformation log (unpicker
) and a unique hash
If saveTangles = TRUE
, the following files are written:
tangledXY_<hash>.rds
or tangledXY_raster_<hash>.rds
— the transformed data
detangler_<hash>.rds
— the metadata required for reverse transformation
Optional: shapefile output if exportShapefile = TRUE
For raster input, both rasterdata = TRUE
and raster_object = TRUE
are usually recommended. This ensures rotation steps align with raster grid expectations.
The detangler object is the critical output. It allows the same transformation sequence to be reversed or applied to related datasets.
Coordinate reference systems are intentionally ignored in this function. Anonymised outputs do not have spatial meaning, but retain topological properties of the input.
If writing shapefiles, no CRS is assigned and no .prj
file is written.
Brendan Malone
CM O’Keefe, S Otorepec, M Elliot, E Mackey, and K O’Hara (2017) The De-Identification Decision Making Framework. CSIRO Reports EP173122 and EP175702. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.4225/08/59c169433efd4")}
## Example 1: Using point data.frame
library(digest)
set.seed(1)
pts <- data.frame(X = runif(100), Y = runif(100))
res <- tangles(data = pts, depth = 4)
str(res)
## Example 2: Using sf object
library(sf)
sf_pts <- st_as_sf(pts, coords = c("X", "Y"))
res_sf <- tangles(data = sf_pts, depth = 3, exportShapefile = TRUE)
## Example 3: Using terra raster
library(terra)
ext_path <- system.file("extdata", package = "tangles")
rast.files <- list.files(path = ext_path, full.names = TRUE)
rasters <- terra::rast(rast.files)
res_r <- tangles(data = rasters, depth = 3, rasterdata = TRUE, raster_object = TRUE)
str(res_r)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.