From a907706845b1e415d198de967e147183ba002e45 Mon Sep 17 00:00:00 2001 From: Scott Chamberlain Date: Sun, 5 Jul 2015 15:32:39 -0700 Subject: [PATCH] changed occ_to_sp to occ2sp --- NAMESPACE | 2 +- R/map_gist.R | 6 +----- R/occ2sp.R | 20 +++++++++----------- man/{occ_to_sp.Rd => occ2sp.Rd} | 21 ++++++++++----------- 4 files changed, 21 insertions(+), 28 deletions(-) rename man/{occ_to_sp.Rd => occ2sp.Rd} (60%) diff --git a/NAMESPACE b/NAMESPACE index 6707d80..100f08f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,7 +9,7 @@ export(map_ggplot) export(map_gist) export(map_leaflet) export(map_plot) -export(occ_to_sp) +export(occ2sp) export(palettes) export(spocc_rcharts_togeojson) export(style_geojson) diff --git a/R/map_gist.R b/R/map_gist.R index 4b4fb70..bdfe710 100644 --- a/R/map_gist.R +++ b/R/map_gist.R @@ -33,11 +33,7 @@ map_gist <- function(data, description = "", public = TRUE, browse = TRUE, ...) { stopifnot(is(data, "occdatind") | is(data, "occdat")) - data <- if (is(data, "occdatind")) { - do.call(rbind, data$data) - } else { - occ2df(data) - } + data <- occ2df(data) datgeojson <- style_geojson(input = data, var = "name", ...) file <- tempfile(fileext = ".csv") write.csv(datgeojson, file) diff --git a/R/occ2sp.R b/R/occ2sp.R index 487a428..fb09db4 100644 --- a/R/occ2sp.R +++ b/R/occ2sp.R @@ -1,9 +1,9 @@ -#' Create a spatial points dataframe from a spocc search. +#' Create a spatial points dataframe from a spocc search #' #' @importFrom sp SpatialPoints SpatialPointsDataFrame plot #' @export #' -#' @param occObj The resuslts of a spocc search called by occ() +#' @param x The resuslts of a spocc search called by occ() #' @param coord_string A valid EPGS cooridate string from the sp package, the default is WSGS 84 #' @param just_coords Return data frame with specios names and provenance or just a spatial points #' object, which is the default. @@ -18,18 +18,16 @@ #' library("maptools") #' library("spocc") #' data(wrld_simpl) -#' plot(wrld_simpl[wrld_simpl$NAME == "United States", ],xlim=c(-70,-60)) -#' out <- occ(query = "Accipiter striatus", from = c("inat","gbif")) -#' sp_points <- occ_to_sp(out, just_coords=TRUE) -#' points(sp_points,col=2) +#' plot(wrld_simpl[wrld_simpl$NAME == "United States", ], xlim = c(-70, -60)) +#' out <- occ(query = "Accipiter striatus", from = c("ecoengine", "gbif"), limit = 50) +#' sp_points <- occ2sp(out, just_coords = TRUE) +#' points(sp_points, col = 2) #' } - -occ_to_sp <- function(occObj, coord_string = "+proj=longlat +datum=WGS84", just_coords = FALSE){ - - points <- occ2df(occObj) +occ2sp <- function(x, coord_string = "+proj=longlat +datum=WGS84", just_coords = FALSE) { + points <- occ2df(x) # remove NA rows - points <- points[complete.cases(points),] + points <- points[complete.cases(points), ] # check valid coords index <- 1:dim(points)[1] diff --git a/man/occ_to_sp.Rd b/man/occ2sp.Rd similarity index 60% rename from man/occ_to_sp.Rd rename to man/occ2sp.Rd index a5f6bbb..b752fe7 100644 --- a/man/occ_to_sp.Rd +++ b/man/occ2sp.Rd @@ -1,14 +1,13 @@ % Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/occ2sp.R -\name{occ_to_sp} -\alias{occ_to_sp} -\title{Create a spatial points dataframe from a spocc search.} +\name{occ2sp} +\alias{occ2sp} +\title{Create a spatial points dataframe from a spocc search} \usage{ -occ_to_sp(occObj, coord_string = "+proj=longlat +datum=WGS84", - just_coords = FALSE) +occ2sp(x, coord_string = "+proj=longlat +datum=WGS84", just_coords = FALSE) } \arguments{ -\item{occObj}{The resuslts of a spocc search called by occ()} +\item{x}{The resuslts of a spocc search called by occ()} \item{coord_string}{A valid EPGS cooridate string from the sp package, the default is WSGS 84} @@ -16,7 +15,7 @@ occ_to_sp(occObj, coord_string = "+proj=longlat +datum=WGS84", object, which is the default.} } \description{ -Create a spatial points dataframe from a spocc search. +Create a spatial points dataframe from a spocc search } \details{ This function will return either a spatial points dataframe or spatial points object. @@ -30,10 +29,10 @@ data sources. More coordinate system codes can be found at the EPGS registry: library("maptools") library("spocc") data(wrld_simpl) -plot(wrld_simpl[wrld_simpl$NAME == "United States", ],xlim=c(-70,-60)) -out <- occ(query = "Accipiter striatus", from = c("inat","gbif")) -sp_points <- occ_to_sp(out, just_coords=TRUE) -points(sp_points,col=2) +plot(wrld_simpl[wrld_simpl$NAME == "United States", ], xlim = c(-70, -60)) +out <- occ(query = "Accipiter striatus", from = c("ecoengine", "gbif"), limit = 50) +sp_points <- occ2sp(out, just_coords = TRUE) +points(sp_points, col = 2) } }