From 372ac63b87f4b378ab34be3edc1cb26a25bbec49 Mon Sep 17 00:00:00 2001 From: edzer Date: Thu, 12 Dec 2024 17:54:17 +0100 Subject: [PATCH] fixes #727 --- NEWS.md | 2 ++ R/spatstat.R | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 8e960982..1db2e832 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # version 0.6-8 +* fix `st_as_stars.im()`; #727 and #648, thanks to Barry Rowlingson + # version 0.6-7 * `st_extract()` fix if points coincide with boundary grid cell centers and bilinear interpolation is used; #720 diff --git a/R/spatstat.R b/R/spatstat.R index 62fc3d90..14c368e2 100644 --- a/R/spatstat.R +++ b/R/spatstat.R @@ -24,7 +24,13 @@ as.owin.stars = function(W, ..., fatal) { #' @export st_as_stars.im = function(.x, ...) { # see https://github.com/r-spatial/stars/issues/648 - setNames(st_as_stars(as.data.frame(.x, ...)), "v") + #setNames(st_as_stars(as.data.frame(.x, ...)), "v") + d = dim(.x) + nd = create_dimensions( + list(x = create_dimension(1, d[2], .x$xrange[1], diff(.x$xrange)/d[2]), + y = create_dimension(1, d[1], .x$yrange[1], diff(.x$yrange)/d[1])), + get_raster(affine = c(0.0, 0.0), dimensions = c("x", "y"), curvilinear = FALSE)) + st_stars(list(v = t(.x$v)), nd) } as.im.stars = function(X, ...) {