#' Measure
#'
#' Allows interactive selection of points and returns length of selecte line in
#' units of the current \code{qmap} object.
#' @param qmap_obj a \code{qmap} object from which to measure features.
#'
#' @import sp
#' @export
m <- function(qmap_obj = NULL){
if (!inherits(qmap_obj, "qmap")) {
stop("Requires a valid qmap_obj.")
}
plot(qmap_obj)
message("Click on plot to draw line to measure. Press 'Esc' to exit.")
loc <- locator(1)
locs <- sp::coordinates(loc)
while (!is.null(loc)) {
sl <- SpatialLines(list(Lines(list(Line(locs)), "id")))
plot(sl,add=T)
loc <- locator(1)
if(!is.null(loc)){
locs<-rbind(locs,sp::coordinates(loc))
}
}
sf::st_length(sf::st_as_sf(sl))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.