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

Commit

Permalink
added all boolean functions, #73
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Sep 14, 2017
1 parent 818273f commit bf4dea8
Show file tree
Hide file tree
Showing 13 changed files with 294 additions and 0 deletions.
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ export(lawn_bbox)
export(lawn_bbox_polygon)
export(lawn_bearing)
export(lawn_bezier)
export(lawn_boolean_clockwise)
export(lawn_boolean_contains)
export(lawn_boolean_crosses)
export(lawn_boolean_disjoint)
export(lawn_boolean_overlap)
export(lawn_boolean_pointonline)
export(lawn_buffer)
export(lawn_center)
export(lawn_center_of_mass)
Expand Down
16 changes: 16 additions & 0 deletions R/boolean_clockwise.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' Boolean clockwise
#'
#' @export
#' @param line line [data-Feature]<([data-LineString])>
#' @family boolean functions
#' @return a logical (`TRUE`/`FALSE`)
#' @examples
#' l1 <- '[[0,0],[1,1],[1,0],[0,0]]'
#' l2 <- '[[0,0],[1,0],[1,1],[0,0]]'
#' lawn_boolean_clockwise(lawn_linestring(l1))
#' lawn_boolean_clockwise(lawn_linestring(l2))
lawn_boolean_clockwise <- function(line, lint = FALSE) {
lawnlint(line, lint)
ct$eval(sprintf("var bcw = turf.booleanClockwise(%s);", convert(line)))
ct$get("bcw")
}
16 changes: 16 additions & 0 deletions R/boolean_contains.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' Boolean contains
#'
#' @export
#' @param feature1,feature2 any [data-Geometry]/[data-Feature] objects
#' @family boolean functions
#' @return a logical (`TRUE`/`FALSE`)
#' @examples
#' l1 <- '[[1, 1], [1, 2], [1, 3], [1, 4]]'
#' pt1 <- '[1, 2]'
#' lawn_boolean_contains(feature1=lawn_linestring(l1), feature2=lawn_point(pt1))
lawn_boolean_contains <- function(feature1, feature2, lint = FALSE) {
lawnlint(list(feature1, feature2), lint)
ct$eval(sprintf("var bcon = turf.booleanContains(%s, %s);",
convert(feature1), convert(feature2)))
ct$get("bcon")
}
16 changes: 16 additions & 0 deletions R/boolean_crosses.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' Boolean crosses
#'
#' @export
#' @param feature1,feature2 any [data-Geometry]/[data-Feature] objects
#' @family boolean functions
#' @return a logical (`TRUE`/`FALSE`)
#' @examples
#' l1 <- '[[-2, 2], [4, 2]]'
#' l2 <- '[[1, 1], [1, 2], [1, 3], [1, 4]]'
#' lawn_boolean_crosses(lawn_linestring(l1), lawn_linestring(l2))
lawn_boolean_crosses <- function(feature1, feature2, lint = FALSE) {
lawnlint(list(feature1, feature2), lint)
ct$eval(sprintf("var bcr = turf.booleanCrosses(%s, %s);",
convert(feature1), convert(feature2)))
ct$get("bcr")
}
16 changes: 16 additions & 0 deletions R/boolean_disjoint.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' Boolean crosses
#'
#' @export
#' @param feature1,feature2 any [data-Geometry]/[data-Feature] objects
#' @family boolean functions
#' @return a logical (`TRUE`/`FALSE`)
#' @examples
#' pt1 <- '[2, 2]'
#' l1 <- '[[1, 1], [1, 2], [1, 3], [1, 4]]'
#' lawn_boolean_disjoint(lawn_point(pt1), lawn_linestring(l2))
lawn_boolean_disjoint <- function(feature1, feature2, lint = FALSE) {
lawnlint(list(feature1, feature2), lint)
ct$eval(sprintf("var bdj = turf.booleanDisjoint(%s, %s);",
convert(feature1), convert(feature2)))
ct$get("bdj")
}
20 changes: 20 additions & 0 deletions R/boolean_overlap.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#' Boolean overlap
#'
#' @export
#' @param feature1,feature2 any [data-Geometry]/[data-Feature](
#' <[data-LineString]|[data-MultiLineString]|[data-Polygon]|[data-MultiPolygon])
#' objects
#' @family boolean functions
#' @return a logical (`TRUE`/`FALSE`)
#' @examples
#' poly1 <- "[[[0,0],[0,5],[5,5],[5,0],[0,0]]]"
#' poly2 <- "[[[1,1],[1,6],[6,6],[6,1],[1,1]]]"
#' poly3 <- "[[[10,10],[10,15],[15,15],[15,10],[10,10]]]"
#' lawn_boolean_overlap(lawn_polygon(poly1), lawn_polygon(poly2))
#' lawn_boolean_overlap(lawn_polygon(poly2), lawn_polygon(poly3))
lawn_boolean_overlap <- function(feature1, feature2, lint = FALSE) {
lawnlint(list(feature1, feature2), lint)
ct$eval(sprintf("var bover = turf.booleanOverlap(%s, %s);",
convert(feature1), convert(feature2)))
ct$get("bover")
}
21 changes: 21 additions & 0 deletions R/boolean_pointonline.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' Boolean overlap
#'
#' @export
#' @param point any [data-Geometry]/[data-Feature](<[data-Point]>)
#' @param linestring any [data-Geometry]/[data-Feature](<[data-LineString]>)
#' @param ignoreEndVertices (logical) whether to ignore the start and end
#' vertices. Default: `FALSE
#' @family boolean functions
#' @return a logical (`TRUE`/`FALSE`)
#' @examples
#' l1 <- "[[-1, -1],[1, 1],[1.5, 2.2]]"
#' lawn_boolean_pointonline(lawn_point("[0, 0]"), lawn_linestring(l1))
lawn_boolean_pointonline <- function(point, linestring,
ignoreEndVertices = FALSE, lint = FALSE) {

lawnlint(list(point, linestring), lint)
ct$eval(sprintf("var bpol = turf.booleanPointOnLine(%s, %s, %s);",
convert(point), convert(linestring),
convert(ignoreEndVertices)))
ct$get("bpol")
}
30 changes: 30 additions & 0 deletions man/lawn_boolean_clockwise.Rd

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

29 changes: 29 additions & 0 deletions man/lawn_boolean_contains.Rd

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

29 changes: 29 additions & 0 deletions man/lawn_boolean_crosses.Rd

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

29 changes: 29 additions & 0 deletions man/lawn_boolean_disjoint.Rd

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

32 changes: 32 additions & 0 deletions man/lawn_boolean_overlap.Rd

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

34 changes: 34 additions & 0 deletions man/lawn_boolean_pointonline.Rd

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

0 comments on commit bf4dea8

Please sign in to comment.