R/flip.R

Defines functions lawn_flip

Documented in lawn_flip

#' Flip x,y to y,x, and vice versa
#'
#' @export
#' @param input [data-Feature] or [data-FeatureCollection]
#' @template lint
#' @return A [data-Feature] or [data-FeatureCollection]
#' @examples
#' # a point
#' serbia <- '{
#'   "type": "Feature",
#'   "properties": {"color": "red"},
#'   "geometry": {
#'     "type": "Point",
#'     "coordinates": [20.566406, 43.421008]
#'    }
#' }'
#' lawn_flip(serbia)
#'
#' # a featurecollection
#' pts <- lawn_random("points")
#' lawn_flip(pts)
#' @examples \dontrun{
#' lawn_data$points_average %>% view
#' lawn_flip(lawn_data$points_average) %>% view
#' lawn_data$polygons_average %>% view
#' lawn_flip(lawn_data$polygons_average) %>% view
#' }
lawn_flip <- function(input, lint = FALSE) {
  input <- convert(input)
  lawnlint(input, lint)
  if (lint) is_type(input, type_top = c("Feature", "FeatureCollection"))
  ct$eval(sprintf("var flp = turf.flip(%s);", input))
  structure(ct$get("flp"), class = tolower(ct$get("flp.type")))
}

Try the lawn package in your browser

Any scripts or data that you put into this service are public.

lawn documentation built on Jan. 6, 2021, 5:07 p.m.