Skip to content
Permalink
Browse files

Fixes a bug leading to errors in processing extent

When switching products with different Native projection (4008 vs sinusoidal), the projection string was not properly updated.
  • Loading branch information
lbusett committed Jun 20, 2018
1 parent 9952b9a commit 77f5693e9e1e180f05efaa04fa031567e782ba89
Showing with 21 additions and 17 deletions.
  1. +5 −5 R/bbox_from_file.R
  2. +14 −11 R/gh_load_extent.R
  3. +2 −1 R/gui_helpers.R
@@ -11,19 +11,19 @@
#' @note License: GPL 3.0

bbox_from_file <- function(file_path, crs_out) {

# Retrieve CRS using gdal: if fails, then the file is not a valid spatial file
in_gdalinfo <- suppressWarnings(try(rgdal::GDALinfo(file_path),
silent = TRUE))
in_ogrinfo <- suppressWarnings(try(rgdal::ogrInfo(file_path),
silent = TRUE))

if (methods::is(in_ogrinfo, "try-error") &
methods::is(in_gdalinfo, "try-error")) {
stop(file_path, "is not recognised by GDAL or OGR as a valid spatial",
"file. Please check your inputs. Aborting!")
}

# If it does not fail, then retrieve the bounding box
if (methods::is(in_gdalinfo, "try-error")) {
bbox_in <- matrix(in_ogrinfo$extent,
@@ -34,13 +34,13 @@ bbox_from_file <- function(file_path, crs_out) {
bbox_in <- gdalUtils::gdalinfo(file_path, raw_output = FALSE)$bbox
crs_in <- attr(in_gdalinfo, "projection")
}

# Convert the bounding box in the chosen projection (ensuring to include the
# full area covered in the original bbox by using "enlarge == TRUE")
bbox_out <- reproj_bbox(bbox_in,
crs_in,
crs_out,
enlarge = TRUE)

return(bbox_out)
}
@@ -4,7 +4,7 @@
#' @noRd
#' @importFrom gWidgets size svalue
#' @noRd
gh_load_extent <- function(h, wids, out_proj_list, mod_proj_str,
gh_load_extent <- function(h, wids, out_proj_list, mod_proj_str,
modis_grid) {
#nocov start
choice <- try(gfile(
@@ -32,12 +32,15 @@ gh_load_extent <- function(h, wids, out_proj_list, mod_proj_str,
)
Sys.sleep(0.05)
# Convert bbox coordinates to output projection

curr_proj <-
out_proj_crs <- ifelse(
gWidgets::svalue(wids$proj_choice) != "User Defined",
out_proj_list[[gWidgets::svalue(wids$proj_choice)]],
gWidgets::svalue(wids$output_proj4))

# curr_proj <-
# out_proj_crs <- ifelse(
# gWidgets::svalue(wids$proj_choice) != "User Defined",
# out_proj_list[[gWidgets::svalue(wids$proj_choice)]],
# gWidgets::svalue(wids$output_proj4))
curr_proj <- out_proj_crs <- gWidgets::svalue(wids$output_proj4)

print(gWidgets::svalue(wids$proj_choice))
# Create the bounding box in the chosen projection retrieving it from
# the specified file
bbox_out <- try(bbox_from_file(file_path = choice,
@@ -46,14 +49,14 @@ gh_load_extent <- function(h, wids, out_proj_list, mod_proj_str,
if (class(bbox_out) == "try-error") {
gmessage(bbox_out, title = "Error Detected!")
} else {

proj <- gui_get_proj(CRS(curr_proj))
units <- gui_get_units(CRS(curr_proj), proj)
# re-set bbox in the GUI according coordinates retrieved from file
gui_update_bboxlabels(bbox_out,
units,
wids)

# Set tiles according with the bounding box
gui_update_tiles(bbox_out,
out_proj_crs,
@@ -63,7 +66,7 @@ gh_load_extent <- function(h, wids, out_proj_list, mod_proj_str,
}
message("[", date(), "]", " Retrieving Extent, please wait... DONE!")
dispose(wait_window)

}
#nocov end
}
}
@@ -549,7 +549,8 @@ gui_save_options <- function(general_opts,
}
}

if (general_opts$download_server == "http" & unique(http) == "Not Available") { #nolint
if (general_opts$download_server == "http" & http["Aqua"] == "Not Available"
& general_opts$sensor == "Aqua") { #nolint
gWidgets::gmessage(
message = strwrap("The selected product/version is only available for the
Terra sensor.\n\n Please switch sensor!", width = 300),

0 comments on commit 77f5693

Please sign in to comment.
You can’t perform that action at this time.