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

Handle all location types: geopoint, geotrace, geoshape #69

Closed florianm closed 4 years ago

florianm commented 4 years ago

Spatial musings

ODK Collect can capture points (geopoints), lines (geotrace), and polygons (geoshape). ODK Central's 0.7 OData submissions export geopoints either as GeoJSON (ODK Central and ruODK default) or WKT. ODK Central's 0.7 OData submissions export geotrace and geoshape always as GeoJSON. Since v0.8, GeoJSON and WKT export seems to work across all geo field types.

What does a data analyst want to do with each location type? How much parsing should ruODK provide? As a data analyst, I need to:

Which formats should ruODK output:

Implementation

Current behaviour

Suggested new behaviour (discuss)

Probably out of scope

Challenges

odata_submission_rectangle needs to exempt geo{point, trace, shape} from unnesting

odata_submission_rectangle will blindly (as it has no form introspection ...yet) unnest any list column. This works OK-ish for GeoJSON points as these have a set length. Unnesting geotraces and geoshapes will inevitably end in tears over their variable number of points.

This means that odata_submission_get(parse = TRUE, wkt = FALSE) will fail with geotraces or geoshapes.

Therefore odata_submission_rectangle needs a parameter form_schema = NULL to pass an optional form schema, extract field names of geo{point, trace, shape}s, and exempt those from rectangling. This would preserve GeoJSON and parse GeoJSON into list columns, which then could be further parsed into spatial classes.

Getting too funky with spatial classes will add dependencies

Downside: sf, st, rgdal, rgeos dependencies could be a pain for users to install.

Upside: Adding some nice helpers and working examples (mapping, spatial operations, coordinate extraction) would be immensely useful to less spatially versed R users.

Testing

Test form: https://sandbox.central.getodk.org/#/projects/14/forms/build_Locations_1589344221/submissions

Added to CONTRIBUTING.md / Test:

ODKC_TEST_FID_WKT="build_Locations_1589344221"

As DBCA still runs a production server on ODK Central v0.6, and the spatial output has changed since then, I will address this issue after migrating our server. ETA mid 2020.

Checklist

Once spatial parsing has changed, make sure to update all the docs and examples.

florianm commented 4 years ago

Current status:

This issue could make it into https://github.com/ropensci/software-review/issues/335