Skip to content

Commit

Permalink
speed up x/y for #19
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsumner committed Apr 23, 2024
1 parent 35fabae commit c9e56f0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: vaster
Title: Tools for Raster Grid Logic
Version: 0.0.1.9002
Version: 0.0.1.9003
Authors@R: c(person("Michael", "Sumner", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-2471-7511")))
Description: Provides raster grid logic, the grid operations that don't require access to materialized data, i.e. most of them.
Grids are arrays with dimension and extent, and many operations are functions of just the dimension 'nrows', 'ncols' or
Expand All @@ -11,7 +11,7 @@ Description: Provides raster grid logic, the grid operations that don't require
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
URL: https://github.com/hypertidy/vaster, https://hypertidy.github.io/vaster/
BugReports: https://github.com/hypertidy/vaster/issues
Suggests:
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# vaster dev

* Speed up `x_from_col` and `y_from_row`, fixes #19.

* New functions `rasterio_idx()` (was affinity::raster_to_rasterio), `rasterio0` (was affinity::raster_io0) and
internal for now `rasterio_crop()`.

Expand Down
8 changes: 6 additions & 2 deletions R/coordinates.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ x_from_col <- function(dimension, extent = NULL, col) {

col[col < 1] <- NA
col[col > dimension[1L]] <- NA
x_centre(dimension, extent = extent)[col]
xres <- x_res(dimension, extent)
extent[1] - xres/2 + col * xres

}

#' @name coordinates
Expand All @@ -156,7 +158,9 @@ y_from_row <- function(dimension, extent = NULL, row) {

row[row < 1] <- NA
row[row > dimension[2]] <- NA
rev(y_centre(dimension, extent = extent))[row]
yres <- y_res(dimension, extent)
extent[4] + yres/2 - row * yres

}

#' @name coordinates
Expand Down

0 comments on commit c9e56f0

Please sign in to comment.