Geocalc v0.5.5 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
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
Converts radians to degrees. Return degrees
Called when an application is started
Link to this section Functions
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
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]]
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
destination_point(Geocalc.Point.t, Geocalc.Point.t, number) :: tuple
destination_point(Geocalc.Point.t, number, 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]}
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
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]
intersection_point(Geocalc.Point.t, Geocalc.Point.t, 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, number, Geocalc.Point.t, Geocalc.Point.t) :: tuple
intersection_point(Geocalc.Point.t, number, Geocalc.Point.t, number) :: 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"}
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
Called when an application is started.
This function is called when an application is started using
Application.start/2
(and functions on top of that, such as
Application.ensure_started/2
). This function should start the top-level
process of the application (which should be the top supervisor of the
application’s supervision tree if the application follows the OTP design
principles around supervision).
start_type
defines how the application is started:
:normal
- used if the startup is a normal startup or if the application is distributed and is started on the current node because of a failover from another node and the application specification key:start_phases
is:undefined
.{:takeover, node}
- used if the application is distributed and is started on the current node because of a failover on the nodenode
.{:failover, node}
- used if the application is distributed and is started on the current node because of a failover on nodenode
, and the application specification key:start_phases
is not:undefined
.
start_args
are the arguments passed to the application in the :mod
specification key (e.g., mod: {MyApp, [:my_args]}
).
This function should either return {:ok, pid}
or {:ok, pid, state}
if
startup is successful. pid
should be the PID of the top supervisor. state
can be an arbitrary term, and if omitted will default to []
; if the
application is later stopped, state
is passed to the stop/1
callback (see
the documentation for the c:stop/1
callback for more information).
use Application
provides no default implementation for the start/2
callback.
Callback implementation for Application.start/2
.