Geocalc v0.6.0 Geocalc View Source

Calculate distance, bearing and more between Latitude/Longitude points.

Link to this section Summary

Functions

Calculates bearing. Return radians

Calculates a bounding box around a point with a radius in meters Returns an array with 2 points (list format). The bottom left point, and the top-right one

Compute distance from the point to great circle defined by start-point and end-point. Return distance in meters

Returns the pair of meridians at which a great circle defined by two points crosses the given latitude. Return longitudes

Converts degrees to radians. Return radians

Finds point between start and end points in direction to end point with given distance (in meters). Finds point from start point with given distance (in meters) and bearing. Return array with latitude and longitude

Calculates distance between 2 points. Return distance in meters

Compute the geographic center (aka geographic midpoint, center of gravity) for an array of geocoded objects and/or [lat,lon] arrays (can be mixed). Any objects missing coordinates are ignored. Follows the procedure documented at http://www.geomidpoint.com/calculation.html

Finds intersection point from start points with given bearings. Return array with latitude and longitude. Raise an exception if no intersection point found

Returns maximum latitude reached when travelling on a great circle on given bearing from the point (Clairaut’s formula). Negate the result for the minimum latitude (in the Southern hemisphere). The maximum latitude is independent of longitude; it will be the same for all points on a given latitude. Return radians

Converts radians to degrees. Return degrees

Link to this section Functions

Link to this function bearing(point_1, point_2) View Source
bearing(Geocalc.Point.t(), Geocalc.Point.t()) :: number()

Calculates bearing. Return radians.

Example

iex> berlin = {52.5075419, 13.4251364}
iex> paris = {48.8588589, 2.3475569}
iex> Geocalc.bearing(berlin, paris)
-1.9739245359361486
iex> Geocalc.bearing(paris, berlin)
1.0178267866082613

Example

iex> berlin = %{lat: 52.5075419, lon: 13.4251364}
iex> paris = %{latitude: 48.8588589, longitude: 2.3475569}
iex> Geocalc.bearing(berlin, paris)
-1.9739245359361486
Link to this function bounding_box(point, radius_in_m) View Source
bounding_box(Geocalc.Point.t(), number()) :: list()

Calculates a bounding box around a point with a radius in meters Returns an array with 2 points (list format). The bottom left point, and the top-right one

Example

iex> berlin = [52.5075419, 13.4251364]
iex> radius = 10_000
iex> Geocalc.bounding_box(berlin, radius)
[[52.417520954378574, 13.277235453275123], [52.59756284562143, 13.573037346724874]]
Link to this function cross_track_distance_to(point, path_start_point, path_end_point) View Source
cross_track_distance_to(Geocalc.Point.t(), Geocalc.Point.t(), Geocalc.Point.t()) :: number()

Compute distance from the point to great circle defined by start-point and end-point. Return distance in meters.

Example

iex> berlin = [52.5075419, 13.4251364]
iex> london = [51.5286416, -0.1015987]
iex> paris = [48.8588589, 2.3475569]
iex> Geocalc.cross_track_distance_to(berlin, london, paris)
-877680.2992295175
Link to this function crossing_parallels(point_1, path_2, latitude) View Source
crossing_parallels(Geocalc.Point.t(), Geocalc.Point.t(), number()) :: number()

Returns the pair of meridians at which a great circle defined by two points crosses the given latitude. Return longitudes.

Example

iex> berlin = [52.5075419, 13.4251364]
iex> paris = [48.8588589, 2.3475569]
iex> Geocalc.crossing_parallels(berlin, paris, 12.3456)
{:ok, 123.179463369946, -39.81144878508576}

Example

iex> point_1 = %{lat: 0, lng: 0}
iex> point_2 = %{lat: -180, lng: -90}
iex> latitude = 45.0
iex> Geocalc.crossing_parallels(point_1, point_2, latitude)
{:error, "Not found"}
Link to this function degrees_to_radians(degrees) View Source
degrees_to_radians(number()) :: number()

Converts degrees to radians. Return radians.

Example

iex> Geocalc.degrees_to_radians(143.67156782221554)
2.5075419

Example

iex> Geocalc.degrees_to_radians(-10.735322818996854)
-0.18736672945597435
Link to this function destination_point(point_1, point_2, distance) View Source
destination_point(Geocalc.Point.t(), number(), number()) :: tuple()
destination_point(Geocalc.Point.t(), Geocalc.Point.t(), number()) :: tuple()

Finds point between start and end points in direction to end point with given distance (in meters). Finds point from start point with given distance (in meters) and bearing. Return array with latitude and longitude.

Example

iex> berlin = [52.5075419, 13.4251364]
iex> paris = [48.8588589, 2.3475569]
iex> bearing = Geocalc.bearing(berlin, paris)
iex> distance = 400_000
iex> Geocalc.destination_point(berlin, bearing, distance)
{:ok, [50.97658022467569, 8.165929595956982]}

Example

iex> zero_point = {0.0, 0.0}
iex> equator_degrees = 90.0
iex> equator_bearing = Geocalc.degrees_to_radians(equator_degrees)
iex> distance = 1_000_000
iex> Geocalc.destination_point(zero_point, equator_bearing, distance)
{:ok, [5.484172965344896e-16, 8.993216059187306]}

Example

iex> berlin = %{lat: 52.5075419, lon: 13.4251364}
iex> bearing = -1.9739245359361486
iex> distance = 100_000
iex> Geocalc.destination_point(berlin, bearing, distance)
{:ok, [52.147030316318904, 12.076990111001148]}

Example

iex> berlin = [52.5075419, 13.4251364]
iex> paris = [48.8588589, 2.3475569]
iex> distance = 250_000
iex> Geocalc.destination_point(berlin, paris, distance)
{:ok, [51.578054644172525, 10.096282782248409]}
Link to this function distance_between(point_1, point_2) View Source
distance_between(Geocalc.Point.t(), Geocalc.Point.t()) :: number()

Calculates distance between 2 points. Return distance in meters.

Example

iex> berlin = [52.5075419, 13.4251364]
iex> paris = [48.8588589, 2.3475569]
iex> Geocalc.distance_between(berlin, paris)
878327.4291149472
iex> Geocalc.distance_between(paris, berlin)
878327.4291149472

Example

iex> berlin = %{lat: 52.5075419, lon: 13.4251364}
iex> london = %{lat: 51.5286416, lng: -0.1015987}
iex> paris = %{latitude: 48.8588589, longitude: 2.3475569}
iex> Geocalc.distance_between(berlin, paris)
878327.4291149472
iex> Geocalc.distance_between(paris, london)
344229.88946533133
Link to this function geographic_center(points) View Source
geographic_center(list()) :: Geocalc.Point.t()

Compute the geographic center (aka geographic midpoint, center of gravity) for an array of geocoded objects and/or [lat,lon] arrays (can be mixed). Any objects missing coordinates are ignored. Follows the procedure documented at http://www.geomidpoint.com/calculation.html.

Example

iex> point_1 = [0, 0]
iex> point_2 = [0, 3]
iex> Geocalc.geographic_center([point_1, point_2])
[0.0, 1.5]
Link to this function intersection_point(point_1, bearing_1, point_2, bearing_2) View Source
intersection_point(Geocalc.Point.t(), number(), Geocalc.Point.t(), number()) :: tuple()
intersection_point(Geocalc.Point.t(), number(), Geocalc.Point.t(), Geocalc.Point.t()) :: tuple()
intersection_point(Geocalc.Point.t(), Geocalc.Point.t(), Geocalc.Point.t(), number()) :: tuple()
intersection_point(Geocalc.Point.t(), Geocalc.Point.t(), Geocalc.Point.t(), Geocalc.Point.t()) :: tuple()

Finds intersection point from start points with given bearings. Return array with latitude and longitude. Raise an exception if no intersection point found.

Example

iex> berlin = [52.5075419, 13.4251364]
iex> berlin_bearing = -2.102
iex> london = [51.5286416, -0.1015987]
iex> london_bearing = 1.502
iex> Geocalc.intersection_point(berlin, berlin_bearing, london, london_bearing)
{:ok, [51.49271112601574, 10.735322818996854]}

Example

iex> berlin = {52.5075419, 13.4251364}
iex> london = {51.5286416, -0.1015987}
iex> paris = {48.8588589, 2.3475569}
iex> Geocalc.intersection_point(berlin, london, paris, london)
{:ok, [51.5286416, -0.10159869999999019]}

Example

iex> berlin = %{lat: 52.5075419, lng: 13.4251364}
iex> bearing = Geocalc.degrees_to_radians(90.0)
iex> Geocalc.intersection_point(berlin, bearing, berlin, bearing)
{:error, "No intersection point found"}
Link to this function max_latitude(point, bearing) View Source
max_latitude(Geocalc.Point.t(), number()) :: number()

Returns maximum latitude reached when travelling on a great circle on given bearing from the point (Clairaut’s formula). Negate the result for the minimum latitude (in the Southern hemisphere). The maximum latitude is independent of longitude; it will be the same for all points on a given latitude. Return radians.

Example

iex> berlin = [52.5075419, 13.4251364]
iex> paris = [48.8588589, 2.3475569]
iex> bearing = Geocalc.bearing(berlin, paris)
iex> Geocalc.max_latitude(berlin, bearing)
55.953467429882835
Link to this function radians_to_degrees(radians) View Source
radians_to_degrees(number()) :: number()

Converts radians to degrees. Return degrees.

Example

iex> Geocalc.radians_to_degrees(2.5075419)
143.67156782221554

Example

iex> Geocalc.radians_to_degrees(-0.1015987)
-5.821176714015797