Adds spatial annotations using polygon data.frames.

addSpatialAnnotation(object, ...)

# S4 method for class 'SPATA2'
addSpatialAnnotation(
  object,
  tags,
  area,
  id = NULL,
  overwrite = FALSE,
  class = "SpatialAnnotation",
  ...
)

# S4 method for class 'SpatialData'
addSpatialAnnotation(
  object,
  tags,
  area,
  id = NULL,
  overwrite = FALSE,
  class = "SpatialAnnotation",
  ...
)

Arguments

object

An object of class SPATA2 or, in case of S4 generics, objects of classes for which a method has been defined.

...

Additional slot content given to methods::new() when constructing the SpatialAnnotation object.

tags

A character vector of tags for the spatial annotation.

area

A named list of data.frames with the numeric variables x and y or x_orig and y_orig. Observations correspond to the vertices of the polygons that are needed to represent the spatial annotation. Must contain exactly one slot named outer which sets the outer border of the spatial annotation. Can contain multiple slots named inner (suffixed) with numbers that correspond to inner polygons - holes within the annotation.

id

Character value. The ID of the spatial annotation. If NULL, the ID of the annotation is created by combining the string 'spat_ann' with the index the new annotation has in the list of all annotations.

overwrite

Logical value. Must be TRUE to allow overwriting.

Value

The updated input object, containing the added, removed or computed results.

See also

Examples


library(SPATA2)
library(tidyverse)

data("example_data")

object <- example_data$object_UKF275T_diet

create_circle_polygon <- function(p, r, n) {

 angles <- seq(0, 2 * pi, length.out = n + 1)

 x_coords <- p[1] + r * cos(angles)
 y_coords <- p[2] + r * sin(angles)

 polygon_df <- tibble::tibble(x = x_coords, y = y_coords)

 return(polygon_df)

}

center <-
 getCoordsDf(object)[c("x", "y")] %>%
 map_dbl(.f = mean)

area_circle <- create_circle_polygon(center, r = 75, n = 100)

print(area_circle)

object <- addSpatialAnnotation(object, area = list(outer = area_circle), id = "circle")

plotSpatialAnnotations(object, ids = "circle")

hole <- create_circle_polygon(center, r = 25, n = 100)

object <- addInnerBorder(object, id = "circle", border_df = hole, new_id = "circle_with_hole")

plotSpatialAnnotations(object, ids = c("circle", "circle_with_hole"))