| coords2JSON {mapview} | R Documentation |
Similar to toJSON from jsonlite, this function takes a
set of coordinates as input and converts them to proper JSON format. Note
that the function is powered by Rcpp which makes it a convenient
alternative to existing methods when it comes to processing big datasets.
## S4 method for signature 'numeric' coords2JSON(x) ## S4 method for signature 'character' coords2JSON(x, xy = c(1, 2)) ## S4 method for signature 'matrix' coords2JSON(x, xy = c(1, 2))
x |
A 'numeric' vector with a single pair of coordinates or a matrix with multiple pairs of input coordinates, typically projected in EPSG:4326 (http://spatialreference.org/ref/epsg/wgs-84/). |
xy |
An 'integer' vector specifying the coordinate columns. |
A single 'character' object in JSON format.
Florian Detsch
crd <- matrix(ncol = 3, nrow = 12) # x-coordinates set.seed(10) crd[, 1] <- rnorm(nrow(crd), 10, 3) # y-coordinates set.seed(10) crd[, 2] <- rnorm(nrow(crd), 50, 3) # additional data crd[, 3] <- month.abb # reformat a single pair of coordinates coords2JSON(crd[1, ]) # reformat multiple pairs of coordinates at once coords2JSON(crd)