Good evening everybody,
I would like to suggest some improvement of the spatial data storage.
Actually, geopoint are stored into 4 attributes (longitude, latitude, elevation and accuracy), Geotrace and geoshape are stored in a text field. The format of that string is not so simple. The use of Well Known Text format could be a great enhancement. All the databases supported by odk do understand that GIS format. https://fr.wikipedia.org/wiki/Well-known_text
Actually we have to create some fun sql to get data into GIS Eneblad databases such as PostGIS :
CREATE OR REPLACE FUNCTION odk.geom_from_odk_to_postgis(LONG numeric, LAT numeric, GEOTRACE TEXT, GEOSHAPE TEXT)
RETURNS geometry(GEOMETRY,4326) AS
$$
WITH geom_from_odk AS
(
SELECT trim(COALESCE(NULLIF(trim(concat(LAT,' ',LONG),';'),' '),
GEOTRACE,
GEOSHAPE),';') as geom_odk
),
node_array AS (
SELECT geom_odk, unnest(string_to_array(btrim(geom_odk::text, ';'::text), ';'::text)) AS unnest,
array_length(string_to_array(btrim(geom_odk::text, ';'::text), ';'::text), 1) AS nb_points,
generate_series(1, array_length(string_to_array(btrim(geom_odk::text, ';'::text), ';'::text), 1)) AS ordre,
split_part(unnest(string_to_array(btrim(geom_odk::text, ';'::text), ';'::text)), ' '::text, 1)::numeric AS LAT,
split_part(unnest(string_to_array(btrim(geom_odk::text, ';'::text), ';'::text)), ' '::text, 2)::numeric AS long
FROM geom_from_odk
)--, geom AS (
SELECT
CASE
WHEN node_array.nb_points = 1 THEN st_union(st_setsrid(st_makepoint(node_array.long::double precision, node_array.lat::double precision), 4326))
WHEN st_isclosed(st_makeline(array_agg(st_setsrid(st_makepoint(node_array.long::double precision, node_array.lat::double precision), 4326) ORDER BY node_array.ordre))) IS FALSE THEN st_makeline(array_agg(st_setsrid(st_makepoint(node_array.long::double precision, node_array.lat::double precision), 4326) ORDER BY node_array.ordre))
WHEN st_isclosed(st_makeline(array_agg(st_setsrid(st_makepoint(node_array.long::double precision, node_array.lat::double precision), 4326) ORDER BY node_array.ordre))) AND node_array.nb_points > 3 THEN st_makepolygon(st_makeline(array_agg(st_setsrid(st_makepoint(node_array.long::double precision, node_array.lat::double precision), 4326) ORDER BY node_array.ordre)))
-- ELSE the polygon is invalid because made of 3 points, 1st and 3rd are the same so we create a linestring
ELSE st_makeline(array_agg(st_setsrid(st_makepoint(node_array.long::double precision, node_array.lat::double precision), 4326) ORDER BY node_array.ordre))
END AS geom
FROM node_array
GROUP BY node_array.nb_points;
$$
LANGUAGE sql VOLATILE
COST 100;
Spatial databases do have easy native functions to transform a wkt data into geometry. For example, in PostGIS the simple use of the ST_GeomFromText(geo_column) function should do the job
http://postgis.net/docs/ST_GeomFromText.html
Mysql do have the same : https://dev.mysql.com/doc/refman/5.7/en/gis-wkt-functions.html#function_st-geomfromtext
ODK Collect could become a great GIS Field tool !