Geo.Turf.Measure (geo_turf v0.2.0)

A collection of measurement related tools

Summary

Functions

Takes a LineString and returns a Point at a specified distance along the line. Note that this will aproximate location to the nearest coordinate point.

Takes a LineString and returns a Point at the middle of the line.

Takes a feature or collection and returns their area in square meters.

Takes two points and finds the geographic bearing between them, i.e. the angle measured in degrees from the north line (0 degrees)

Find the center of a Geo.geometry() item and give us a Geo.Point

Verifies that two points are close to each other. Defaults to 100 meters.

Calculates the distance between two points in degrees, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.

Takes a t:Geo.geometry() and measures its length in the specified units.

Functions

Link to this function

along(line_string, distance, unit \\ :kilometers)

Takes a LineString and returns a Point at a specified distance along the line. Note that this will aproximate location to the nearest coordinate point.

Examples

iex> %Geo.LineString{coordinates: [{-23.621,64.769},{-23.629,64.766},{-23.638,64.766}]}
...>   |> Geo.Turf.Measure.along(400, :meters)
%Geo.Point{coordinates: {-23.629,64.766}}
Link to this function

along_midpoint(line)

Takes a LineString and returns a Point at the middle of the line.

Examples

iex> %Geo.LineString{coordinates: [{-23.621,64.769},{-23.629,64.766},{-23.638,64.766}]}
...>   |> Geo.Turf.Measure.along_midpoint()
%Geo.Point{coordinates: {-23.629, 64.766}}
@spec area(Geo.geometry()) :: number()

Takes a feature or collection and returns their area in square meters.

Examples

iex> %Geo.Polygon{coordinates: [[{125, -15}, {113, -22}, {154, -27}, {144, -15}, {125, -15}]]}
...>   |> Geo.Turf.Measure.area()
3332484969239.2676
Link to this function

bearing(point1, point2)

@spec bearing(Geo.Point.t(), Geo.Point.t()) :: float()

Takes two points and finds the geographic bearing between them, i.e. the angle measured in degrees from the north line (0 degrees)

Examples

iex> point1 = %Geo.Point{coordinates: {-75.343, 39.984}}
...> point2 = %Geo.Point{coordinates: {-75.534, 39.123}}
...> Geo.Turf.Measure.bearing(point1, point2)
...>  |> Geo.Turf.Math.rounded(2)
-170.23
Link to this function

center(geometry)

Find the center of a Geo.geometry() item and give us a Geo.Point

Examples

iex> Geo.Turf.Measure.center(%Geo.Polygon{coordinates: [{0,0}, {0,10}, {10,10}, {10,0}]})
%Geo.Point{ coordinates: {5, 5} }
Link to this function

close_to(point_a, point_b, maximum \\ 100, units \\ :meters)

Verifies that two points are close to each other. Defaults to 100 meters.

Examples

iex> %Geo.Point{coordinates: {-22.653375, 64.844254}}
...> |> Geo.Turf.Measure.close_to(%Geo.Point{coordinates: {-22.654042, 64.843656}})
true

iex> %Geo.Point{coordinates: {-22.653375, 64.844254}}
...> |> Geo.Turf.Measure.close_to(%Geo.Point{coordinates: {-23.803020, 64.730435}}, 100, :kilometers)
true
Link to this function

distance(from, to, unit \\ :kilometers)

Calculates the distance between two points in degrees, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.

Examples

iex> Geo.Turf.Measure.distance(
...>   %Geo.Point{coordinates: {-75.343, 39.984}},
...>   %Geo.Point{coordinates: {-75.534, 39.123}},
...>   :kilometers)
97.13
Link to this function

length_of(feature, unit \\ :kilometers)

Takes a t:Geo.geometry() and measures its length in the specified units.

Examples

iex> %Geo.LineString{coordinates: [{-23.621,64.769},{-23.629,64.766},{-23.638,64.766}]}
...>   |> Geo.Turf.Measure.length_of()
0.93