Geo.Turf.Measure (geo_turf v0.3.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.
Takes in an origin %Geo.Point{}
and calculates the destination of a new %Geo.Point{}
at a given distance and bearing away from the origin point.
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.
Types
units()
@type units() :: {:units, Geo.Turf.Math.length_unit()}
Functions
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}}
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}}
area(arg1)
@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
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
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} }
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
destination(point, distance, bearing, opts \\ [])
@spec destination( origin :: Geo.Point.t(), distance :: number(), bearing :: number(), options :: [units()] ) :: Geo.Point.t()
Takes in an origin %Geo.Point{}
and calculates the destination of a new %Geo.Point{}
at a given distance and bearing away from the origin point.
This uses the Haversine formula to account for global curvature.
See the turf.destination
documentation for more information.
Parameters
origin
- the origin pointdistance
- the distance from the origin point to the destination pointbearing
- the angle from the origin point to the destination pointopts
- a keyword list of options
Options
:units
- the unit of the distance, defaults to:kilometers
Examples
iex> %Geo.Point{coordinates: {-75.343, 39.984}}
...> |> Geo.Turf.Measure.destination(100, 180, unit: :kilometers)
%Geo.Point{coordinates: {-75.343, 39.08467963627546}}
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
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