Geometry.MultiPolygonM (Geometry v0.2.0) View Source

A set of polygons from type Geometry.PolygonM

MultiPointM implements the protocols Enumerable and Collectable.

Examples

iex> Enum.map(
...>   MultiPolygonM.new([
...>     PolygonM.new([
...>       LineStringM.new([
...>         PointM.new(11, 12, 14),
...>         PointM.new(11, 22, 24),
...>         PointM.new(31, 22, 34),
...>         PointM.new(11, 12, 14)
...>       ]),
...>     ]),
...>     PolygonM.new([
...>       LineStringM.new([
...>         PointM.new(35, 10, 14),
...>         PointM.new(45, 45, 24),
...>         PointM.new(10, 20, 34),
...>         PointM.new(35, 10, 14)
...>       ]),
...>       LineStringM.new([
...>         PointM.new(20, 30, 14),
...>         PointM.new(35, 35, 24),
...>         PointM.new(30, 20, 34),
...>         PointM.new(20, 30, 14)
...>       ])
...>     ])
...>   ]),
...>   fn polygon -> length(polygon) == 1 end
...> )
[true, false]

iex> Enum.into(
...>   [
...>     PolygonM.new([
...>       LineStringM.new([
...>         PointM.new(11, 12, 14),
...>         PointM.new(11, 22, 24),
...>         PointM.new(31, 22, 34),
...>         PointM.new(11, 12, 14)
...>       ])
...>     ])
...>   ],
...>   MultiPolygonM.new())
%MultiPolygonM{
  polygons:
    MapSet.new([
      [
        [
          [11, 12, 14],
          [11, 22, 24],
          [31, 22, 34],
          [11, 12, 14]
        ]
      ]
    ])
}

Link to this section Summary

Functions

Returns true if the given MultiPolygonM is empty.

Creates a MultiPolygonM from the given coordinates.

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

Creates an empty MultiPolygonM.

Creates a MultiPolygonM from the given Geometry.MultiPolygonMs.

Returns the number of elements in MultiPolygonM.

Returns the GeoJSON term of a MultiPolygonM.

Converts MultiPolygonM to a list.

Returns the WKB representation for a MultiPolygonM.

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

Link to this section Types

Specs

t() :: %Geometry.MultiPolygonM{polygons: MapSet.t([Geometry.coordinates()])}

Link to this section Functions

Specs

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

Returns true if the given MultiPolygonM is empty.

Examples

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

iex> MultiPolygonM.empty?(
...>   MultiPolygonM.new([
...>     PolygonM.new([
...>         LineStringM.new([
...>           PointM.new(1, 1, 4),
...>           PointM.new(1, 5, 8),
...>           PointM.new(5, 4, 6),
...>           PointM.new(1, 1, 4)
...>        ])
...>     ])
...>   ])
...> )
false
Link to this function

from_coordinates(coordinates)

View Source

Specs

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

Creates a MultiPolygonM from the given coordinates.

Examples

iex> MultiPolygonM.from_coordinates([
...>   [
...>     [[6, 2, 4], [8, 2, 5], [8, 4, 6], [6, 2, 4]]
...>   ], [
...>     [[1, 1, 4], [9, 1, 5], [9, 8, 6], [1, 1, 4]],
...>     [[6, 2, 3], [7, 2, 7], [7, 3, 4], [6, 2, 3]]
...>   ]
...> ])
%MultiPolygonM{
  polygons:
    MapSet.new([
      [
        [[6, 2, 4], [8, 2, 5], [8, 4, 6], [6, 2, 4]],
      ], [
        [[1, 1, 4], [9, 1, 5], [9, 8, 6], [1, 1, 4]],
        [[6, 2, 3], [7, 2, 7], [7, 3, 4], [6, 2, 3]]
      ]
    ])
}

Specs

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

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

Examples

iex> ~s(
...>   {
...>     "type": "MultiPolygon",
...>     "coordinates": [
...>       [
...>         [[6, 2, 4], [8, 2, 5], [8, 4, 6], [6, 2, 4]]
...>       ], [
...>         [[1, 1, 4], [9, 1, 5], [9, 8, 6], [1, 1, 4]],
...>         [[6, 2, 3], [7, 2, 7], [7, 3, 4], [6, 2, 3]]
...>       ]
...>     ]
...>   }
...> )
...> |> Jason.decode!()
...> |> MultiPolygonM.from_geo_json()
{:ok,
 %MultiPolygonM{
   polygons:
     MapSet.new([
       [
         [[1, 1, 4], [9, 1, 5], [9, 8, 6], [1, 1, 4]],
         [[6, 2, 3], [7, 2, 7], [7, 3, 4], [6, 2, 3]]
       ], [
         [[6, 2, 4], [8, 2, 5], [8, 4, 6], [6, 2, 4]]
       ]
     ])
 }}

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 MultiPolygonM 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.PointM.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 MultiPolygonM 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> MultiPolygonM.from_wkt("
...>   SRID=1234;MULTIPOLYGON M (
...>     (
...>        (40 40 20, 20 45 10, 45 30 30, 40 40 20)
...>     ), (
...>        (20 35 10, 10 30 20, 10 10 15, 30 5 15, 45 20 16, 20 35 10),
...>        (30 20 15, 20 15 10, 20 25 25, 30 20 15)
...>     )
...>   )
...> ")
{:ok,
 %MultiPolygonM{
   polygons:
     MapSet.new([
       [
         [
           [20, 35, 10],
           [10, 30, 20],
           [10, 10, 15],
           [30, 5, 15],
           [45, 20, 16],
           [20, 35, 10]
         ],
         [
           [30, 20, 15],
           [20, 15, 10],
           [20, 25, 25],
           [30, 20, 15]
         ]
       ],
       [
         [
           [40, 40, 20],
           [20, 45, 10],
           [45, 30, 30],
           [40, 40, 20]
         ]
       ]
     ])
 }, 1234}

iex> MultiPolygonM.from_wkt("MultiPolygon M EMPTY")
{:ok, %MultiPolygonM{}}

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_polygon_m, polygon_m)

View Source

Specs

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

Checks if MultiPolygonM contains point.

Examples

iex> MultiPolygonM.member?(
...>   MultiPolygonM.new([
...>     PolygonM.new([
...>       LineStringM.new([
...>         PointM.new(11, 12, 14),
...>         PointM.new(11, 22, 24),
...>         PointM.new(31, 22, 34),
...>         PointM.new(11, 12, 14)
...>       ])
...>     ])
...>   ]),
...>   PolygonM.new([
...>     LineStringM.new([
...>       PointM.new(11, 12, 14),
...>       PointM.new(11, 22, 24),
...>       PointM.new(31, 22, 34),
...>       PointM.new(11, 12, 14)
...>     ])
...>   ])
...> )
true

iex> MultiPolygonM.member?(
...>   MultiPolygonM.new([
...>     PolygonM.new([
...>       LineStringM.new([
...>         PointM.new(11, 12, 14),
...>         PointM.new(11, 22, 24),
...>         PointM.new(31, 22, 34),
...>         PointM.new(11, 12, 14)
...>       ])
...>     ])
...>   ]),
...>   PolygonM.new([
...>     LineStringM.new([
...>       PointM.new(11, 12, 14),
...>       PointM.new(11, 22, 24),
...>       PointM.new(33, 22, 34),
...>       PointM.new(11, 12, 14)
...>     ])
...>   ])
...> )
false

Specs

new() :: t()

Creates an empty MultiPolygonM.

Examples

iex> MultiPolygonM.new()
%MultiPolygonM{polygons: MapSet.new()}

Specs

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

Creates a MultiPolygonM from the given Geometry.MultiPolygonMs.

Examples

iex> MultiPolygonM.new([
...>   PolygonM.new([
...>     LineStringM.new([
...>       PointM.new(6, 2, 4),
...>       PointM.new(8, 2, 5),
...>       PointM.new(8, 4, 6),
...>       PointM.new(6, 2, 4)
...>     ]),
...>   ]),
...>   PolygonM.new([
...>     LineStringM.new([
...>       PointM.new(1, 1, 4),
...>       PointM.new(9, 1, 5),
...>       PointM.new(9, 8, 6),
...>       PointM.new(1, 1, 4)
...>     ]),
...>     LineStringM.new([
...>       PointM.new(6, 2, 4),
...>       PointM.new(7, 2, 5),
...>       PointM.new(7, 3, 6),
...>       PointM.new(6, 2, 4)
...>     ])
...>   ])
...> ])
%MultiPolygonM{
  polygons:
    MapSet.new([
      [
        [[1, 1, 4], [9, 1, 5], [9, 8, 6], [1, 1, 4]],
        [[6, 2, 4], [7, 2, 5], [7, 3, 6], [6, 2, 4]]
      ],
      [[[6, 2, 4], [8, 2, 5], [8, 4, 6], [6, 2, 4]]]
    ])
}

iex> MultiPolygonM.new([])
%MultiPolygonM{}

Specs

size(t()) :: non_neg_integer()

Returns the number of elements in MultiPolygonM.

Examples

iex> MultiPolygonM.size(
...>   MultiPolygonM.new([
...>     PolygonM.new([
...>       LineStringM.new([
...>         PointM.new(11, 12, 14),
...>         PointM.new(11, 22, 24),
...>         PointM.new(31, 22, 34),
...>         PointM.new(11, 12, 14)
...>       ])
...>     ])
...>   ])
...> )
1
Link to this function

to_geo_json(multi_polygon_m)

View Source

Specs

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

Returns the GeoJSON term of a MultiPolygonM.

There are no guarantees about the order of polygons in the returned coordinates.

Examples

MultiPolygonM.to_list(
  MultiPolygonM.new([
    PolygonM.new([
      LineStringM.new([
        PointM.new(111, 112, 114),
        PointM.new(111, 122, 124),
        PointM.new(131, 122, 134),
        PointM.new(111, 112, 114)
      ])
    ]),
    PolygonM.new([
      LineStringM.new([
        PointM.new(211, 212, 214),
        PointM.new(211, 222, 224),
        PointM.new(231, 222, 234),
        PointM.new(211, 212, 214)
      ])
    ])
  ])
)
# =>
# %{
#   "type" => "MultiPolygon",
#   "coordinates" => [
#     [
#       [
#         [11, 12, 14],
#         [11, 22, 24],
#         [31, 22, 34],
#         [11, 12, 14]
#       ]
#     ], [
#       [
#         [21, 22, 24],
#         [21, 22, 24],
#         [21, 22, 24],
#         [21, 22, 24]
#       ]
#     ]
#   ]
# }
Link to this function

to_list(multi_polygon_m)

View Source

Specs

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

Converts MultiPolygonM to a list.

Examples

iex> MultiPolygonM.to_list(
...>   MultiPolygonM.new([
...>     PolygonM.new([
...>       LineStringM.new([
...>         PointM.new(11, 12, 14),
...>         PointM.new(11, 22, 24),
...>         PointM.new(31, 22, 34),
...>         PointM.new(11, 12, 14)
...>       ])
...>     ])
...>   ])
...> )
[
  [
    [
      [11, 12, 14],
      [11, 22, 24],
      [31, 22, 34],
      [11, 12, 14]
    ]
  ]
]
Link to this function

to_wkb(multi_polygon, 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 MultiPolygonM.

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.PointM.to_wkb/1 function.

Link to this function

to_wkt(multi_polygon_m, opts \\ [])

View Source

Specs

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

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

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

Examples

MultiPolygonM.to_wkt(
  MultiPolygonM.new([
    PolygonM.new([
      LineStrinZM.new([
        PointM.new(20, 35, 10),
        PointM.new(10, 30, 20),
        PointM.new(10, 10, 15),
        PointM.new(30, 5, 15),
        PointM.new(45, 20, 16),
        PointM.new(20, 35, 10)
      ]),
      LineStringM.new([
        PointM.new(30, 20, 15),
        PointM.new(20, 15, 10),
        PointM.new(20, 25, 25),
        PointM.new(30, 20, 15)
      ])
    ]),
    PolygonM.new([
      LineStringM.new([
        PointM.new(40, 40, 20),
        PointM.new(20, 45, 10),
        PointM.new(45, 30, 30),
        PointM.new(40, 40, 20)
      ])
    ])
  ])
)
# Returns a string without any \n or extra spaces (formatted just for readability):
# SRID=478;MultiPolygon M (
#   (
#     (20 35 10, 10 30 20, 10 10 15, 30 5 15, 45 20 16, 20 35 10),
#     (30 20 15, 20 15 10, 20 25 25, 30 20 15)
#   ), (
#     (40 40 20, 20 45 10, 45 30 30, 40 40 20)
#   )
# )