package mlgpx

  1. Overview
  2. Docs

Module Gpx.CoordinateSource

Geographic coordinate handling with validation

The Coordinate module provides validated coordinate types for latitude, longitude, and degrees. All coordinates use the WGS84 datum and are validated at construction time to ensure they fall within valid ranges:

  • Latitude: -90.0 to +90.0 degrees
  • Longitude: -180.0 to +180.0 degrees
  • Degrees: 0.0 to 360.0 degrees

Example: Coordinate.latitude 37.7749 creates a validated latitude.

Geographic coordinate types with validation

Sourcetype latitude = private float

Coordinate types with validation constraints

Sourcetype longitude = private float
Sourcetype degrees = private float
Sourcetype t = {
  1. lat : latitude;
  2. lon : longitude;
}

Coordinate pair

Constructors

Sourceval latitude : float -> (latitude, string) result

Create validated latitude.

  • parameter f

    Latitude in degrees (-90.0 to 90.0)

  • returns

    Ok latitude or Error msg

Sourceval longitude : float -> (longitude, string) result

Create validated longitude.

  • parameter f

    Longitude in degrees (-180.0 to 180.0)

  • returns

    Ok longitude or Error msg

Sourceval degrees : float -> (degrees, string) result

Create validated degrees.

  • parameter f

    Degrees (0.0 to 360.0)

  • returns

    Ok degrees or Error msg

Conversion Functions

Sourceval latitude_to_float : latitude -> float

Convert latitude to float

Sourceval longitude_to_float : longitude -> float

Convert longitude to float

Sourceval degrees_to_float : degrees -> float

Convert degrees to float

Operations

Sourceval make : latitude -> longitude -> t

Create coordinate pair from validated components

Sourceval make_from_floats : float -> float -> (t, string) result

Create coordinate pair from floats with validation

Sourceval lat : t -> latitude

Extract latitude component

Sourceval lon : t -> longitude

Extract longitude component

Sourceval to_floats : t -> float * float

Convert coordinate to float pair

Comparison and Printers

Sourceval compare : t -> t -> int

Compare two coordinates

Sourceval equal : t -> t -> bool

Test coordinate equality

Sourceval pp : Format.formatter -> t -> unit

Pretty print coordinate

OCaml

Innovation. Community. Security.