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

Commit

Permalink
fixes to some functions for integrating new turfjs
Browse files Browse the repository at this point in the history
using turf 4.7.3 now
fix tests for turf 4.7.3
  • Loading branch information
sckott committed Sep 14, 2017
1 parent fb245ce commit 150e413
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 20 deletions.
2 changes: 1 addition & 1 deletion R/as.feature.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#' }'
#' as.feature(line)
#'
#' # returns self if no match - note "Points" is not a geojson type
#' # returns self if no match - note "Points" is not a GeoJSON type
#' pt <- '{"type":"Points","coordinates":[-75.343,39.984]}'
#' as.feature(pt)
as.feature <- function(x, ...) {
Expand Down
6 changes: 3 additions & 3 deletions R/isolines.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#' @family interpolation
#' @return A [data-FeatureCollection] of isolines
#' ([data-LineString] features).
#' @examples
#' @details Warning: this function seems to be broken, not sure why
#' @examples \dontrun{
#' # pts <- lawn_random(n = 100, bbox = c(0, 30, 20, 50))
#' pts <- lawn_point_grid(c(0, 30, 20, 50), 100, 'miles')
#' pts$features$properties <-
Expand All @@ -28,10 +29,9 @@
#' breaks <- c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
#' lawn_isolines(points = pts, breaks, z = 'temperature')
#'
#' @examples \dontrun{
#' lawn_isolines(pts, breaks, 'temperature') %>% view
#' }
lawn_isolines <- function(points, breaks, z, propertiesToAllIsolines = NULL,
lawn_isolines <- function(points, breaks, z, propertiesToAllIsolines = c(),
propertiesPerIsoline = list(), resolution = NULL,
lint = FALSE) {
calls <- names(sapply(match.call(), deparse))[-1]
Expand Down
2 changes: 1 addition & 1 deletion R/lawn_feature.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' )
#' lapply(pts, lawn_feature)
#' }
lawn_feature <- function(geometry, properties = list(), lint = FALSE) {
lawn_feature <- function(geometry, properties = c(), lint = FALSE) {
lawnlint(geometry, lint)
ct$eval(sprintf("var feet = turf.feature(%s, %s);",
convert(geometry), convert(properties)))
Expand Down
2 changes: 1 addition & 1 deletion R/onLoad.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ht <- NULL

.onLoad <- function(libname, pkgname){
ct <<- V8::v8();
ct$source(system.file("js/turf452.js", package = pkgname))
ct$source(system.file("js/turf473.js", package = pkgname))
ct$source(system.file("js/turf-meta.js", package = pkgname))
ct$source(system.file("js/turf-invariant.js", package = pkgname))
ct$source(system.file("js/cloner.js", package = pkgname))
Expand Down
27 changes: 27 additions & 0 deletions inst/js/turf473.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion man/as.feature.Rd

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

2 changes: 1 addition & 1 deletion man/lawn_feature.Rd

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

7 changes: 5 additions & 2 deletions man/lawn_isolines.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-bbox_polygon.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test_that("lawn_bbox_polygon works", {

test_that("lawn_bbox_polygon fails correctly", {
expect_error(lawn_bbox_polygon(), "argument \"bbox\" is missing, with no default")
expect_true(is.na(lawn_bbox_polygon(1)$geometry$coordinates[,,1][1]))
expect_error(lawn_bbox_polygon(1), "Coordinates must contain numbers")
expect_error(lawn_bbox_polygon(c("1", 2, 3, 4)), "All values must be numeric")
expect_error(lawn_bbox_polygon(c("a", "b", "c", "d")), "All values must be numeric")
})
2 changes: 1 addition & 1 deletion tests/testthat/test-erase.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ test_that("lawn_erase fails correctly", {
expect_error(lawn_erase(), "argument \"poly1\" is missing, with no default")
expect_error(lawn_erase("A", "B"), "A is not defined")
expect_error(lawn_erase(poly1, "{}"),
"<geojson> must be a Feature or Geometry Object")
"geojson must be a valid Feature or Geometry Object")
expect_error(lawn_erase(poly1, "{}", lint = TRUE),
"member required")
expect_error(lawn_erase(poly1, "{}", lint = TRUE), "\"type\" member required")
Expand Down
12 changes: 8 additions & 4 deletions tests/testthat/test-intersect.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ test_that("works returns correct classes", {
})

test_that("fails correctly", {
expect_error(lawn_intersect(), "argument \"poly1\" is missing, with no default")
expect_error(lawn_intersect(),
"argument \"poly1\" is missing, with no default")
expect_error(lawn_intersect(lawn_data$points_average, lawn_data$points_count),
"has no method 'intersection'")
expect_error(lawn_intersect(poly1, sub("Polygon", "polygon", poly2)), "Unknown GeoJSON type: polygon")
expect_error(lawn_intersect(poly1, sub("Feature", "feature", poly2)), "Unknown GeoJSON type: feature")
expect_error(lawn_intersect(poly1, sub("coordinates", "cordinates", poly2)), "Cannot read property '0' of undefined")
expect_error(lawn_intersect(poly1, sub("Polygon", "polygon", poly2)),
"Unknown Geometry Type")
expect_error(lawn_intersect(poly1, sub("Feature", "feature", poly2)),
"Unknown Geometry Type")
expect_error(lawn_intersect(poly1, sub("coordinates", "cordinates", poly2)),
"Cannot read property 'length' of undefined")
})
6 changes: 4 additions & 2 deletions tests/testthat/test-point_on_line.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ test_that("lawn_point_on_line works", {
})

test_that("lawn_point_on_line fails correctly", {
expect_error(lawn_point_on_line(), "argument \"line\" is missing, with no default")
expect_error(lawn_point_on_line(5, TRUE), "input must be a LineString Feature or Geometry")
expect_error(lawn_point_on_line(),
"argument \"line\" is missing, with no default")
expect_error(lawn_point_on_line(5, TRUE),
"lines must be LineString or MultiLineString")
})
2 changes: 1 addition & 1 deletion tests/testthat/test-simplify.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ test_that("lawn_simplify fails correctly", {
# missing arguments
expect_error(lawn_simplify(), "argument \"feature\" is missing, with no default")
# wrong input object
expect_error(lawn_simplify("{}"), "Cannot read property")
expect_error(lawn_simplify("{}"), "unknown GeoJSON type")
# can't pass in a character string to tolerance
expect_error(lawn_simplify(feature, "a"), "tolerance must be")
# can't pass in a non-logical to high_quality
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-transform_scale.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test_that("lawn_transform_scale fails correctly", {
expect_error(lawn_transform_scale(), "argument \"x\" is missing, with no default")
expect_error(lawn_transform_scale(5), "argument \"factor\" is missing, with no default")
expect_error(lawn_transform_scale(x, 5, "asdfasf"), "invalid origin")
expect_error(lawn_transform_scale(list(), 100), "Unknown Geometry Type")
expect_error(lawn_transform_scale(list(), 100), "unknown GeoJSON type")

expect_error(lawn_transform_scale(x, "adf"), "adf is not defined")
expect_error(lawn_transform_scale(x, 34, c(1, "ad")),
Expand Down

0 comments on commit 150e413

Please sign in to comment.