Prepare and Export Survey Sample Points for CAPI Fieldwork Apps
Source:R/vantor_fieldwork.R
vantor_export_capi.RdEnriches a set of survey sample locations (sf points or polygons, such as
household structures, enumeration clusters, or ground-truth plots) with
navigation and preload fields ready for ODK Collect, KoboToolbox,
ArcGIS Survey123, World Bank Survey Solutions, and QField:
sample_id: Unique formatted sample identifierlongitude,latitude: WGS84 decimal degree coordinatesodk_geopoint: Preload string ("<lat> <lon> 0 0") used by ODK / Kobogeopointquestionsplus_code: Offline-capable 10-character Google Plus Code viavantor_plus_code()google_maps_url: One-click navigation link for mobile enumeratorsOptional grid cell assignment (
cell_id) if agridfromvantor_survey_grid()is suppliedOptional imagery vintage metadata (
acq_date,sensor,gsd_m) ifseamlinesare supplied
Usage
vantor_export_capi(
samples,
id_col = NULL,
grid = NULL,
seamlines = NULL,
output_csv = NULL,
output_geojson = NULL,
output_suso_tab = NULL,
suso_gps_var = NULL,
verbose = getOption("vantorr.verbose", TRUE)
)Arguments
- samples
An
sfobject (POINTorPOLYGON; polygons are converted to representative points viasf::st_point_on_surface()).- id_col
Character string. Optional existing column name in
samplesto use assample_id. IfNULL, generates sequential IDs ("S001","S002", ...).- grid
Optional
sfgrid fromvantor_survey_grid()used to assign each sample to its Enumeration Area / gridcell_id.- seamlines
Optional
sfseamline polygons fromvantor_get_seamlines()used to attach imagery vintage (imagery_acq_date,imagery_sensor) to each sample point.- output_csv
Optional file path to write a CSV preload table (for ODK Collect, KoboToolbox, and ArcGIS Survey123). Default is
NULL.- output_geojson
Optional file path to write a GeoJSON file for mobile GIS map overlays (QField, Mergin Maps). Default is
NULL.- output_suso_tab
Optional file path to write a tab-delimited (
.tab) assignment preload file formatted for World Bank Survey Solutions Headquarters (Upload Assignments). Includes composite GPS columns (<suso_gps_var>__Latitudeand<suso_gps_var>__Longitude) so sampled structures appear as interactive pins on the Interviewer tablet Map Dashboard over the.tpkbasemap, plus_target_area(fromcell_id),plus_code, andimagery_acq_date. Default isNULL.- suso_gps_var
Optional character string. Variable name of the identifying GPS question in Survey Solutions Designer (e.g.,
"hh_gps"). When provided (or whenoutput_suso_tabis set), the coordinate columns on both the returnedsfobject and the exported.tabfile are named<suso_gps_var>__Latitudeand<suso_gps_var>__Longitudeinstead oflatitudeandlongitude. Default isNULL(uses"hh_gps"automatically whenoutput_suso_tabis supplied).- verbose
Logical. Print progress messages. Default is
getOption("vantorr.verbose", TRUE).
Details
Optionally writes the enriched dataset to a CSV preload table (output_csv)
and/or a GeoJSON file (output_geojson).
Examples
pts <- sf::st_as_sf(
data.frame(
hh_id = c("HH_01", "HH_02"),
lon = c(-105.005, -105.002),
lat = c(39.735, 39.738)
),
coords = c("lon", "lat"),
crs = 4326
)
capi_sf <- vantor_export_capi(pts, id_col = "hh_id", suso_gps_var = "hh_gps", verbose = FALSE)
head(capi_sf)
#> Simple feature collection with 2 features and 7 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -105.005 ymin: 39.735 xmax: -105.002 ymax: 39.738
#> Geodetic CRS: WGS 84
#> hh_id geometry sample_id hh_gps__Latitude hh_gps__Longitude
#> 1 HH_01 POINT (-105.005 39.735) HH_01 39.735 -105.005
#> 2 HH_02 POINT (-105.002 39.738) HH_02 39.738 -105.002
#> odk_geopoint plus_code
#> 1 39.735000 -105.005000 0 0 85FPPXPW+22
#> 2 39.738000 -105.002000 0 0 85FPPXQX+66
#> google_maps_url
#> 1 https://www.google.com/maps/search/?api=1&query=39.735000,-105.005000
#> 2 https://www.google.com/maps/search/?api=1&query=39.738000,-105.002000