Skip to content

Commit

Permalink
fix #723
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Oct 31, 2024
1 parent 79690b8 commit 5d6fc15
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions R/stars.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,20 @@ xy_from_colrow = function(x, geotransform) {
x %*% matrix(geotransform[c(2, 3, 5, 6)], nrow = 2, ncol = 2)
}

colrow_from_xy = function(x, obj, NA_outside = FALSE) {
colrow_from_xy = function(x, obj, NA_outside = FALSE, flip = FALSE) {
if (inherits(obj, "stars"))
obj = st_dimensions(obj)
xy = attr(obj, "raster")$dimensions
if (inherits(obj, "dimensions"))
gt = st_geotransform(obj)

if (isTRUE(st_is_longlat(st_crs(obj)))) {
if (flip && isTRUE(st_is_longlat(st_crs(obj)))) {
bb = st_bbox(obj)
# see https://github.com/r-spatial/stars/issues/519 where this is problematic;
# not sure whether this introduces new problems.
# sign = ifelse(x[,1] < bb["xmin"], 1., ifelse(x[,1] > bb["xmax"], -1., 0.))
# x[,1] = x[,1] + sign * 360.
# one more try: https://github.com/r-spatial/stars/issues/563
## one more try: https://github.com/r-spatial/stars/issues/563
ix = x[,1] > bb["xmax"] & !is.na(x[,1])
x[ix,1] = x[ix,1] - 360.
ix = x[,1] < bb["xmin"] & !is.na(x[,1])
Expand Down
2 changes: 1 addition & 1 deletion R/warp.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ transform_grid_grid = function(x, target, threshold) {
ny = dim(x)[1]
cbind(i %% ny, i %/% ny) + 1
} else
colrow_from_xy(pts, x, NA_outside = TRUE)
colrow_from_xy(pts, x, NA_outside = TRUE, flip = TRUE)
dims = dim(x)
index = matrix(seq_len(prod(dims[dxy])), dims[ dxy[1] ], dims[ dxy[2] ])[xy]
x = unclass(x) # avoid using [[<-.stars:
Expand Down

0 comments on commit 5d6fc15

Please sign in to comment.