Skip to content

Commit

Permalink
fix read_mdim() for #680
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Apr 22, 2024
1 parent e8612e4 commit 1efaa78
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion R/mdim.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ mdim_use_bounds = function(dims, x, bnds, center = TRUE) {
dims
}

match_raster_dims = function(nms) {
m = tolower(nms) %in% c("lon", "long", "longitude", "lat", "latitude")
if (sum(m) == 2)
which(m)
else
1:2
}


#' Read or write data using GDAL's multidimensional array API
#'
Expand Down Expand Up @@ -190,7 +198,7 @@ read_mdim = function(filename, variable = character(0), ..., options = character
raster = if (sf)
get_raster(dimensions = rep(NA_character_,2))
else
get_raster(dimensions = names(d)[1:2])
get_raster(dimensions = names(d)[match_raster_dims(names(d))])
} else
raster = get_raster(dimensions = raster)
dimensions = create_dimensions(d, raster = raster)
Expand Down
4 changes: 2 additions & 2 deletions R/ncdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,10 @@ read_ncdf = function(.x, ..., var = NULL, ncsub = NULL, curvilinear = character(
coords[[lon_coord]] <- ((coords[[lon_coord]] + 180) %% 360) - 180
} else if(!is.null(lons) && .is_degrees(atts, lon_coord) &&
max(lons) > 180) {
message(paste0("0-360 longitude crossing the international date",
message(paste("0-360 longitude crossing the international date",
"line encountered.\nLongitude coordinates will be",
"0-360 in output."))

}
}
coords
Expand Down

0 comments on commit 1efaa78

Please sign in to comment.