View Source Geometry.MultiLineString (Geometry v0.3.1)

A set of line-strings from type Geometry.LineString

MultiLineStringMZ implements the protocols Enumerable and Collectable.

Examples

iex> Enum.map(
...>   MultiLineString.new([
...>     LineString.new([
...>       Point.new(1, 2),
...>       Point.new(3, 4)
...>     ]),
...>     LineString.new([
...>       Point.new(1, 2),
...>       Point.new(11, 12),
...>       Point.new(13, 14)
...>     ])
...>   ]),
...>   fn line_string -> length line_string end
...> )
[2, 3]

iex> Enum.into(
...>   [LineString.new([Point.new(1, 2), Point.new(5, 6)])],
...>   MultiLineString.new())
%MultiLineString{
  line_strings:
  MapSet.new([
    [[1, 2], [5, 6]]
  ])
}

Link to this section Summary

Functions

Returns true if the given MultiLineString is empty.

Creates a MultiLineString from the given coordinates.

Returns an :ok tuple with the MultiLineString 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 MultiLineString 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 MultiLineString 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 MultiLineString contains line_string.

Creates an empty MultiLineString.

Creates a MultiLineString from the given Geometry.MultiLineStrings.

Returns the number of elements in MultiLineString.

Returns the GeoJSON term of a MultiLineString.

Converts MultiLineString to a list.

Returns the WKB representation for a MultiLineString.

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

Link to this section Types

Specs

t() :: %Geometry.MultiLineString{line_strings: MapSet.t(Geometry.coordinates())}

Link to this section Functions

Link to this function

empty?(multi_line_string)

View Source

Specs

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

Returns true if the given MultiLineString is empty.

Examples

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

iex> MultiLineString.empty?(
...>   MultiLineString.new([
...>     LineString.new([Point.new(1, 2), Point.new(3, 4)])
...>   ])
...> )
false
Link to this function

from_coordinates(coordinates)

View Source

Specs

from_coordinates([Geometry.coordinate()]) :: t()

Creates a MultiLineString from the given coordinates.

Examples

iex> MultiLineString.from_coordinates([
...>   [[-1, 1], [2, 2], [-3, 3]],
...>   [[-10, 10], [-20, 20]]
...> ])
%MultiLineString{
  line_strings:
    MapSet.new([
      [[-1, 1], [2, 2], [-3, 3]],
      [[-10, 10], [-20, 20]]
    ])
}

Specs

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

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

Examples

iex> ~s(
...>   {
...>     "type": "MultiLineString",
...>     "coordinates": [
...>       [[-1, 1], [2, 2], [-3, 3]],
...>       [[-10, 10], [-20, 20]]
...>     ]
...>   }
...> )
iex> |> Jason.decode!()
iex> |> MultiLineString.from_geo_json()
{:ok,
 %Geometry.MultiLineString{
   line_strings:
     MapSet.new([
       [[-10, 10], [-20, 20]],
       [[-1, 1], [2, 2], [-3, 3]]
     ])
 }}

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() | {t(), Geometry.srid()}} | Geometry.wkb_error()

Returns an :ok tuple with the MultiLineString 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() | {t(), Geometry.srid()}} | Geometry.wkt_error()

Returns an :ok tuple with the MultiLineString 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> MultiLineString.from_wkt("
...>   SRID=1234;MultiLineString (
...>     (10 20, 20 10, 20 40),
...>     (40 30, 30 30)
...>   )
...> ")
{:ok, {
  %MultiLineString{
    line_strings:
      MapSet.new([
        [[10, 20], [20, 10], [20, 40]],
        [[40, 30], [30, 30]]
      ])
  },
  1234
}}

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

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?(multi_line_string, line_string)

View Source

Specs

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

Checks if MultiLineString contains line_string.

Examples

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

iex> MultiLineString.member?(
...>   MultiLineString.new([
...>     LineString.new([
...>       Point.new(11, 12),
...>       Point.new(21, 22)
...>     ]),
...>     LineString.new([
...>       Point.new(31, 32),
...>       Point.new(41, 42)
...>     ])
...>   ]),
...>   LineString.new([
...>     Point.new(11, 12),
...>     Point.new(41, 42)
...>   ])
...> )
false

Specs

new() :: t()

Creates an empty MultiLineString.

Examples

iex> MultiLineString.new()
%MultiLineString{line_strings: MapSet.new()}

Specs

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

Creates a MultiLineString from the given Geometry.MultiLineStrings.

Examples

iex> MultiLineString.new([
...>   LineString.new([
...>     Point.new(1, 2),
...>     Point.new(2, 3),
...>     Point.new(3, 4)
...>   ]),
...>   LineString.new([
...>     Point.new(10, 20),
...>     Point.new(30, 40)
...>   ]),
...>   LineString.new([
...>     Point.new(10, 20),
...>     Point.new(30, 40)
...>   ])
...> ])
%Geometry.MultiLineString{
  line_strings:
    MapSet.new([
      [[1, 2], [2, 3], [3, 4]],
      [[10, 20], [30, 40]]
    ])
}

iex> MultiLineString.new([])
%MultiLineString{line_strings: MapSet.new()}

Specs

size(t()) :: non_neg_integer()

Returns the number of elements in MultiLineString.

Examples

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

to_geo_json(multi_line_string)

View Source

Specs

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

Returns the GeoJSON term of a MultiLineString.

There are no guarantees about the order of line-strings in the returned coordinates.

Examples

[
  [[-1, 1], [2, 2], [-3, 3]],
  [[-10, 10], [-20, 20]]
]
|> MultiLineString.from_coordinates()
MultiLineString.to_geo_json(
  MultiLineString.new([
    LineString.new([
      Point.new(-1, 1),
      Point.new(2, 2),
      Point.new(-3, 3)
    ]),
    LineString.new([
      Point.new(-10, 10),
      Point.new(-20, 20)
    ])
  ])
)
# =>
# %{
#   "type" => "MultiLineString",
#   "coordinates" => [
#     [[-1, 1], [2, 2], [-3, 3]],
#     [[-10, 10], [-20, 20]]
#   ]
# }
Link to this function

to_list(multi_line_string)

View Source

Specs

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

Converts MultiLineString to a list.

Link to this function

to_wkb(multi_line_string, opts \\ [])

View Source

Specs

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

Returns the WKB representation for a MultiLineString.

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 :xdr.

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(multi_line_string, opts \\ [])

View Source

Specs

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

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

There are no guarantees about the order of line-strings in the returned WKT-string.

Examples

MultiLineString.to_wkt(MultiLineString.new())
# => "MultiLineString EMPTY"

MultiLineString.to_wkt(
  MultiLineString.new([
    LineString(
      [Point.new(7.1, 8.1), Point.new(9.2, 5.2)]
    ),
    LineString(
      [Point.new(5.5, 9.2), Point.new(1.2, 3.2)]
    )
  ])
)
# Returns a string without any \n or extra spaces (formatted just for readability):
# MultiLineString (
#   (5.5 9.2, 1.2 3.2),
#   (7.1 8.1, 9.2 5.2)
# )

MultiLineString.to_wkt(
  MultiLineString.new([
    LineString(
      [Point.new(7.1, 8.1), Point.new(9.2, 5.2)]
    ),
    LineString(
      [Point.new(5.5, 9.2), Point.new(1.2, 3.2)]
    )
  ]),
  srid: 555
)
# Returns a string without any \n or extra spaces (formatted just for readability):
# SRID=555;MultiLineString (
#   (5.5 9.2, 1.2 3.2),
#   (7.1 8.1, 9.2 5.2)
# )