Geometry.GeometryCollection (Geometry v0.2.0) View Source

A collection set of 2D geometries.

GeometryCollection implements the protocols Enumerable and Collectable.

Examples

iex> Enum.map(
...>   GeometryCollection.new([
...>     Point.new(11, 12),
...>     LineString.new([
...>       Point.new(21, 22),
...>       Point.new(31, 32)
...>     ])
...>   ]),
...>   fn
...>     %Point{} -> :point
...>     %LineString{} -> :line_string
...>   end
...> ) |> Enum.sort()
[:line_string, :point]

iex> Enum.into([Point.new(1, 2)], GeometryCollection.new())
%GeometryCollection{
  geometries: MapSet.new([%Point{coordinate: [1, 2]}])
}

Link to this section Summary

Functions

Returns true if the given GeometryCollection is empty.

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

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

Returns an :ok tuple with the GeometryCollection from the given WKB string. Otherwise returns an :error tuple.

The same as from_wkb/2, but raises a Geometry.Error exception if it fails.

Returns an :ok tuple with the GeometryCollection from the given WKT string. Otherwise returns an :error tuple.

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

Checks if GeometryCollection contains geometry.

Creates an empty GeometryCollection.

Creates an empty GeometryCollection.

Returns the number of elements in GeometryCollection.

Returns the GeoJSON term of a GeometryCollection.

Converts GeometryCollection to a list.

Returns the WKB representation for a GeometryCollection.

Returns the WKT representation for a GeometryCollection. With option :srid an EWKT representation with the SRID is returned.

Link to this section Types

Specs

t() :: %Geometry.GeometryCollection{geometries: MapSet.t(Geometry.t())}

Link to this section Functions

Link to this function

empty?(geometry_collection)

View Source

Specs

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

Returns true if the given GeometryCollection is empty.

Examples

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

iex> GeometryCollection.empty?(GeometryCollection.new([Point.new(1, 2)]))
false

Specs

from_geo_json(Geometry.geo_json_term()) ::
  {:ok, t()} | Geometry.geo_json_error()

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

Examples

iex> ~s({
...>   "type": "GeometryCollection",
...>   "geometries": [
...>     {"type": "Point", "coordinates": [1.1, 2.2]}
...>   ]
...> })
iex> |> Jason.decode!()
iex> |> GeometryCollection.from_geo_json()
{
  :ok,
  %GeometryCollection{
    geometries: MapSet.new([%Point{coordinate: [1.1, 2.2]}])
  }
}

Specs

from_geo_json!(Geometry.geo_json_term()) :: t()

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

Link to this function

from_wkb(wkb, mode \\ :binary)

View Source

Specs

from_wkb(Geometry.wkb(), Geometry.mode()) ::
  {:ok, t()} | {:ok, t(), Geometry.srid()} | Geometry.wkb_error()

Returns an :ok tuple with the GeometryCollection from the given WKB string. Otherwise returns an :error tuple.

If the geometry contains a SRID the id is added to the tuple.

An example of a simpler geometry can be found in the description for the Geometry.Point.from_wkb/2 function.

Link to this function

from_wkb!(wkb, mode \\ :binary)

View Source

Specs

from_wkb!(Geometry.wkb(), Geometry.mode()) :: t() | {t(), Geometry.srid()}

The same as from_wkb/2, but raises a Geometry.Error exception if it fails.

Specs

from_wkt(Geometry.wkt()) ::
  {:ok, t()} | {:ok, t(), Geometry.srid()} | Geometry.wkt_error()

Returns an :ok tuple with the GeometryCollection from the given WKT string. Otherwise returns an :error tuple.

If the geometry contains a SRID the id is added to the tuple.

Examples

iex> GeometryCollection.from_wkt(
...>   "GeometryCollection (Point (1.1 2.2))")
{
  :ok,
  %GeometryCollection{
    geometries: MapSet.new([%Point{coordinate: [1.1, 2.2]}])
  }
}

iex> GeometryCollection.from_wkt(
...>   "SRID=123;GeometryCollection (Point (1.1 2.2))")
{
  :ok,
  %GeometryCollection{
    geometries: MapSet.new([%Point{coordinate: [1.1, 2.2]}])
  },
  123
}

iex> GeometryCollection.from_wkt("GeometryCollection EMPTY")
{:ok, %GeometryCollection{}}

Specs

from_wkt!(Geometry.wkt()) :: t() | {t(), Geometry.srid()}

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

Link to this function

member?(geometry_collection, geometry)

View Source

Specs

member?(t(), Geometry.t()) :: boolean()

Checks if GeometryCollection contains geometry.

Examples

iex> GeometryCollection.member?(
...>   GeometryCollection.new([
...>     Point.new(11, 12),
...>     LineString.new([
...>       Point.new(21, 22),
...>       Point.new(31, 32)
...>     ])
...>   ]),
...>   Point.new(11, 12)
...> )
true

iex> GeometryCollection.member?(
...>   GeometryCollection.new([
...>     Point.new(11, 12),
...>     LineString.new([
...>       Point.new(21, 22),
...>       Point.new(31, 32)
...>     ])
...>   ]),
...>   Point.new(1, 2)
...> )
false

Specs

new() :: t()

Creates an empty GeometryCollection.

Examples

iex> GeometryCollection.new()
%GeometryCollection{geometries: MapSet.new()}

Specs

new([Geometry.t()]) :: t()

Creates an empty GeometryCollection.

Examples

iex> GeometryCollection.new([
...>   Point.new(1, 2),
...>   LineString.new([Point.new(1, 1), Point.new(2, 2)])
...> ])
%GeometryCollection{geometries: MapSet.new([
  %Point{coordinate: [1, 2]},
  %LineString{points: [[1, 1], [2, 2]]}
])}
Link to this function

size(geometry_collection)

View Source

Specs

size(t()) :: non_neg_integer()

Returns the number of elements in GeometryCollection.

Examples

iex> GeometryCollection.size(
...>   GeometryCollection.new([
...>     Point.new(11, 12),
...>     LineString.new([
...>       Point.new(21, 22),
...>       Point.new(31, 32)
...>     ])
...>   ])
...> )
2
Link to this function

to_geo_json(geometry_collection)

View Source

Specs

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

Returns the GeoJSON term of a GeometryCollection.

Examples

iex> GeometryCollection.to_geo_json(
...> GeometryCollection.new([Point.new(1.1, 2.2)]))
%{
  "type" => "GeometryCollection",
  "geometries" => [
    %{
      "type" => "Point",
      "coordinates" => [1.1, 2.2]
    }
  ]
}
Link to this function

to_list(geometry_collection)

View Source

Specs

to_list(t()) :: [Geometry.t()]

Converts GeometryCollection to a list.

Examples

iex> GeometryCollection.to_list(
...>   GeometryCollection.new([
...>     Point.new(11, 12)
...>   ])
...> )
[%Point{coordinate: [11, 12]}]
Link to this function

to_wkb(geometry_collection, opts \\ [])

View Source

Specs

to_wkb(t(), opts) :: Geometry.wkb()
when opts: [endian: Geometry.endian(), srid: Geometry.srid()]

Returns the WKB representation for a GeometryCollection.

With option :srid an EWKB representation with the SRID is returned.

The option endian indicates whether :xdr big endian or :ndr little endian is returned. The default is :ndr.

The :mode determines whether a hex-string or binary is returned. The default is :binary.

An example of a simpler geometry can be found in the description for the Geometry.Point.to_wkb/1 function.

Link to this function

to_wkt(geometry_collection, opts \\ [])

View Source

Specs

to_wkt(t(), opts) :: Geometry.wkt() when opts: [{:srid, Geometry.srid()}]

Returns the WKT representation for a GeometryCollection. With option :srid an EWKT representation with the SRID is returned.

Examples

iex> GeometryCollection.to_wkt(GeometryCollection.new())
"GeometryCollection EMPTY"

iex> GeometryCollection.to_wkt(
...>   GeometryCollection.new([
...>     Point.new(1.1, 1.2),
...>     Point.new(2.1, 2.2)
...>   ])
...> )
"GeometryCollection (Point (1.1 1.2), Point (2.1 2.2))"

iex> GeometryCollection.to_wkt(
...>   GeometryCollection.new([Point.new(1.1, 2.2)]),
...>   srid: 4711)
"SRID=4711;GeometryCollection (Point (1.1 2.2))"