tangles {tangles} | R Documentation |
Anonymise spatial point patterns and raster objects
Description
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.
Usage
tangles(data = NULL, depth = 3, rasterdata = FALSE, raster_object = FALSE,
saveTangles = FALSE, exportShapefile = FALSE, path = NULL)
Arguments
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 |
Value
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
ortangledXY_raster_<hash>.rds
— the transformed data -
detangler_<hash>.rds
— the metadata required for reverse transformation Optional: shapefile output if
exportShapefile = TRUE
Note
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.
Author(s)
Brendan Malone
References
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. doi:10.4225/08/59c169433efd4
Examples
## 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)