Skip to content

Commit

Permalink
feat: area()
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajic committed Oct 26, 2024
1 parent 0b426a9 commit 7c6fb21
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Collate:
'methods-IDs.R'
'methods-XY.R'
'methods-affine.R'
'methods-area.R'
'methods-centroids.R'
'methods-coerce.R'
'methods-convHull.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ exportMethods(XY)
exportMethods(activeFeatType)
exportMethods(activeSpatUnit)
exportMethods(affine)
exportMethods(area)
exportMethods(as.character)
exportMethods(as.list)
exportMethods(as.matrix)
Expand Down
3 changes: 2 additions & 1 deletion R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ setGeneric(
function(x, ...) standardGeneric("overlapToMatrix")
)

# Methods and documentations found in methods-spatShift.R

setGeneric("spatShift", function(x, ...) standardGeneric("spatShift"))
setGeneric("affine", function(x, y, ...) standardGeneric("affine"))
setGeneric("shear", function(x, ...) standardGeneric("shear"))
setGeneric("XY", function(x, ...) standardGeneric("XY"))
setGeneric("XY<-", function(x, ..., value) standardGeneric("XY<-"))
setGeneric("area", function(x, ...) standardGeneric("area"))

# Methods and documentations found in methods-overlaps.R
setGeneric("overlaps", function(x, ...) standardGeneric("overlaps"))
Expand Down
36 changes: 36 additions & 0 deletions R/methods-area.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# docs ----------------------------------------------------------- #
#' @title Get the area of individual polygons
#' @name area
#' @description Compute the area covered by polygons
#' @param x `giottoPolygon`
#' @param ... additional args to pass
#' @returns `numeric` vector of spatial area
#' @examples
#' sl <- GiottoData::loadSubObjectMini("spatLocsObj")
#' gpoly <- GiottoData::loadSubObjectMini("giottoPolygon")
#' gpoints <- GiottoData::loadSubObjectMini("giottoPoints")
#'
#' # area of polygons
#' area(gpoly)
#'
#' # area of the convex hull
#' area(convHull(sl))
#' feature_hulls <- convHull(gpoints, by = "feat_ID")
#' area(feature_hulls)
#'
NULL
# ---------------------------------------------------------------- #

#' @rdname area
#' @export
setMethod("area", signature("giottoPolygon"), function(x, ...) {
# handle warning about missing CRS
handle_warnings(area(x[], ...))$result
})

#' @rdname area
#' @export
setMethod("area", signature("SpatVector"), function(x, ...) {
# handle warning about missing CRS
handle_warnings(terra::expanse(x, transform = FALSE, ...))$result
})
37 changes: 37 additions & 0 deletions man/area.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7c6fb21

Please sign in to comment.