mirror of
https://github.com/owntracks/recorder.git
synced 2026-08-23 11:26:16 +00:00
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user