ocat/storage: FEATURE: produce GPX output

closes #9
This commit is contained in:
Jan-Piet Mens
2015-08-29 21:11:03 +02:00
parent 54610a9332
commit 7145d5c11d
3 changed files with 50 additions and 0 deletions
+8
View File
@@ -108,6 +108,7 @@ void usage(char *prog)
printf(" --format json -f output format (default: JSON)\n");
printf(" csv (overrides $OCAT_FORMAT\n");
printf(" geojson\n");
printf(" gpx\n");
printf(" raw\n");
printf(" --fields tst,lat,lon,... Choose fields for CSV. (dflt: ALL)\n");
printf(" --last -L JSON object with last users\n");
@@ -205,6 +206,8 @@ int main(int argc, char **argv)
otype = GEOJSON;
else if (!strcmp(optarg, "raw"))
otype = RAW;
else if (!strcmp(optarg, "gpx"))
otype = GPX;
else if (!strcmp(optarg, "csv"))
otype = CSV;
else {
@@ -388,6 +391,11 @@ int main(int argc, char **argv)
}
json_delete(geojson);
}
} else if (otype == GPX) {
char *xml = gpx_string(locs);
if (xml)
printf("%s\n", xml);
}
json_delete(obj);
+40
View File
@@ -673,6 +673,46 @@ JsonNode *geo_json(JsonNode *location_array)
return (fcollection);
}
/*
* Turn our JSON location array into a GPX XML string.
*/
char *gpx_string(JsonNode *location_array)
{
JsonNode *one;
static UT_string *xml = NULL;
if (location_array->tag != JSON_ARRAY)
return (NULL);
utstring_renew(xml);
utstring_printf(xml, "%s", "<?xml version='1.0' encoding='UTF-8' standalone='no' ?>\n\
<gpx version='1.1' creator='OwnTracks-Recorder'>\n\
<trk>\n\
<trkseg>\n");
// <trkpt lat="xx.xxx" lon="yy.yyy"> <!-- Attribute des Trackpunkts --> </trkpt>
json_foreach(one, location_array) {
double lat = 0.0, lon = 0.0;
JsonNode *j;
if ((j = json_find_member(one, "lat")) != NULL) {
lat = j->number_;
}
if ((j = json_find_member(one, "lon")) != NULL) {
lon = j->number_;
}
utstring_printf(xml, "<trkpt lat='%lf' lon='%lf' />\n", lat, lon);
}
utstring_printf(xml, "%s", " </trkseg>\n</trk>\n</gpx>\n");
return (utstring_body(xml));
}
/*
* Remove all data for a user's device. Return a JSON object with a status
* and an array of deleted files.
+2
View File
@@ -9,6 +9,7 @@ typedef enum {
CSV,
JSON,
RAW,
GPX,
} output_type;
JsonNode *lister(char *username, char *device, time_t s_lo, time_t s_hi, int reverse);
@@ -17,5 +18,6 @@ int make_times(char *time_from, time_t *s_lo, char *time_to, time_t *s_to);
JsonNode *geo_json(JsonNode *json);
JsonNode *kill_datastore(char *username, char *device);
JsonNode *last_users();
char *gpx_string(JsonNode *json);
#endif