ropensci / ruODK

ruODK: An R Client for the ODK Central API
https://docs.ropensci.org/ruODK/
GNU General Public License v3.0
42 stars 13 forks source link

ODK Central geoshapes and geotraces contain an empty last coordinate #88

Closed florianm closed 4 years ago

florianm commented 4 years ago

Problem

ODK Central geoshapes and geotraces contain an empty last coordinate. I'm relatively sure that the problem comes out of ODK Central, not ruODK. Neither geopoint nor the CSV AIP export are affected.

Even if ODK Central fix this issue in future releases, older versions will still export this empty last coordinate. ruODK should discard this empty last coordinate.

For WKT, that's relatively easily done with a stringr::str_replace_all(., ",undefined NaN", "") in split_geoshape / split_geotrace. For GJ, we need to drop the last list element in the GJ list column (need more coffee and a steady hand).

This problem came up while working on #87 following an email request by ruODK user Timon Weitkamp.

Reproducible example

Examples are found in package data (until this bug is fixed and package data are refreshed):

# WKT geoshape (polygon)
data("geo_wkt_raw", package="ruODK")
geo_wkt_raw$value[[1]]$shape$location_shape_gps
#> "POLYGON ((115.88551204651594 -31.998645069556574 0,115.88430408 -31.99588955 0,115.88552612811326 
#> -31.995722633177788 0,115.88456857949494 -31.994522126877417 0,115.88277518749237 -31.995364928301797 
#> 0,115.88551204651594 -31.998645069556574 0,undefined NaN))"

# WKT geotrace (polygon)
geo_wkt_raw$value[[1]]$path$location_path_gps
#> [1] "LINESTRING (115.88501214981079 -31.997176185855277 0,115.88591940701008 -31.995860539692956 
#> 0,115.88509060442449 -31.995041912207018 0,115.884690284729 -31.993920161739386 0,undefined NaN)"

# GJ shape (polygon)
data("geo_gj_raw", package="ruODK")
geo_gj_raw$value[[1]]$shape$location_shape_gps

#> ...
$coordinates[[6]]
$coordinates[[6]][[1]]
[1] 115.8855

$coordinates[[6]][[2]]
[1] -31.99865

$coordinates[[6]][[3]]
[1] 0

$coordinates[[7]]
$coordinates[[7]][[1]]
NULL

$coordinates[[7]][[2]]
NULL