Geometry.Feature (Geometry v0.2.0) View Source

A combination of a geometry and properties.

Link to this section Summary

Functions

Returns true for an empty Feature.

Returns an :ok tuple with the Feature from the given GeoJSON term. Otherwise returns an :error tuple.

The same as from_geo_josn/1, but raises a Geometry.Error exception if it fails.

Creates a new empty Feature.

Creates a new Feature.

Returns the GeoJSON term of a Feature.

Link to this section Types

Specs

t() :: %Geometry.Feature{geometry: Geometry.t() | nil, properties: map() | nil}

Link to this section Functions

Specs

empty?(t()) :: boolean()

Returns true for an empty Feature.

Examples

iex> Feature.empty?(Feature.new())
true

iex> Feature.empty?(Feature.new(geometry: Point.new(1, 2)))
false
Link to this function

from_geo_json(json, opts \\ [])

View Source

Specs

from_geo_json(Geometry.geo_json_term(), opts) ::
  {:ok, t()} | Geometry.geo_json_error()
when opts: [{:type, :z | :m | :zm}]

Returns an :ok tuple with the Feature from the given GeoJSON term. Otherwise returns an :error tuple.

The :type option specifies which type is expected. The possible values are :z, :m, and :zm.

Examples

iex> ~s({
...>   "type": "Feature",
...>   "geometry": {"type": "Point", "coordinates": [1, 2, 3]},
...>   "properties": {"facility": "Hotel"}
...> })
iex> |> Jason.decode!()
iex> |> Feature.from_geo_json(type: :z)
{:ok, %Feature{
  geometry: %PointZ{coordinate: [1, 2, 3]},
  properties: %{"facility" => "Hotel"}
}}

iex> ~s({
...>   "type": "Feature",
...>   "geometry": {"type": "Point", "coordinates": [1, 2]},
...>   "properties": {"facility": "Hotel"}
...> })
iex> |> Jason.decode!()
iex> |> Feature.from_geo_json()
{:ok, %Feature{
  geometry: %Point{coordinate: [1, 2]},
  properties: %{"facility" => "Hotel"}
}}
Link to this function

from_geo_json!(json, opts \\ [])

View Source

Specs

from_geo_json!(Geometry.geo_json_term(), opts) :: t()
when opts: [{:type, :z | :m | :zm}]

The same as from_geo_josn/1, but raises a Geometry.Error exception if it fails.

Examples

iex> ~s({
...>   "type": "Feature",
...>   "geometry": {"type": "Point", "coordinates": [1, 2, 3]},
...>   "properties": {"facility": "Hotel"}
...> })
iex> |> Jason.decode!()
iex> |> Feature.from_geo_json!(type: :m)
%Feature{
  geometry: %PointM{coordinate: [1, 2, 3]},
  properties: %{"facility" => "Hotel"}
}

Specs

new() :: t()

Creates a new empty Feature.

Examples

iex> Feature.new()
%Feature{}

Specs

new(geometry: Geometry.t(), properties: map()) :: t()

Creates a new Feature.

Examples

iex> Feature.new(
...>   geometry: Point.new(1, 2),
...>   properties: %{facility: :hotel}
...> )
%Feature{
  geometry: %Point{coordinate: [1, 2]},
  properties: %{facility: :hotel}
}

Specs

to_geo_json(t()) :: Geometry.geo_json_term()

Returns the GeoJSON term of a Feature.

Examples

iex> Feature.to_geo_json(Feature.new(
...>   geometry: Point.new(1, 2),
...>   properties: %{facility: :hotel}
...> ))
%{
  "type" => "Feature",
  "geometry" => %{
    "type" => "Point",
    "coordinates" => [1, 2]
  },
  "properties" => %{facility: :hotel}
}