Skip to content

Commit

Permalink
cran changes
Browse files Browse the repository at this point in the history
  • Loading branch information
csaybar committed Jan 23, 2021
1 parent e0688a4 commit 4c95118
Show file tree
Hide file tree
Showing 52 changed files with 461 additions and 886 deletions.
11 changes: 0 additions & 11 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ export(ee_manage_set_properties)
export(ee_manage_task)
export(ee_monitoring)
export(ee_print)
export(ee_search_dataset)
export(ee_search_display)
export(ee_search_enddate)
export(ee_search_provider)
export(ee_search_provider_list)
export(ee_search_startdate)
export(ee_search_tags)
export(ee_search_tagstitle)
export(ee_search_title)
export(ee_search_title_list)
export(ee_search_type)
export(ee_table_to_asset)
export(ee_table_to_drive)
export(ee_table_to_gcs)
Expand Down
301 changes: 0 additions & 301 deletions R/Deprecated.R
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)]
}
16 changes: 3 additions & 13 deletions R/Map.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,7 @@
#' name = "SF"
#' )
#'
#' # Case 5: mapview + EarthEnginemap
#' # library(mapview)
#' # library(sf)
#' # nc <- st_read(system.file("shp/arequipa.shp", package="rgee"))
#' # mapview(nc, m2)
#'
#' # Case 6: mapedit
#' # library(mapedit)
#' # my_geometry <- m4 %>% editMap()
#'
#' # Case 7: ImageCollection
#' # Case 5: ImageCollection
#' nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>%
#' st_transform(4326) %>%
#' sf_as_ee()
Expand All @@ -170,7 +160,7 @@
#' m5 <- Map$addLayers(ee_s2, legend = TRUE)
#' m5
#'
#' # Case 8: Map comparison
#' # Case 6: Map comparison
#' image <- ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318")
#' Map$centerObject(image)
#' m_ndvi <- Map$addLayer(
Expand All @@ -182,7 +172,7 @@
#' m6 <- m4 | m_ndvi
#' m6
#'
#' # Case 9: digging up the metadata
#' # Case 7: digging up the metadata
#' m6$rgee$tokens
#' m5$rgee$tokens
#' }
Expand Down
Loading

0 comments on commit 4c95118

Please sign in to comment.