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
.
Details
While split_geotrace
and 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)
.
See also
Other utilities:
attachment_get()
,
attachment_link()
,
attachment_url()
,
form_schema_parse()
,
get_one_attachment()
,
get_one_submission()
,
get_one_submission_att_list()
,
get_one_submission_audit()
,
handle_ru_attachments()
,
handle_ru_datetimes()
,
handle_ru_geopoints()
,
handle_ru_geoshapes()
,
handle_ru_geotraces()
,
isodt_to_local()
,
odata_submission_rectangle()
,
predict_ruodk_name()
,
prepend_uuid()
,
split_geopoint()
,
split_geoshape()
,
split_geotrace()
,
strip_uuid()
,
tidyeval
,
unnest_all()
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]])
#> List of 2
#> $ : NULL
#> $ : NULL
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)