Common.PositionThis module deals with coordinates and conversion from and to different coordinate systems.
module type Unit = sig ... endIn order to avoid mixing up different unit, we introduce this module type. In practice, only floats are used internally, but the user can hide this fact to get stronger guarantees in their code, at the price of having to explicitly call the conversion functions.
module Units : sig ... endmodule Earth : sig ... endModel of the Earth
module type SphericalType = sig ... endSpherical coordinates (WGS 84, EPSG:4326)
module Spherical :
SphericalType
with module Meters = Units.Meters
and module Degrees = Units.Degrees
and module Radians = Units.RadiansIf one wants to hide the fact that Meters.t and Degrees.t are floats, one can cast it by locally defining module Spherical = Position.(Spherical : SphericalType).
We consider spherical coordinates as the default, as these are the coordinates used in OSM.
include module type of Sphericalmodule Meters = Units.Metersmodule Degrees = Units.Degreesmodule Radians = Units.RadiansThe (longitude, latitude) coordinates of each point, in degrees (following WGS 84's ellipsoid). North and East are positive.
Return an angle between -180 and 180 equivalent (modulo 360) to its argument.
normalise_angle_around a0 a returns an angle between a0 - 180 and a0 + 180 equivalent to its argument.
Similar functions but for radians instead of degrees.
val north_pole : tSome specific coordinates.
val south_pole : tval null_island : tval test_coordinates : t listSome specific coordinates, distances, and angles, for tests.
val test_angles : Degrees.t listval test_distances : Meters.t listval test_latitudes : Degrees.t listval antimeridian : Degrees.tValue of the longitude of the Antimeridian (that is, the 180th meridian).
Shortest distance between two points (around the world, as a great circle), in meters. In other words, the length of the geodesic between the provided two points. Several algorithms with various precision and computation speed can be used: it is assumed that long-distance measurements are rare and short-distance measurements frequent.
Computing the distance can be quite costly, despite the fact that we try to use appropriate algorithms depending on the situation. This function is less accurate than distance, but is faster.
In the rare cases in which precision is absolutely necessary, this function will choose the most appropriate algorithms to compute the distance without taking computation speed into account. It will always be slower than distance.
State whether the distance between two points is within the provided interval (bounds included). This should typically be faster than calling distance and comparing it to the associated bounds.
val longitude_meters_to_radians :
lat:Units.Degrees.t ->
Units.Meters.t ->
Units.Radians.tConversion of a distance in meters to the (assuming spherical Earth) corresponding angle of coordinates at the provided latitude, assuming it is taken parallel to the equator. The latitude is always expressed in degrees, even when converting to radians.
val longitude_meters_to_degrees :
lat:Units.Degrees.t ->
Units.Meters.t ->
Units.Degrees.tval latitude_meters_to_radians :
?lat:Units.Degrees.t ->
Units.Meters.t ->
Units.Radians.tSimilar, but with a distance taken perpendicular to the equator. The latitude is here optional as it doesn't change that much the result. Note that it must always be expressed in degrees, even in the conversion to radian.
val latitude_meters_to_degrees :
?lat:Units.Degrees.t ->
Units.Meters.t ->
Units.Degrees.tval longitude_radians_to_meters :
lat:Units.Degrees.t ->
Units.Radians.t ->
Units.Meters.tThe inverse functions.
val longitude_degrees_to_meters :
lat:Units.Degrees.t ->
Units.Degrees.t ->
Units.Meters.tval latitude_radians_to_meters :
?lat:Units.Degrees.t ->
Units.Radians.t ->
Units.Meters.tval latitude_degrees_to_meters :
?lat:Units.Degrees.t ->
Units.Degrees.t ->
Units.Meters.tval print : t -> stringPrint-out the coordinates, mainly for debugging purposes.
module Ops : sig ... endUseful operators to include when dealing with coordinates and distances.
Whether two floats are close enough (up to epsilon).
module TestOps : sig ... endOperators to be used for tests.