Skip to content

Commit

Permalink
v
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Jan 24, 2025
1 parent eb03687 commit d0904e8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: terra
Type: Package
Title: Spatial Data Analysis
Version: 1.8-15
Date: 2025-01-23
Version: 1.8-16
Date: 2025-01-24
Depends: R (>= 3.5.0)
Suggests: parallel, tinytest, ncdf4, sf (>= 0.9-8), deldir, XML, leaflet (>= 2.2.1), htmlwidgets
LinkingTo: Rcpp
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# version 1.8-16

## bug fixes

## enhancements

## new

- `as.array<SpatRasterDataset>` method

# version 1.8-15

Released 2025-01-24

## bug fixes

- `readRDS` failed for rasters with timestep="seconds" [#1711](https://github.com/rspatial/terra/issues/1711) by Pascal Oettli
Expand Down
23 changes: 23 additions & 0 deletions R/coerce.R
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,29 @@ setMethod("as.array", signature(x="SpatRaster"),
}
)

setMethod("as.array", signature(x="SpatRasterDataset"),
function(x) {
n <- length(x)
if (n < 2) return(as.array(x[1]))

dm <- sapply(x, dim)
udm <- apply(dm, 1, function(i)length(unique))
if (!all(udm) == 1) {
error("as.array", "cannot make an array from rasters with different dimensions")
}

a <- array(NA, c(dm[,1], n))
dimnames(a) <- list(NULL, NULL, NULL, names(x))

for (i in 1:n) {
a[,,,i] <- as.array(x[i])
}
a
}
)




# to sf from SpatVector
# available in sf
Expand Down
3 changes: 3 additions & 0 deletions man/coerce.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
\alias{as.vector,SpatRaster-method}
\alias{as.matrix,SpatRaster-method}
\alias{as.array,SpatRaster-method}
\alias{as.array,SpatRasterDataset-method}

\alias{as.vector,SpatExtent-method}
\alias{as.matrix,SpatExtent-method}
Expand All @@ -27,6 +28,8 @@ Coercion of a SpatRaster to a vector, matrix or array. Or coerce a SpatExtent to

\S4method{as.array}{SpatRaster}(x)

\S4method{as.array}{SpatRasterDataset}(x)

\S4method{as.vector}{SpatExtent}(x, mode='any')

\S4method{as.matrix}{SpatExtent}(x, ...)
Expand Down

0 comments on commit d0904e8

Please sign in to comment.