#' @title kmlToPoly
#' @description Convert keyhole files to polygons
#' @details Converts KML files to spatial polygons
#' @rdname kmlToPoly
#' @export kmlToPoly
#' @author Jared P. Lander
#' @param x A list generated by \code{\link[maptools]{getKMLcoordinates}} or a path to a KML file.
#' @param id String specifying an identifier as defined in \code{\link[sp]{Polygons}}
#' @param \dots Further arguments
#'
kmlToPoly <- function(x, id='Block', ...)
{
UseMethod('kmlToPoly')
}
#' @export kmlToPoly.list
#' @export
#' @rdname kmlToPoly
#' @importFrom magrittr "%>%"
#' @importFrom purrr map
#'
kmlToPoly.list <- function(x, id='Block', ...)
{
x %>% map(sp::Polygon) %>% sp::Polygons(ID=id) %>% list %>% sp::SpatialPolygons()
}
#' @export kmlToPoly.character
#' @export
#' @rdname kmlToPoly
#' @importFrom magrittr "%>%"
#'
kmlToPoly <- function(x, id='Block', ignoreAltitude=TRUE, ...)
{
maptools::getKMLcoordinates(kmlfile=x, ignoreAltitude=ignoreAltitude) %>%
kmlToPoly
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.