Geofox.Helpers (geofox_ex v0.1.1)

View Source

Helper functions for creating Geofox API data structures.

Summary

Functions

Create a bounding box from two coordinates.

Create a coordinate structure.

Create a GTI time structure.

Create a GTI time structure from an Elixir DateTime.

Create a station/location structure.

Functions

bounding_box(lower_left, upper_right)

@spec bounding_box(map(), map()) :: map()

Create a bounding box from two coordinates.

Examples

iex> lower = Geofox.Helpers.coordinate(9.9, 53.5)
iex> upper = Geofox.Helpers.coordinate(10.1, 53.6)
iex> Geofox.Helpers.bounding_box(lower, upper)
%{"lowerLeft" => %{"x" => 9.9, "y" => 53.5, "type" => "EPSG_4326"}, "upperRight" => %{"x" => 10.1, "y" => 53.6, "type" => "EPSG_4326"}}

coordinate(x, y, type \\ "EPSG_4326")

@spec coordinate(number(), number(), String.t()) :: map()

Create a coordinate structure.

Examples

iex> Geofox.Helpers.coordinate(53.5511, 9.9937)
%{"x" => 53.5511, "y" => 9.9937, "type" => "EPSG_4326"}

iex> Geofox.Helpers.coordinate(53.5511, 9.9937, "EPSG_31467")
%{"x" => 53.5511, "y" => 9.9937, "type" => "EPSG_31467"}

gti_time(date, time)

@spec gti_time(String.t(), String.t()) :: map()

Create a GTI time structure.

Examples

iex> Geofox.Helpers.gti_time("2024-01-15", "14:30")
%{"date" => "2024-01-15", "time" => "14:30"}

gti_time_from_datetime(datetime)

@spec gti_time_from_datetime(DateTime.t()) :: map()

Create a GTI time structure from an Elixir DateTime.

Examples

iex> dt = ~U[2024-01-15 14:30:00Z]
iex> Geofox.Helpers.gti_time_from_datetime(dt)
%{"date" => "2024-01-15", "time" => "14:30"}

station(name, id \\ nil, opts \\ [])

@spec station(String.t(), String.t() | nil, keyword()) :: map()

Create a station/location structure.

Examples

iex> Geofox.Helpers.station("Hauptbahnhof", "Master:1")
%{"name" => "Hauptbahnhof", "id" => "Master:1", "type" => "STATION"}

iex> Geofox.Helpers.station("Airport", nil, type: "POI")
%{"name" => "Airport", "id" => nil, "type" => "POI"}