-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create GeoJSON serializer and parser (#830)
* Create geojson serializer * Create geojson serializer tests * update serializers doc * add Josiah as contributor * add serializer_geojson to NAMESPACE * add geojsonsf to suggests * add geojson parser along tests * make requested adjustments to serializer and serializer test * add sf under suggest for tests * include namespace on geojson_sf call in tests Pass a non valid geojson value to the serializer. * Address requested changes in #830. - Update namespace w/ devtools::document() - Update news under "New features" - Move check for `geojsonsf` package to top of function - Add `application/vdn.geo+json` as valid content type Co-authored-by: josiahparry <josiah.parry@gmail.com>
- Loading branch information
1 parent
89b9730
commit 06e46f3
Showing
9 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
test_that("GeoJSON serializes properly", { | ||
skip_if_not_installed("geojsonsf") | ||
skip_if_not_installed("sf") | ||
|
||
# Objects taken from ?st_sf() examples. | ||
sfc <- sf::st_sfc(sf::st_point(1:2), sf::st_point(3:4)) | ||
sf <- sf::st_sf(a = 3:4, sfc) | ||
|
||
# Test sfc | ||
val <- serializer_geojson()(sfc, data.frame(), PlumberResponse$new(), stop) | ||
expect_equal(val$status, 200L) | ||
expect_equal(val$headers$`Content-Type`, "application/geo+json") | ||
expect_equal(val$body, geojsonsf::sfc_geojson(sfc)) | ||
|
||
# Test sf | ||
val <- serializer_geojson()(sf, data.frame(), PlumberResponse$new(), stop) | ||
expect_equal(val$status, 200L) | ||
expect_equal(val$headers$`Content-Type`, "application/geo+json") | ||
expect_equal(val$body, geojsonsf::sf_geojson(sf)) | ||
|
||
}) | ||
|
||
test_that("Errors call error handler", { | ||
skip_if_not_installed("geojsonsf") | ||
skip_if_not_installed("sf") | ||
|
||
errors <- 0 | ||
errHandler <- function(req, res, err){ | ||
errors <<- errors + 1 | ||
} | ||
|
||
expect_equal(errors, 0) | ||
serializer_geojson()(parse(text="h$534i} {!"), data.frame(), PlumberResponse$new(), errorHandler = errHandler) | ||
expect_equal(errors, 1) | ||
}) |