#' @importFrom methods show
NULL
length.oshElement <- function(x) {
length(x@data)
}
print.oshex <- function(x, ...) {
cat("An OSHEX Object \n\n",
"Queries Performed: ", x@meta@version - 1 , "\n",
"Slots Lengths: Nodes: ", length(x@node), ", Ways: ",
length(x@way), ", Relations: ", length(x@relation), "\n",
"Geographic Extent: ", x@meta@extent, "\n",
"Temporal Coverage: ", as.character(x@meta@temporal), "\n")
}
#' Show an OSHEX S4 class
#' @param object Any R object
#' @export
setMethod("show", signature = "oshex", function(object) {
print(object)
})
summary.oshex <- function(object) {
printSummary <- function(tmpListObject) {
if(length(tmpListObject) == 0) {
return(" -\n")
} else {
return(paste0(" ", names(tmpListObject), ": ", tmpListObject, "\n"))
}
}
slts <- c("node", "way", "relation")
tmp.summary <- setNames(lapply(slts, function(nm) {
if(is.null(slot(object, nm)@tags)) {
warning(paste("tags are not found in the oshex", nm, "slot"))
return(NULL)
} else {
return(sort(table(unlist(lapply(slot(object, nm)@tags, names))), decreasing = TRUE))
}
}), nm = slts)
cat(" node tags:\n", head(printSummary(tmp.summary$node)), " (...)\n\n",
"way tags:\n", head(printSummary(tmp.summary$way)), " (...)\n\n",
"relation tags:\n", head(printSummary(tmp.summary$relation)), " (...)\n")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.