-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
461 additions
and
886 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,301 +0,0 @@ | ||
#' Interface to search into the Earth Engine Data Catalog | ||
#' | ||
#' R functions for searching in Earth Engine's public data archive. | ||
#' | ||
#' @param quiet logical. Suppress info message | ||
#' @param ee_search_dataset data.frame generated by rgee::ee_search_Datasets() | ||
#' or a character which represents the EE dataset ID. | ||
#' @param stardate Character. Start date of dataset availability. | ||
#' @param enddate Character. End date of dataset availability. | ||
#' @param provider Character. Name of the dataset's provider. See | ||
#' ee_search_provider_list() | ||
#' @param type Character. "Image", "ImageCollection" or a "table". | ||
#' @param ... Character vector. tags | ||
#' @param logical_operator Character. Available just for rgee::ee_search_tags | ||
#' and rgee::ee_search_title. 'AND' represents inclusiveness between tags in | ||
#' searching and 'OR' exclusiveness. | ||
#' @param upgrade Logical. If the dataset needs to be upgraded. | ||
#' @param maxdisplay Numeric. Maximum number of tabs to display in their browser | ||
#' @param path_dataset Path of the dataset. By default it will loaded | ||
#' automatically. | ||
#' @name ee_search-tools | ||
#' @return A data.frame where rows represents public data archive. | ||
#' @examples | ||
#' \dontrun{ | ||
#' library(rgee) | ||
#' ee_Initialize() | ||
#' | ||
#' # ee_search_provider_list() | ||
#' # ee_search_title_list() | ||
#' myquery <- ee_search_dataset() %>% | ||
#' ee_search_type("Image") %>% | ||
#' ee_search_provider("WWF") %>% | ||
#' ee_search_tags("srtm", "flow", "direction", "dem") %>% | ||
#' ee_search_title("15", "Flow", logical_operator = "AND") %>% | ||
#' ee_search_display() | ||
#' } | ||
#' @export | ||
ee_search_dataset <- function(quiet = FALSE, | ||
upgrade = FALSE, | ||
path_dataset = NULL) { | ||
message_deprecated <- c( | ||
"\"ee_search_dataset\" will not be available for rgee version 1.0.8 ." | ||
) | ||
.Deprecated("ee_search_dataset", msg = message_deprecated) | ||
|
||
oauth_func_path <- system.file("python/ee_utils.py", package = "rgee") | ||
utils_py <- ee_source_python(oauth_func_path) | ||
ee_path <- ee_utils_py_to_r(utils_py$ee_path()) | ||
ee_search_dataset_file <- sprintf( | ||
"%s/ee_search_dataset.csv", | ||
ee_path | ||
) | ||
if (file.exists(ee_search_dataset_file) & !upgrade) { | ||
ee_search_dataset <- read.csv(ee_search_dataset_file, | ||
stringsAsFactors = FALSE) | ||
} else { | ||
if (is.null(path_dataset)) { | ||
user_samapriya <- "https://raw.githubusercontent.com/csaybar/" | ||
ee_template <- "%sEarth-Engine-Datasets-List/master/%s" | ||
ee_search_dataset_uri <- sprintf(ee_template, user_samapriya, | ||
find_eedataset()) | ||
} else { | ||
ee_search_dataset_uri <- path_dataset | ||
} | ||
ee_search_dataset <- read.csv(ee_search_dataset_uri, | ||
stringsAsFactors = FALSE) | ||
if (!quiet) { | ||
cat("Downloading(Upgrading) the Earth Engine catalog ... please wait\n") | ||
} | ||
write.csv( | ||
x = ee_search_dataset, | ||
file = ee_search_dataset_file, | ||
row.names = FALSE | ||
) | ||
} | ||
return(ee_search_dataset) | ||
} | ||
|
||
#' @name ee_search-tools | ||
#' @export | ||
ee_search_startdate <- function(ee_search_dataset, stardate) { | ||
message_deprecated <- c( | ||
"\"ee_search_startdate\" will not be available for rgee version 1.0.8 ." | ||
) | ||
.Deprecated("ee_search_startdate", msg = message_deprecated) | ||
|
||
m <- gregexpr("[\\w']+", ee_search_dataset$start_date, perl = TRUE) | ||
ee_start_date <- ee_search_dataset$start_date %>% | ||
regmatches(m) %>% | ||
lapply(fix_date) | ||
m <- do.call(c, m) | ||
stardate <- as.Date(stardate) | ||
ee_search_dataset_q <- ee_search_dataset[which(ee_start_date > stardate), ] | ||
rownames(ee_search_dataset_q) <- NULL | ||
return(ee_search_dataset_q) | ||
} | ||
|
||
#' @name ee_search-tools | ||
#' @export | ||
ee_search_enddate <- function(ee_search_dataset, enddate = Sys.Date()) { | ||
message_deprecated <- c( | ||
"\"ee_search_enddate\" will not be available for rgee version 1.0.8 ." | ||
) | ||
.Deprecated("ee_search_enddate", msg = message_deprecated) | ||
m <- gregexpr("[\\w']+", ee_search_dataset$end_date, perl = TRUE) | ||
ee_end_date <- ee_search_dataset$end_date %>% | ||
regmatches(m) %>% | ||
lapply(fix_date) | ||
m <- do.call(c, m) | ||
enddate <- as.Date(enddate) | ||
ee_search_dataset_q <- ee_search_dataset[which(ee_end_date < enddate), ] | ||
rownames(ee_search_dataset_q) <- NULL | ||
return(ee_search_dataset_q) | ||
} | ||
|
||
#' @name ee_search-tools | ||
#' @export | ||
ee_search_type <- function(ee_search_dataset, type) { | ||
message_deprecated <- c( | ||
"\"ee_search_type\" will not be available for rgee version 1.0.8 ." | ||
) | ||
.Deprecated("ee_search_type", msg = message_deprecated) | ||
ee_search_dataset_type <- tolower(ee_search_dataset$type) | ||
type <- tolower(type) | ||
if (type %in% unique(ee_search_dataset_type)) { | ||
ee_search_dataset_q <- ee_search_dataset[ee_search_dataset_type %in% type, ] | ||
rownames(ee_search_dataset_q) <- NULL | ||
return(ee_search_dataset_q) | ||
} else { | ||
stop("type argument is not valid") | ||
} | ||
} | ||
|
||
#' @name ee_search-tools | ||
#' @export | ||
ee_search_provider <- function(ee_search_dataset, provider) { | ||
message_deprecated <- c( | ||
"\"ee_search_provider\" will not be available for rgee version 1.0.8 ." | ||
) | ||
.Deprecated("ee_search_provider", msg = message_deprecated) | ||
if (provider %in% unique(ee_search_dataset$provider)) { | ||
condition <- ee_search_dataset$provider %in% provider | ||
ee_search_dataset_q <- ee_search_dataset[condition,] | ||
rownames(ee_search_dataset_q) <- NULL | ||
return(ee_search_dataset_q) | ||
} else { | ||
stop("provider argument is not valid") | ||
} | ||
} | ||
|
||
#' @name ee_search-tools | ||
#' @export | ||
ee_search_provider_list <- function(ee_search_dataset) { | ||
message_deprecated <- c( | ||
"\"ee_search_provider_list\" will not be available for rgee version 1.0.8 ." | ||
) | ||
.Deprecated("ee_search_provider_list", msg = message_deprecated) | ||
return(unique(ee_search_dataset$provider)) | ||
} | ||
|
||
#' @name ee_search-tools | ||
#' @export | ||
ee_search_tags <- function(ee_search_dataset, ..., logical_operator = "OR") { | ||
message_deprecated <- c( | ||
"\"ee_search_tags\" will not be available for rgee version 1.0.8 ." | ||
) | ||
.Deprecated("ee_search_tags", msg = message_deprecated) | ||
tags <- tolower(c(...)) | ||
ee_tags <- tolower(ee_search_dataset$tags) | ||
if (logical_operator == "OR") { | ||
cond <- mapply(function(x) grepl(x, ee_tags), tags) %>% apply(1, any) | ||
} else if (logical_operator == "AND") { | ||
cond <- mapply(function(x) grepl(x, ee_tags), tags) %>% apply(1, all) | ||
} else { | ||
stop("logical_operator argument is not valid") | ||
} | ||
ee_search_dataset_q <- ee_search_dataset[cond, ] | ||
rownames(ee_search_dataset_q) <- NULL | ||
return(ee_search_dataset_q) | ||
} | ||
|
||
#' @name ee_search-tools | ||
#' @export | ||
ee_search_title <- function(ee_search_dataset, ..., logical_operator = "OR") { | ||
message_deprecated <- c( | ||
"\"ee_search_title\" will not be available for rgee version 1.0.8." | ||
) | ||
.Deprecated("ee_search_title", msg = message_deprecated) | ||
tags <- tolower(c(...)) | ||
ee_title <- tolower(ee_search_dataset$title) | ||
if (logical_operator == "OR") { | ||
cond <- mapply(function(x) grepl(x, ee_title), tags) %>% apply(1, any) | ||
} else if (logical_operator == "AND") { | ||
cond <- mapply(function(x) grepl(x, ee_title), tags) %>% apply(1, all) | ||
} else { | ||
stop("logical_operator argument is not valid") | ||
} | ||
ee_search_dataset_q <- ee_search_dataset[cond, ] | ||
rownames(ee_search_dataset_q) <- NULL | ||
return(ee_search_dataset_q) | ||
} | ||
|
||
|
||
#' @name ee_search-tools | ||
#' @export | ||
ee_search_tagstitle <- function(ee_search_dataset, ..., | ||
logical_operator = "OR") { | ||
message_deprecated <- c( | ||
"\"ee_search_tagstitle\" will not be available for rgee version 1.0.8." | ||
) | ||
.Deprecated("ee_search_tagstitle", msg = message_deprecated) | ||
|
||
tags <- tolower(c(...)) | ||
ee_title <- tolower(ee_search_dataset$title) | ||
ee_tags <- tolower(ee_search_dataset$tags) | ||
if (logical_operator == "OR") { | ||
cond_1 <- mapply(function(x) grepl(x, ee_title), tags) %>% apply(1, any) | ||
cond_2 <- mapply(function(x) grepl(x, ee_tags), tags) %>% apply(1, any) | ||
cond_3 <- mapply(any, cond_1, cond_2) | ||
} else if (logical_operator == "AND") { | ||
cond_1 <- mapply(function(x) grepl(x, ee_title), tags) %>% apply(1, all) | ||
cond_2 <- mapply(function(x) grepl(x, ee_tags), tags) %>% apply(1, all) | ||
cond_3 <- mapply(any, cond_1, cond_2) | ||
} else { | ||
stop("logical_operator argument is not valid") | ||
} | ||
ee_search_dataset_q <- ee_search_dataset[cond_3, ] | ||
rownames(ee_search_dataset_q) <- NULL | ||
return(ee_search_dataset_q) | ||
} | ||
|
||
#' @name ee_search-tools | ||
#' @export | ||
ee_search_title_list <- function(ee_search_dataset) { | ||
message_deprecated <- c( | ||
"\"ee_search_title_list\" will not be available for rgee version 1.0.8." | ||
) | ||
.Deprecated("ee_search_title_list", msg = message_deprecated) | ||
return(unique(ee_search_dataset$provider)) | ||
} | ||
|
||
#' Change the date format | ||
#' @noRd | ||
fix_date <- function(x) { | ||
month <- x[1] | ||
day <- x[2] | ||
year <- x[3] | ||
if (nchar(year) == 2 & as.integer(year) > 50) { | ||
year <- 1900 + as.integer(year) | ||
} else if (nchar(year) == 2 & as.integer(year) <= 50) { | ||
year <- 2000 + as.integer(year) | ||
} else { | ||
year <- as.integer(year) | ||
} | ||
final_date <- as.Date(sprintf("%s-%s-%s", year, month, day)) | ||
return(final_date) | ||
} | ||
|
||
#' @name ee_search-tools | ||
#' @export | ||
ee_search_display <- function(ee_search_dataset, maxdisplay = 10) { | ||
message_deprecated <- c( | ||
"\"ee_search_title_list\" will not be available for rgee version 1.0.8.", | ||
" Use ee_utils_search_display instead." | ||
) | ||
.Deprecated("ee_search_title_list", msg = message_deprecated) | ||
|
||
if (is.character(ee_search_dataset)) { | ||
tag_name <- gsub("\\/", "_", ee_search_dataset) | ||
} else { | ||
tag_name <- gsub("\\/", "_", ee_search_dataset$id) | ||
} | ||
db_catalog <- "https://developers.google.com/earth-engine/datasets/catalog/" | ||
catalog_uri <- paste0(db_catalog, tag_name) %>% | ||
"["(1:maxdisplay) %>% | ||
na.omit() %>% | ||
as.character() | ||
for (uri in catalog_uri) { | ||
browseURL(uri) | ||
} | ||
invisible(TRUE) | ||
} | ||
|
||
#' Find the EE Dataset List on GitHub | ||
#' @noRd | ||
find_eedataset <- function() { | ||
message_deprecated <- c( | ||
"\"ee_search_title_list\" will not be available for rgee version 1.0.8." | ||
) | ||
.Deprecated("ee_search_title_list", msg = message_deprecated) | ||
|
||
if (!requireNamespace("httr", quietly = TRUE)) { | ||
stop("package httr required, please install it first") | ||
} | ||
git_repo <- "https://api.github.com/repos/csaybar/Earth-Engine-Datasets-List/" | ||
req <- httr::GET(sprintf("%s/git/trees/master?recursive=1", git_repo)) | ||
httr::stop_for_status(req) | ||
filelist <- lapply(httr::content(req)$tree, "[", "path") | ||
filelist <- unlist(filelist, use.names = FALSE) | ||
filelist[grepl("eed", filelist)] | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.