diff --git a/NAMESPACE b/NAMESPACE index 62910ab..2f5a0dc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,6 +27,7 @@ export(spocc_rcharts_togeojson) export(spocc_stylegeojson) export(spocc_togeojson) export(wkt2bbox) +export(wkt_vis) import(AntWeb) import(XML) import(assertthat) diff --git a/R/wkt_vis.r b/R/wkt_vis.r new file mode 100644 index 0000000..c535713 --- /dev/null +++ b/R/wkt_vis.r @@ -0,0 +1,35 @@ +#' Visualize well-known text area's on a map. +#' +#' This can be helpful in visualizing the area in which you are searching for +#' occurrences with the \code{occ} function. +#' +#' @import ggmap ggplot2 assertthat rgeos +#' @param x Input well-known text area (character) +#' @param zoom Zoom level, defaults to 6 (numeric) +#' @param maptype Map type, default is terrain (character) +#' @export +#' @examples \dontrun{ +#' poly <- 'POLYGON((-111.06 38.84, -110.80 39.37, -110.20 39.17, -110.20 38.90, -110.63 38.67, -111.06 38.84))' +#' wkt_vis(poly) +#' +#' poly2 <- 'POLYGON((-125 38.4,-125 40.9,-121.8 40.9,-121.8 38.4,-125 38.4))' +#' wkt_vis(poly2) +#' } + +wkt_vis <- function(x, zoom = 6, maptype = "terrain") +{ + assert_that(!is.null(x)) + assert_that(is.character(x)) + + poly_wkt <- readWKT(x) + df <- fortify(poly_wkt) + center_lat <- min(df$lat) + (max(df$lat) - min(df$lat))/2 + center_long <- min(df$long) + (max(df$long) - min(df$long))/2 + map_center <- c(lon = center_long, lat = center_lat) + species_map <- get_map(location = map_center, zoom = zoom, maptype = maptype) + ggmap(species_map) + + geom_path(data = df, aes(x = long, y = lat, group=group, size=2)) + + theme(legend.position="") + + xlab("Longitude") + + ylab("Latitude") +} \ No newline at end of file diff --git a/man/wkt_vis.Rd b/man/wkt_vis.Rd new file mode 100644 index 0000000..899d02e --- /dev/null +++ b/man/wkt_vis.Rd @@ -0,0 +1,27 @@ +\name{wkt_vis} +\alias{wkt_vis} +\title{Visualize well-known text area's on a map.} +\usage{ +wkt_vis(x, zoom = 6, maptype = "terrain") +} +\arguments{ + \item{x}{Input well-known text area (character)} + + \item{zoom}{Zoom level, defaults to 6 (numeric)} + + \item{maptype}{Map type, default is terrain (character)} +} +\description{ +This can be helpful in visualizing the area in which you +are searching for occurrences with the \code{occ} function. +} +\examples{ +\dontrun{ +poly <- 'POLYGON((-111.06 38.84, -110.80 39.37, -110.20 39.17, -110.20 38.90, -110.63 38.67, -111.06 38.84))' +wkt_vis(poly) + +poly2 <- 'POLYGON((-125 38.4,-125 40.9,-121.8 40.9,-121.8 38.4,-125 38.4))' +wkt_vis(poly2) +} +} +