Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Commit

Permalink
fix #68 - add properites param to centroid and center, bump dev version
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jun 14, 2017
1 parent 1f17b3d commit 35b8a00
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Description: Client for 'Turfjs' (<http://turfjs.org>) for
measuring aspects of 'GeoJSON', and combining, transforming,
and creating random 'GeoJSON' data objects.
Type: Package
Version: 0.3.6.9110
Version: 0.3.6.9130
License: MIT + file LICENSE
Authors@R: c(
person("Scott", "Chamberlain", role = c("aut", "cre"), email = "[email protected]"),
Expand Down
7 changes: 5 additions & 2 deletions R/center.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
#'
#' @export
#' @param features Input features, as a [data-FeatureCollection].
#' @param properties A list of properties. Default: `NULL`
#' @template lint
#' @family measurements
#' @return A [data-Point] feature at the absolute center point of
#' all input features.
#' @examples
#' lawn_center(lawn_data$points_average)
#' lawn_center(lawn_data$points_average, properties = list(
#' foo = "bar", hello = "world"))
#' @examples \dontrun{
#' lawn_center(lawn_data$points_average) %>% view
#' lawn_featurecollection(lawn_data$points_average) %>% view
#' lawn_center(lawn_data$points_average) %>% view
#' }
lawn_center <- function(features, lint = FALSE) {
lawn_center <- function(features, properties = NULL, lint = FALSE) {
features <- convert(features)
lawnlint(features, lint)
ct$eval(sprintf("var cent = turf.center(%s);", features))
ct$eval(sprintf("var cent = turf.center(%s, %s);", features, toj(properties)))
structure(ct$get("cent"), class = "point")
}
10 changes: 6 additions & 4 deletions R/centroid.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#'
#' @export
#'
#' @param features Input features.
#' @param features Input features, as a [data-Feature].
#' @param properties A list of properties. Default: `NULL`
#' @template lint
#' @family measurements
#' @return Feature - centroid of the input features
#' @return a [data-Feature] - centroid of the input features
#' @examples
#' poly <- '{
#' "type": "Feature",
Expand All @@ -26,9 +27,10 @@
#' }
#' }'
#' lawn_centroid(features = poly)
lawn_centroid <- function(features, lint = FALSE) {
#' lawn_centroid(features = poly, properties = list(foo = "bar"))
lawn_centroid <- function(features, properties = NULL, lint = FALSE) {
fts <- convert(features)
lawnlint(fts, lint)
ct$eval(sprintf("var ctr = turf.centroid(%s);", fts))
ct$eval(sprintf("var ctr = turf.centroid(%s, %s);", fts, toj(properties)))
structure(ct$get("ctr"), class = "point")
}
6 changes: 5 additions & 1 deletion man/lawn_center.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions man/lawn_centroid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 35b8a00

Please sign in to comment.