Skip to content

Commit

Permalink
enh: coerce from giottoLargeImage to giottoImage
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajic committed May 3, 2024
1 parent 03df20e commit 710340a
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions R/methods-coerce.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ NULL
#' @returns data.table
#' @examples
#' g <- GiottoData::loadSubObjectMini("giottoPolygon")
#'
#'
#' data.table::as.data.table(g)
NULL

Expand All @@ -33,7 +33,7 @@ NULL
#' @family As coercion functions
#' @examples
#' g <- GiottoData::loadSubObjectMini("giottoPolygon")
#'
#'
#' as.polygons(slot(g, "spatVector"))
NULL

Expand All @@ -47,7 +47,7 @@ NULL
#' @family As coercion functions
#' @examples
#' g <- GiottoData::loadSubObjectMini("giottoPoints")
#'
#'
#' as.points(slot(g, "spatVector"))
NULL

Expand All @@ -62,7 +62,7 @@ NULL
#' @family As coercion functions
#' @examples
#' g <- GiottoData::loadSubObjectMini("giottoPoints")
#'
#'
#' as.sf(g)
NULL

Expand Down Expand Up @@ -104,6 +104,41 @@ as.data.table.giottoPoints <- function(x, ...) {
}




# image types ####

methods::setAs("giottoLargeImage", "giottoImage", function(from) {
mgobj <- .spatraster_sample_values(
raster_object = from,
size = getOption("giotto.plot_img_max_crop", 1e8),
output = "magick",
verbose = TRUE
)

# Create giottoImage
mImg <- createGiottoImage(
name = objName(from),
mg_object = mgobj,
verbose = FALSE
)

ext(mImg) <- ext(from)

# # Set scalefactor
im_dims <- magick::image_info(mImg@mg_object)
x_scalefactor <- im_dims[["width"]] / dim(from)[2]
y_scalefactor <- im_dims[["height"]] / dim(from)[1]

mImg@scale_factor <- c("x" = x_scalefactor, "y" = y_scalefactor)
mImg@resolution <- 1 / mImg@scale_factor

return(mImg)
})




# to SpatVector ####
# TODO
# as.points
Expand Down

0 comments on commit 710340a

Please sign in to comment.