Skip to content

Commit

Permalink
Merge pull request #82 from trafficonese/i69_iquery_terra
Browse files Browse the repository at this point in the history
fix: accept SpatRaster in imageQuery
  • Loading branch information
tim-salabim authored Jun 1, 2024
2 parents a148612 + f808a02 commit c0f6410
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions R/imagequery.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ addImageQuery = function(map,
projected <- sf::st_transform(x, crs = 4326)
}
}
if (inherits(x, "SpatRaster")) {
projected = terra::project(
x
, "epsg:4326"
, method = "near"
)
}
if (inherits(x, "Raster")) {
projected = raster::projectRaster(
x
Expand Down
9 changes: 7 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,16 @@ image2Array = function(x, band = 1) {
switch(class(x)[1],
"stars" = stars2Array(x, band = band),
"RasterLayer" = rasterLayer2Array(x),
stop("can only query single raster or stars layers so far"))
"SpatRaster" = rasterLayer2Array(x),
stop("can only query single raster, stars or terra layers so far"))
}

rasterLayer2Array = function(x) {
x = as.matrix(x)
if (inherits(x, "SpatRaster")) {
x = as.matrix(x, wide = TRUE)
} else {
x = as.matrix(x)
}
paste(
sapply(seq(ncol(x)), function(i) {
paste0(
Expand Down

0 comments on commit c0f6410

Please sign in to comment.