addInnerBorder.Rd
These methods allow the addition of an inner border to spatial annotations, creating holes.
addInnerBorder(object, ...)
# S4 method for class 'SPATA2'
addInnerBorder(object, id, border_df, new_id = FALSE, overwrite = FALSE, ...)
# S4 method for class 'SpatialAnnotation'
addInnerBorder(object, border_df, ...)
An object of class SPATA2
or, in case of S4 generics,
objects of classes for which a method has been defined.
Used to absorb deprecated arguments or functions.
Character value. The ID of the spatial annotation to which the hole is added.
A data.frame that contains the x- and y- positions of the vertices of the polygon that corresponds to the borders of the whole. See details for input requirements.
If character value, stores the resulting spatial annotatiton under the specified ID.
Logical value. Must be TRUE
to allow overwriting.
The updated input object, containing the added, removed or computed results.
If used on a SpatialAnnotation
directly, the variables of border_df
should
be called x_orig and y_orig and should be scaled correspondingly. If
used with the SPATA2
object, the variables can be called x and y, too.
In that case, the function assumes that the coordinates are scaled to the
image that is currently active and creates x_orig and y_orig accordingly.
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"))