Geometry.PolygonZM (Geometry v0.1.0) View Source
A polygon struct, representing a 3D polygon with a measurement.
A none empty line-string requires at least one ring with four points.
Link to this section Summary
Functions
Returns true if the given PolygonZM is empty.
Creates a PolygonZM from the given coordinates.
Returns an :ok tuple with the PolygonZM 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 PolygonZM 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 PolygonZM 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.
Creates an empty PolygonZM.
Creates a PolygonZM from the given rings.
Returns the GeoJSON term of a PolygonZM.
Returns the WKB representation for a PolygonZM.
Returns the WKT representation for a PolygonZM. With option :srid an
EWKT representation with the SRID is returned.
Link to this section Types
Specs
t() :: %Geometry.PolygonZM{rings: [Geometry.coordinates()]}
Link to this section Functions
Specs
Returns true if the given PolygonZM is empty.
Examples
iex> PolygonZM.empty?(PolygonZM.new())
true
iex> PolygonZM.empty?(
...> 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)
...> ])
...> ])
...> )
false
Specs
from_coordinates([Geometry.coordinate()]) :: t()
Creates a PolygonZM from the given coordinates.
Examples
iex> PolygonZM.from_coordinates([
...> [[1, 1, 1, 1], [2, 1, 2, 3], [2, 2, 3, 2], [1, 1, 1, 1]]
...> ])
%PolygonZM{
rings: [
[[1, 1, 1, 1], [2, 1, 2, 3], [2, 2, 3, 2], [1, 1, 1, 1]]
]
}
Specs
from_geo_json(Geometry.geo_json_term()) :: {:ok, t()} | Geometry.geo_json_error()
Returns an :ok tuple with the PolygonZM from the given GeoJSON term.
Otherwise returns an :error tuple.
Examples
iex> ~s(
...> {
...> "type": "Polygon",
...> "coordinates": [
...> [[35, 10, 11, 12],
...> [45, 45, 21, 22],
...> [15, 40, 31, 33],
...> [10, 20, 11, 55],
...> [35, 10, 11, 12]]
...> ]
...> }
...> )
iex> |> Jason.decode!()
iex> |> PolygonZM.from_geo_json()
{:ok, %PolygonZM{
rings: [
[
[35, 10, 11, 12],
[45, 45, 21, 22],
[15, 40, 31, 33],
[10, 20, 11, 55],
[35, 10, 11, 12]
]
]
}}
iex> ~s(
...> {
...> "type": "Polygon",
...> "coordinates": [
...> [[35, 10, 11, 12],
...> [45, 45, 21, 22],
...> [15, 40, 31, 33],
...> [10, 20, 11, 55],
...> [35, 10, 11, 12]],
...> [[20, 30, 11, 11],
...> [35, 35, 14, 55],
...> [30, 20, 12, 45],
...> [20, 30, 11, 11]]
...> ]
...> }
...> )
iex> |> Jason.decode!()
iex> |> PolygonZM.from_geo_json()
{:ok, %PolygonZM{
rings: [[
[35, 10, 11, 12],
[45, 45, 21, 22],
[15, 40, 31, 33],
[10, 20, 11, 55],
[35, 10, 11, 12]
], [
[20, 30, 11, 11],
[35, 35, 14, 55],
[30, 20, 12, 45],
[20, 30, 11, 11]
]]
}}
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 PolygonZM 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 PolygonZM 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> PolygonZM.from_wkt("
...> POLYGON ZM (
...> (35 10 11 22, 45 45 22 33, 15 40 33 44, 10 20 55 66, 35 10 11 22),
...> (20 30 22 55, 35 35 33 66, 30 20 88 99, 20 30 22 55)
...> )
...> ")
{:ok,
%PolygonZM{
rings: [
[
[35, 10, 11, 22],
[45, 45, 22, 33],
[15, 40, 33, 44],
[10, 20, 55, 66],
[35, 10, 11, 22]
], [
[20, 30, 22, 55],
[35, 35, 33, 66],
[30, 20, 88, 99],
[20, 30, 22, 55]
]
]
}}
iex> "
...> SRID=789;
...> POLYGON ZM (
...> (35 10 11 22, 45 45 22 33, 15 40 33 44, 10 20 55 66, 35 10 11 22),
...> (20 30 22 55, 35 35 33 66, 30 20 88 99, 20 30 22 55)
...> )
...> "
iex> |> PolygonZM.from_wkt()
{:ok,
%PolygonZM{
rings: [
[
[35, 10, 11, 22],
[45, 45, 22, 33],
[15, 40, 33, 44],
[10, 20, 55, 66],
[35, 10, 11, 22]
], [
[20, 30, 22, 55],
[35, 35, 33, 66],
[30, 20, 88, 99],
[20, 30, 22, 55]
]
]
}, 789}
iex> PolygonZM.from_wkt("Polygon ZM EMPTY")
{:ok, %PolygonZM{}}
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
new() :: t()
Creates an empty PolygonZM.
Examples
iex> PolygonZM.new()
%PolygonZM{rings: []}
Specs
new([Geometry.LineStringZM.t()]) :: t()
Creates a PolygonZM from the given rings.
Examples
iex> 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)
...> ])
...> ])
%PolygonZM{
rings: [
[[35, 10, 13, 14], [45, 45, 23, 24], [10, 20, 33, 34], [35, 10, 13, 14]],
[[20, 30, 13, 14], [35, 35, 23, 24], [30, 20, 33, 34], [20, 30, 13, 14]]
]
}
iex> PolygonZM.new()
%PolygonZM{}
Specs
to_geo_json(t()) :: Geometry.geo_json_term()
Returns the GeoJSON term of a PolygonZM.
Examples
iex> PolygonZM.to_geo_json(
...> 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)
...> ])
...> ])
...> )
%{
"type" => "Polygon",
"coordinates" => [
[
[35, 10, 13, 14],
[45, 45, 23, 24],
[10, 20, 33, 34],
[35, 10, 13, 14]
], [
[20, 30, 13, 14],
[35, 35, 23, 24],
[30, 20, 33, 34],
[20, 30, 13, 14]
]
]
}
Specs
to_wkb(t(), opts) :: Geometry.wkb() when opts: [endian: Geometry.endian(), srid: Geometry.srid()]
Returns the WKB representation for a PolygonZM.
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 PolygonZM. With option :srid an
EWKT representation with the SRID is returned.
Examples
iex> PolygonZM.to_wkt(PolygonZM.new())
"Polygon ZM EMPTY"
iex> PolygonZM.to_wkt(PolygonZM.new(), srid: 1123)
"SRID=1123;Polygon ZM EMPTY"
iex> PolygonZM.to_wkt(
...> 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)
...> ])
...> ])
...> )
"Polygon ZM ((35 10 13 14, 45 45 23 24, 10 20 33 34, 35 10 13 14), (20 30 13 14, 35 35 23 24, 30 20 33 34, 20 30 13 14))"