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