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

Commit

Permalink
fix #74, added boolean_wihtin and lawn_pt2line_distance
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Sep 15, 2017
1 parent 73395f0 commit a2cacc2
Show file tree
Hide file tree
Showing 27 changed files with 183 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export(lawn_boolean_crosses)
export(lawn_boolean_disjoint)
export(lawn_boolean_overlap)
export(lawn_boolean_pointonline)
export(lawn_boolean_within)
export(lawn_buffer)
export(lawn_center)
export(lawn_center_of_mass)
Expand Down Expand Up @@ -133,6 +134,7 @@ export(lawn_point_on_line)
export(lawn_point_on_surface)
export(lawn_polygon)
export(lawn_propeach)
export(lawn_pt2line_distance)
export(lawn_random)
export(lawn_remove)
export(lawn_rewind)
Expand Down
19 changes: 19 additions & 0 deletions R/boolean_within.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' Boolean within
#'
#' returns `TRUE` if the first geometry is completely within the second
#' geometry
#'
#' @export
#' @param feature1,feature2 any [data-Geometry]/[data-Feature] objects
#' @family boolean functions
#' @return a logical (`TRUE`/`FALSE`)
#' @examples
#' pt1 <- '[1, 2]'
#' l1 <- '[[1, 1], [1, 2], [1, 3], [1, 4]]'
#' lawn_boolean_within(lawn_point(pt1), lawn_linestring(l1))
lawn_boolean_within <- function(feature1, feature2, lint = FALSE) {
lawnlint(list(feature1, feature2), lint)
ct$eval(sprintf("var bdj = turf.booleanWithin(%s, %s);",
convert(feature1), convert(feature2)))
ct$get("bdj")
}
40 changes: 40 additions & 0 deletions R/point_pt2line_distance.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Minimum distance between a point and a lineString
#'
#' Returns the minimum distance between a [data-Point] and a [data-LineString],
#' being the distance from a line the minimum distance between the
#' point and any segment of the LineString.
#'
#' @export
#' @param point ([data-Feature]<([data-Point])>) feature or geometry
#' @param line Line to measure, a [data-Feature]<([data-LineString])>,
#' or [data-FeatureCollection]<([data-LineString])>
#' @param units (character) Can be degrees, radians, miles, or kilometers
#' (default)
#' @param mercator (logical) if distance should be on Mercator or WGS84
#' projection. Default: `FALSE`
#' @template lint
#' @family measurements
#' @return distance between point and line (numeric)
#' @examples
#' pt <- lawn_point("[0, 0]")
#' ln <- lawn_linestring("[[1, 1],[-1, 1]]")
#'
#' lawn_pt2line_distance(pt, ln)
#' lawn_pt2line_distance(pt, ln, mercator = TRUE)
#'
#' lawn_pt2line_distance(pt, ln, 'miles')
#' lawn_pt2line_distance(pt, ln, 'radians')
#' lawn_pt2line_distance(pt, ln, 'degrees')
#' lawn_pt2line_distance(pt, ln, mercator = TRUE)
lawn_pt2line_distance <- function(point, line, units = "kilometers",
mercator = FALSE, lint = FALSE) {

point <- convert(point)
line <- convert(line)
lawnlint(list(point, line), lint)
assert(units, "character")
assert(mercator, "logical")
ct$eval(sprintf("var xxx = turf.pointToLineDistance(%s, %s, '%s', %s);",
point, line, units, convert(mercator)))
ct$get("xxx")
}
1 change: 1 addition & 0 deletions man/lawn_along.Rd

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

1 change: 1 addition & 0 deletions man/lawn_area.Rd

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

1 change: 1 addition & 0 deletions man/lawn_bbox.Rd

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

1 change: 1 addition & 0 deletions man/lawn_bbox_polygon.Rd

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

1 change: 1 addition & 0 deletions man/lawn_bearing.Rd

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

3 changes: 2 additions & 1 deletion man/lawn_boolean_clockwise.Rd

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

3 changes: 2 additions & 1 deletion man/lawn_boolean_contains.Rd

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

3 changes: 2 additions & 1 deletion man/lawn_boolean_crosses.Rd

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

3 changes: 2 additions & 1 deletion man/lawn_boolean_disjoint.Rd

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

3 changes: 2 additions & 1 deletion man/lawn_boolean_overlap.Rd

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

3 changes: 2 additions & 1 deletion man/lawn_boolean_pointonline.Rd

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

31 changes: 31 additions & 0 deletions man/lawn_boolean_within.Rd

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

1 change: 1 addition & 0 deletions man/lawn_center.Rd

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

1 change: 1 addition & 0 deletions man/lawn_center_of_mass.Rd

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

1 change: 1 addition & 0 deletions man/lawn_centroid.Rd

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

1 change: 1 addition & 0 deletions man/lawn_destination.Rd

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

1 change: 1 addition & 0 deletions man/lawn_distance.Rd

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

1 change: 1 addition & 0 deletions man/lawn_envelope.Rd

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

1 change: 1 addition & 0 deletions man/lawn_extent.Rd

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

1 change: 1 addition & 0 deletions man/lawn_line_distance.Rd

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

1 change: 1 addition & 0 deletions man/lawn_midpoint.Rd

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

4 changes: 3 additions & 1 deletion man/lawn_point_on_surface.Rd

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

60 changes: 60 additions & 0 deletions man/lawn_pt2line_distance.Rd

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

3 changes: 2 additions & 1 deletion man/lawn_square.Rd

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

0 comments on commit a2cacc2

Please sign in to comment.