Geometry.MultiPolygonZM (Geometry v0.1.0) View Source
A set of polygons from type Geometry.PolygonZM
MultiPointZM implements the protocols Enumerable and Collectable.
Examples
iex> Enum.map(
...> MultiPolygonZM.new([
...> PolygonZM.new([
...> LineStringZM.new([
...> PointZM.new(11, 12, 13, 14),
...> PointZM.new(11, 22, 23, 24),
...> PointZM.new(31, 22, 33, 34),
...> PointZM.new(11, 12, 13, 14)
...> ]),
...> ]),
...> PolygonZM.new([
...> LineStringZM.new([
...> PointZM.new(35, 10, 13, 14),
...> PointZM.new(45, 45, 23, 24),
...> PointZM.new(10, 20, 33, 34),
...> PointZM.new(35, 10, 13, 14)
...> ]),
...> LineStringZM.new([
...> PointZM.new(20, 30, 13, 14),
...> PointZM.new(35, 35, 23, 24),
...> PointZM.new(30, 20, 33, 34),
...> PointZM.new(20, 30, 13, 14)
...> ])
...> ])
...> ]),
...> fn polygon -> length(polygon) == 1 end
...> )
[true, false]
iex> Enum.into(
...> [
...> PolygonZM.new([
...> LineStringZM.new([
...> PointZM.new(11, 12, 13, 14),
...> PointZM.new(11, 22, 23, 24),
...> PointZM.new(31, 22, 33, 34),
...> PointZM.new(11, 12, 13, 14)
...> ])
...> ])
...> ],
...> MultiPolygonZM.new())
%MultiPolygonZM{
polygons:
MapSet.new([
[
[
[11, 12, 13, 14],
[11, 22, 23, 24],
[31, 22, 33, 34],
[11, 12, 13, 14]
]
]
])
}
Link to this section Summary
Functions
Returns true if the given MultiPolygonZM is empty.
Creates a MultiPolygonZM from the given coordinates.
Returns an :ok tuple with the MultiPolygonZM 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 MultiPolygonZM from the given WKB string. Otherwise
returns an :error tuple.
The same as from_wkb/1, but raises a Geometry.Error exception if it fails.
Returns an :ok tuple with the MultiPolygonZM 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 MultiPolygonZM contains point.
Creates an empty MultiPolygonZM.
Creates a MultiPolygonZM from the given Geometry.MultiPolygonZMs.
Returns the number of elements in MultiPolygonZM.
Returns the GeoJSON term of a MultiPolygonZM.
Converts MultiPolygonZM to a list.
Returns the WKB representation for a MultiPolygonZM.
Returns the WKT representation for a MultiPolygonZM. With option :srid an
EWKT representation with the SRID is returned.
Link to this section Types
Specs
t() :: %Geometry.MultiPolygonZM{polygons: MapSet.t([Geometry.coordinates()])}
Link to this section Functions
Specs
Returns true if the given MultiPolygonZM is empty.
Examples
iex> MultiPolygonZM.empty?(MultiPolygonZM.new())
true
iex> MultiPolygonZM.empty?(
...> MultiPolygonZM.new([
...> PolygonZM.new([
...> LineStringZM.new([
...> PointZM.new(1, 1, 3, 4),
...> PointZM.new(1, 5, 4, 8),
...> PointZM.new(5, 4, 2, 6),
...> PointZM.new(1, 1, 3, 4)
...> ])
...> ])
...> ])
...> )
false
Specs
from_coordinates([[Geometry.coordinates()]]) :: t()
Creates a MultiPolygonZM from the given coordinates.
Examples
iex> MultiPolygonZM.from_coordinates([
...> [
...> [[6, 2, 3, 4], [8, 2, 4, 5], [8, 4, 5, 6], [6, 2, 3, 4]]
...> ], [
...> [[1, 1, 3, 4], [9, 1, 4, 5], [9, 8, 5, 6], [1, 1, 3, 4]],
...> [[6, 2, 4, 3], [7, 2, 6, 7], [7, 3, 3, 4], [6, 2, 4, 3]]
...> ]
...> ])
%MultiPolygonZM{
polygons:
MapSet.new([
[
[[6, 2, 3, 4], [8, 2, 4, 5], [8, 4, 5, 6], [6, 2, 3, 4]],
], [
[[1, 1, 3, 4], [9, 1, 4, 5], [9, 8, 5, 6], [1, 1, 3, 4]],
[[6, 2, 4, 3], [7, 2, 6, 7], [7, 3, 3, 4], [6, 2, 4, 3]]
]
])
}
Specs
from_geo_json(Geometry.geo_json_term()) :: {:ok, t()} | Geometry.geo_json_error()
Returns an :ok tuple with the MultiPolygonZM from the given GeoJSON
term. Otherwise returns an :error tuple.
Examples
iex> ~s(
...> {
...> "type": "MultiPolygon",
...> "coordinates": [
...> [
...> [[6, 2, 3, 4], [8, 2, 4, 5], [8, 4, 5, 6], [6, 2, 3, 4]]
...> ], [
...> [[1, 1, 3, 4], [9, 1, 4, 5], [9, 8, 5, 6], [1, 1, 3, 4]],
...> [[6, 2, 4, 3], [7, 2, 6, 7], [7, 3, 3, 4], [6, 2, 4, 3]]
...> ]
...> ]
...> }
...> )
...> |> Jason.decode!()
...> |> MultiPolygonZM.from_geo_json()
{:ok,
%MultiPolygonZM{
polygons:
MapSet.new([
[
[[1, 1, 3, 4], [9, 1, 4, 5], [9, 8, 5, 6], [1, 1, 3, 4]],
[[6, 2, 4, 3], [7, 2, 6, 7], [7, 3, 3, 4], [6, 2, 4, 3]]
], [
[[6, 2, 3, 4], [8, 2, 4, 5], [8, 4, 5, 6], [6, 2, 3, 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.
Specs
from_wkb(Geometry.wkb()) :: {:ok, t()} | {:ok, t(), Geometry.srid()} | Geometry.wkb_error()
Returns an :ok tuple with the MultiPolygonZM 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.PointZM.from_wkb/1 function.
Specs
from_wkb!(Geometry.wkb()) :: t() | {t(), Geometry.srid()}
The same as from_wkb/1, 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 MultiPolygonZM 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> MultiPolygonZM.from_wkt("
...> SRID=1234;MULTIPOLYGON ZM (
...> (
...> (40 40 10 20, 20 45 20 10, 45 30 15 30, 40 40 10 20)
...> ), (
...> (20 35 20 10, 10 30 10 20, 10 10 30 15, 30 5 10 15, 45 20 10 16, 20 35 20 10),
...> (30 20 10 15, 20 15 20 10, 20 25 15 25, 30 20 10 15)
...> )
...> )
...> ")
{:ok,
%MultiPolygonZM{
polygons:
MapSet.new([
[
[
[20, 35, 20, 10],
[10, 30, 10, 20],
[10, 10, 30, 15],
[30, 5, 10, 15],
[45, 20, 10, 16],
[20, 35, 20, 10]
],
[
[30, 20, 10, 15],
[20, 15, 20, 10],
[20, 25, 15, 25],
[30, 20, 10, 15]
]
],
[
[
[40, 40, 10, 20],
[20, 45, 20, 10],
[45, 30, 15, 30],
[40, 40, 10, 20]
]
]
])
}, 1234}
iex> MultiPolygonZM.from_wkt("MultiPolygon ZM EMPTY")
{:ok, %MultiPolygonZM{}}
Specs
from_wkt!(Geometry.wkt()) :: t() | {t(), Geometry.srid()}
The same as from_wkt/1, but raises a Geometry.Error exception if it fails.
Specs
member?(t(), Geometry.PolygonZM.t()) :: boolean()
Checks if MultiPolygonZM contains point.
Examples
iex> MultiPolygonZM.member?(
...> MultiPolygonZM.new([
...> PolygonZM.new([
...> LineStringZM.new([
...> PointZM.new(11, 12, 13, 14),
...> PointZM.new(11, 22, 23, 24),
...> PointZM.new(31, 22, 33, 34),
...> PointZM.new(11, 12, 13, 14)
...> ])
...> ])
...> ]),
...> PolygonZM.new([
...> LineStringZM.new([
...> PointZM.new(11, 12, 13, 14),
...> PointZM.new(11, 22, 23, 24),
...> PointZM.new(31, 22, 33, 34),
...> PointZM.new(11, 12, 13, 14)
...> ])
...> ])
...> )
true
iex> MultiPolygonZM.member?(
...> MultiPolygonZM.new([
...> PolygonZM.new([
...> LineStringZM.new([
...> PointZM.new(11, 12, 13, 14),
...> PointZM.new(11, 22, 23, 24),
...> PointZM.new(31, 22, 33, 34),
...> PointZM.new(11, 12, 13, 14)
...> ])
...> ])
...> ]),
...> PolygonZM.new([
...> LineStringZM.new([
...> PointZM.new(11, 12, 13, 14),
...> PointZM.new(11, 22, 23, 24),
...> PointZM.new(33, 22, 33, 34),
...> PointZM.new(11, 12, 13, 14)
...> ])
...> ])
...> )
false
Specs
new() :: t()
Creates an empty MultiPolygonZM.
Examples
iex> MultiPolygonZM.new()
%MultiPolygonZM{polygons: MapSet.new()}
Specs
new([Geometry.PolygonZM.t()]) :: t()
Creates a MultiPolygonZM from the given Geometry.MultiPolygonZMs.
Examples
iex> MultiPolygonZM.new([
...> PolygonZM.new([
...> LineStringZM.new([
...> PointZM.new(6, 2, 3, 4),
...> PointZM.new(8, 2, 4, 5),
...> PointZM.new(8, 4, 5, 6),
...> PointZM.new(6, 2, 3, 4)
...> ]),
...> ]),
...> PolygonZM.new([
...> LineStringZM.new([
...> PointZM.new(1, 1, 3, 4),
...> PointZM.new(9, 1, 4, 5),
...> PointZM.new(9, 8, 5, 6),
...> PointZM.new(1, 1, 3, 4)
...> ]),
...> LineStringZM.new([
...> PointZM.new(6, 2, 3, 4),
...> PointZM.new(7, 2, 4, 5),
...> PointZM.new(7, 3, 5, 6),
...> PointZM.new(6, 2, 3, 4)
...> ])
...> ])
...> ])
%MultiPolygonZM{
polygons:
MapSet.new([
[
[[1, 1, 3, 4], [9, 1, 4, 5], [9, 8, 5, 6], [1, 1, 3, 4]],
[[6, 2, 3, 4], [7, 2, 4, 5], [7, 3, 5, 6], [6, 2, 3, 4]]
],
[[[6, 2, 3, 4], [8, 2, 4, 5], [8, 4, 5, 6], [6, 2, 3, 4]]]
])
}
iex> MultiPolygonZM.new([])
%MultiPolygonZM{}
Specs
size(t()) :: non_neg_integer()
Returns the number of elements in MultiPolygonZM.
Examples
iex> MultiPolygonZM.size(
...> MultiPolygonZM.new([
...> PolygonZM.new([
...> LineStringZM.new([
...> PointZM.new(11, 12, 13, 14),
...> PointZM.new(11, 22, 23, 24),
...> PointZM.new(31, 22, 33, 34),
...> PointZM.new(11, 12, 13, 14)
...> ])
...> ])
...> ])
...> )
1
Specs
to_geo_json(t()) :: Geometry.geo_json_term()
Returns the GeoJSON term of a MultiPolygonZM.
There are no guarantees about the order of polygons in the returned
coordinates.
Examples
MultiPolygonZM.to_list(
MultiPolygonZM.new([
PolygonZM.new([
LineStringZM.new([
PointZM.new(111, 112, 113, 114),
PointZM.new(111, 122, 123, 124),
PointZM.new(131, 122, 133, 134),
PointZM.new(111, 112, 113, 114)
])
]),
PolygonZM.new([
LineStringZM.new([
PointZM.new(211, 212, 213, 214),
PointZM.new(211, 222, 223, 224),
PointZM.new(231, 222, 233, 234),
PointZM.new(211, 212, 213, 214)
])
])
])
)
# =>
# %{
# "type" => "MultiPolygon",
# "coordinates" => [
# [
# [
# [11, 12, 13, 14],
# [11, 22, 23, 24],
# [31, 22, 33, 34],
# [11, 12, 13, 14]
# ]
# ], [
# [
# [21, 22, 23, 24],
# [21, 22, 23, 24],
# [21, 22, 23, 24],
# [21, 22, 23, 24]
# ]
# ]
# ]
# }
Specs
to_list(t()) :: [Geometry.PolygonZM.t()]
Converts MultiPolygonZM to a list.
Examples
iex> MultiPolygonZM.to_list(
...> MultiPolygonZM.new([
...> PolygonZM.new([
...> LineStringZM.new([
...> PointZM.new(11, 12, 13, 14),
...> PointZM.new(11, 22, 23, 24),
...> PointZM.new(31, 22, 33, 34),
...> PointZM.new(11, 12, 13, 14)
...> ])
...> ])
...> ])
...> )
[
[
[
[11, 12, 13, 14],
[11, 22, 23, 24],
[31, 22, 33, 34],
[11, 12, 13, 14]
]
]
]
Specs
to_wkb(t(), opts) :: Geometry.wkb() when opts: [endian: Geometry.endian(), srid: Geometry.srid()]
Returns the WKB representation for a MultiPolygonZM.
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.
An example of a simpler geometry can be found in the description for the
Geometry.PointZM.to_wkb/1 function.
Specs
to_wkt(t(), opts) :: Geometry.wkt() when opts: [{:srid, Geometry.srid()}]
Returns the WKT representation for a MultiPolygonZM. 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
MultiPolygonZM.to_wkt(
MultiPolygonZM.new([
PolygonZM.new([
LineStrinZM.new([
PointZM.new(20, 35, 20, 10),
PointZM.new(10, 30, 10, 20),
PointZM.new(10, 10, 30, 15),
PointZM.new(30, 5, 10, 15),
PointZM.new(45, 20, 10, 16),
PointZM.new(20, 35, 20, 10)
]),
LineStringZM.new([
PointZM.new(30, 20, 10, 15),
PointZM.new(20, 15, 20, 10),
PointZM.new(20, 25, 15, 25),
PointZM.new(30, 20, 10, 15)
])
]),
PolygonZM.new([
LineStringZM.new([
PointZM.new(40, 40, 10, 20),
PointZM.new(20, 45, 20, 10),
PointZM.new(45, 30, 15, 30),
PointZM.new(40, 40, 10, 20)
])
])
])
)
# Returns a string without any \n or extra spaces (formatted just for readability):
# SRID=478;MultiPolygon ZM (
# (
# (20 35 20 10, 10 30 10 20, 10 10 30 15, 30 5 10 15, 45 20 10 16, 20 35 20 10),
# (30 20 10 15, 20 15 20 10, 20 25 15 25, 30 20 10 15)
# ), (
# (40 40 10 20, 20 45 20 10, 45 30 15 30, 40 40 10 20)
# )
# )