Skip to content

Commit

Permalink
fixes #678
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Apr 16, 2024
1 parent d9e84dd commit cee624a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# version 0.6-6

* constrain reading full GEOLOCATION arrays to the case where they are 2-D; #678

# version 0.6-5

* fix `st_as_stars.Spatial()` for `Spatial` gridded objects with non-square grid cells, see https://github.com/r-spatial/gstat/issues/123
Expand Down
12 changes: 11 additions & 1 deletion R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ unique_part = function(x, prefix) {
x
}

geoloc_is_2D = function(geolocation, driver) { # the thing has 2-D x and y arrays:
# read coordinate array dimensions only:
gxy = c(geolocation$X_DATASET, geolocation$Y_DATASET)
lon = adrop(read_stars(gxy[1], driver = driver, quiet = TRUE,
proxy = TRUE, curvilinear = character(0)))
lat = adrop(read_stars(gxy[2], driver = driver, quiet = TRUE,
proxy = TRUE, curvilinear = character(0)))
dim(lon)[2] > 1 || dim(lat)[2] > 1
}


#' read raster/array dataset from file or connection
#'
Expand Down Expand Up @@ -140,7 +150,7 @@ read_stars = function(.x, sub = TRUE, ..., options = character(0),

if (missing(curvilinear)) { # see if we can get it from metadata item "GEOLOCATION":
geolocation <- try(gdal_metadata(.x, "GEOLOCATION"), silent = TRUE)
if (!inherits(geolocation, "try-error")) { # the thing has x and y arrays:
if (!inherits(geolocation, "try-error") && geoloc_is_2D(geolocation, driver)) { # the thing has 2-D x and y arrays:
# read coordinate arrays:
gxy = c(geolocation$X_DATASET, geolocation$Y_DATASET)
lon = adrop(read_stars(gxy[1], driver = driver, quiet = quiet, NA_value = NA_value,
Expand Down

0 comments on commit cee624a

Please sign in to comment.