-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ruODK v0.9.1: patch geotrace/geoshape coords
* Closes #88 * Include test data snapshot with "bad" coordinates * Test that bad coords are fixed, good coords kept * Update news, citation, codemeta * Add vignette "Spatial"
- Loading branch information
Florian Mayer
authored and
Florian Mayer
committed
Aug 10, 2020
1 parent
41b0527
commit 8bb9f8d
Showing
76 changed files
with
579 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#' Drop any NULL coordinates from a GeoJSON geometry. | ||
#' | ||
#' This helper patches a bug/feature in ODK Central (versions 0.7-0.9), where | ||
#' geotrace / geoshape GeoJSON contains a last coordinate pair with NULL | ||
#' lat/lon (no alt/acc), and WKT ends in `, undefined NaN`. | ||
#' | ||
#' While \code{\link{split_geotrace}} and \code{\link{split_geoshape}} modify | ||
#' the WKT inline, it is more maintainable to separate the GeoJSON cleaner | ||
#' into this function. | ||
#' | ||
#' This helper drops the last element of a GeoJSON coordinate list if it is | ||
#' `list(NULL, NULL)`. | ||
#' | ||
#' @param x A GeoJSON geometry parsed as nested list. | ||
#' E.g. `geo_gj$path_location_path_gps`. | ||
#' @return The nested list minus the last element (if NULL). | ||
#' @family utilities | ||
#' @export | ||
#' @examples | ||
#' # A snapshot of geo data with trailing empty coordinates. | ||
#' data("geo_gj88") | ||
#' | ||
#' len_coords <- length(geo_gj88$path_location_path_gps[[1]]$coordinates) | ||
#' | ||
#' length(geo_gj88$path_location_path_gps[[1]]$coordinates[[len_coords]]) %>% | ||
#' testthat::expect_equal(2) | ||
#' | ||
#' geo_gj88$path_location_path_gps[[1]]$coordinates[[len_coords]][[1]] %>% | ||
#' testthat::expect_null() | ||
#' | ||
#' geo_gj88$path_location_path_gps[[1]]$coordinates[[len_coords]][[2]] %>% | ||
#' testthat::expect_null() | ||
#' | ||
#' # The last coordinate pair is a list(NULL, NULL). | ||
#' # Invalid coordinates like these are a choking hazard for geospatial | ||
#' # packages. We should remove them before we can convert ODK data into native | ||
#' # spatial formats, such as sf. | ||
#' str(geo_gj88$path_location_path_gps[[1]]$coordinates[[len_coords]]) | ||
#' | ||
#' geo_gj_repaired <- geo_gj88 %>% | ||
#' dplyr::mutate( | ||
#' path_location_path_gps = path_location_path_gps %>% | ||
#' purrr::map(drop_null_coords) | ||
#' ) | ||
#' | ||
#' len_coords_repaired <- length( | ||
#' geo_gj_repaired$path_location_path_gps[[1]]$coordinates | ||
#' ) | ||
#' testthat::expect_equal(len_coords_repaired + 1, len_coords) | ||
drop_null_coords <- function(x) { | ||
# Extract and simplify last coords. list(NULL, NULL) becomes list(). | ||
xx <- purrr::compact(x$coordinates[[length(x$coordinates)]]) | ||
# Remove empty coords by setting the entire list(NULL, NULL) to NULL. | ||
if (is.list(xx) && length(xx) == 0) { | ||
x$coordinates[[length(x$coordinates)]] <- NULL | ||
} | ||
x | ||
} | ||
|
||
# usethis::use_test("drop_null_coords") # nolint |
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Oops, something went wrong.