···
(** High-level Unix API for GPX operations *)
-
(** Result binding operators *)
-
let (let*) = Result.bind
(* Re-export IO module *)
···
| (Error e, _) | (_, Error e) -> Error (Gpx.Error.invalid_coordinate e)
-
(** Create simple track from coordinate list *)
-
let make_track_from_coords ~name coords =
-
let make_trkpt (lat, lon) =
-
match (Coordinate.latitude lat, Coordinate.longitude lon) with
-
| (Ok lat, Ok lon) -> Ok (Waypoint.make lat lon)
-
| (Error e, _) | (_, Error e) -> Error (Gpx.Error.invalid_coordinate e)
-
let rec convert_coords acc = function
-
| [] -> Ok (List.rev acc)
-
match make_trkpt coord with
-
| Ok trkpt -> convert_coords (trkpt :: acc) rest
-
let* _trkpts = convert_coords [] coords in
-
Ok (Track.make_from_coords ~name coords)
-
(** Create simple route from coordinate list *)
-
let make_route_from_coords ~name coords =
-
let make_rtept (lat, lon) =
-
match (Coordinate.latitude lat, Coordinate.longitude lon) with
-
| (Ok lat, Ok lon) -> Ok (Waypoint.make lat lon)
-
| (Error e, _) | (_, Error e) -> Error (Gpx.Error.invalid_coordinate e)
-
let rec convert_coords acc = function
-
| [] -> Ok (List.rev acc)
-
match make_rtept coord with
-
| Ok rtept -> convert_coords (rtept :: acc) rest
-
let* _rtepts = convert_coords [] coords in
-
Ok (Route.make_from_coords ~name coords)
-
(** Extract coordinates from waypoints *)
-
let waypoint_coords wpt = Waypoint.to_floats wpt
-
(** Extract coordinates from track *)
-
let track_coords track = Track.to_coords track
-
(** Extract coordinates from route *)
-
let route_coords route = Route.to_coords route
-
(** Count total points in GPX *)
-
let waypoints = Doc.waypoints gpx in
-
let routes = Doc.routes gpx in
-
let tracks = Doc.tracks gpx in
-
List.length waypoints +
-
List.fold_left (fun acc r -> acc + List.length (Route.points r)) 0 routes +
-
List.fold_left (fun acc t -> acc + Track.point_count t) 0 tracks
-
(** Get GPX statistics *)
-
let waypoints = Doc.waypoints gpx in
-
let routes = Doc.routes gpx in
-
let tracks = Doc.tracks gpx in
-
waypoint_count = List.length waypoints;
-
route_count = List.length routes;
-
track_count = List.length tracks;
-
total_points = count_points gpx;
-
has_elevation = List.exists (fun w -> Waypoint.elevation w <> None) waypoints;
-
has_time = List.exists (fun w -> Waypoint.time w <> None) waypoints;
(** Pretty print GPX statistics *)
-
let stats = stats gpx in
-
Printf.printf "GPX Statistics:\n";
-
Printf.printf " Waypoints: %d\n" stats.waypoint_count;
-
Printf.printf " Routes: %d\n" stats.route_count;
-
Printf.printf " Tracks: %d\n" stats.track_count;
-
Printf.printf " Total points: %d\n" stats.total_points;
-
Printf.printf " Has elevation data: %s\n" (if stats.has_elevation then "yes" else "no");
-
Printf.printf " Has time data: %s\n" (if stats.has_time then "yes" else "no")