Skip to content

Commit

Permalink
fix the case when sf resampled and changed the size
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsumner committed Jun 29, 2023
1 parent 9c0070a commit 14644fb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion R/ximage.R
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,18 @@ ximage_sf_data <- function(x, extent = NULL, ...) {
d <- matrix(d[1:prod(dim[1:2])], dm[1], dm[2])
}
if (do_extent) {
extent <- .gt_dim_to_extent(x$geotransform, dm[1:2])

## sf gdal_read (@ 4901a41ec56d2ad1524bab553c9195a6bd417987) doesn't update the geotransform ofsets so we do that here
gt <- x$geotransform
if (x$cols[1] > 1) {
gt[1] <- gt[1] + gt[2] * (x$cols[1] - 1)
}
if (x$rows[1] > 1) {
gt[4] <- gt[4] + gt[6] * (x$row[1] - 1)
}


extent <- .gt_dim_to_extent(gt, dm[1:2])
}
ximage(t(d), extent = extent, ...)
}

0 comments on commit 14644fb

Please sign in to comment.