A collection of helper utilities. Usually users will not have to refer to this directly but it is here if the need arises.
Summary
Functions
Verifies the declared SRID for GeoTurf's WGS84 calculations.
Create a bounding box for a given Geo.geometry/0.
Returns :error when the geometry or coordinate list is empty.
Takes a bounding box tuple and returns it as a %Geo.Polygon{}.
Flatten a t:Geo.geometry() to a simple list of coordinates
Functions
@spec assert_wgs84!(term()) :: :ok
Verifies the declared SRID for GeoTurf's WGS84 calculations.
An SRID of 4326 is accepted. nil is also accepted for compatibility with
Geo's default structs, but means that the caller is asserting that the
coordinates are WGS84; GeoTurf cannot infer a coordinate reference system
from coordinate values alone.
Any other declared SRID raises ArgumentError. Reproject those coordinates
before passing them to GeoTurf. If the coordinates are already WGS84 and only
the metadata is stale, correct it explicitly with
%{geometry | srid: 4326}. GeometryCollection children and list members are
validated recursively.
@spec bbox([{number(), number()}] | Geo.geometry()) :: {number(), number(), number(), number()} | :error
Create a bounding box for a given Geo.geometry/0.
Returns :error when the geometry or coordinate list is empty.
Examples
iex> Geo.Turf.Helpers.bbox(%Geo.Polygon{coordinates: [{1,1}, {1,3}, {3,3}, {3,1}]})
{1,1,3,3}
iex> Geo.Turf.Helpers.bbox([{1,1},{2,2},{3,3}])
{1,1,3,3}
@spec bbox_polygon({number(), number(), number(), number()}) :: Geo.Polygon.t()
Takes a bounding box tuple and returns it as a %Geo.Polygon{}.
The ring winds: SW → SE → NE → NW → SW.
The returned polygon has the WGS84 SRID 4326.
Examples
iex> Geo.Turf.Helpers.bbox_polygon({0, 0, 10, 10})
%Geo.Polygon{coordinates: [[{0, 0}, {10, 0}, {10, 10}, {0, 10}, {0, 0}]], srid: 4326}
iex> Geo.Turf.Helpers.bbox_polygon({-180, -90, 180, 90})
%Geo.Polygon{coordinates: [[{-180, -90}, {180, -90}, {180, 90}, {-180, 90}, {-180, -90}]], srid: 4326}
@spec flatten_coords(Geo.geometry()) :: [{number(), number()}]
Flatten a t:Geo.geometry() to a simple list of coordinates
Examples
iex> Geo.Turf.Helpers.flatten_coords(%Geo.GeometryCollection{geometries: [
...> %Geo.Point{coordinates: {1,1}},
...> %Geo.Point{coordinates: {2,2}}
...> ]})
[{1,1}, {2,2}]