View Source Geometry.PolygonZM (Geometry v0.3.2)
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/2
, 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
@type t() :: %Geometry.PolygonZM{rings: [Geometry.coordinates()]}
Link to this section Functions
Returns true
if the given PolygonZM
is empty.
examples
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
@spec from_coordinates([Geometry.coordinate()]) :: t()
Creates a PolygonZM
from the given coordinates.
examples
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]]
]
}
@spec 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
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]
]]
}}
@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 PolygonZM
from the given WKB string. Otherwise
returns an :error
tuple.
If the geometry contains a SRID the id is added to the tuple.
The optional second argument determines if a :hex
-string or a :binary
input is expected. The default is :binary
.
An example of a simpler geometry can be found in the description for the
Geometry.PointZM.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 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
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{}}
@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 new() :: t()
Creates an empty PolygonZM
.
examples
Examples
iex> PolygonZM.new()
%PolygonZM{rings: []}
@spec new([Geometry.LineStringZM.t()]) :: t()
Creates a PolygonZM
from the given rings
.
examples
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{}
@spec to_geo_json(t()) :: Geometry.geo_json_term()
Returns the GeoJSON term of a PolygonZM
.
examples
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]
]
]
}
@spec to_wkb(t(), opts) :: Geometry.wkb() when opts: [ endian: Geometry.endian(), srid: Geometry.srid(), mode: Geometry.mode() ]
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
.
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.PointZM.to_wkb/1
function.
@spec 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
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))"