Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
changed occ_to_sp to occ2sp
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jul 5, 2015
1 parent 8e35147 commit a907706
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions R/map_gist.R
Expand Up @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions 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.
Expand All @@ -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]
Expand Down
21 changes: 10 additions & 11 deletions man/occ_to_sp.Rd → man/occ2sp.Rd
@@ -1,22 +1,21 @@
% 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}

\item{just_coords}{Return data frame with specios names and provenance or just a spatial points
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.
Expand All @@ -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)
}
}

0 comments on commit a907706

Please sign in to comment.