Geometry.PolygonM (Geometry v0.2.0) View Source
A polygon struct, representing a 2D 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 PolygonM
is empty.
Creates a PolygonM
from the given coordinates.
Returns an :ok
tuple with the PolygonM
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 PolygonM
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 PolygonM
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 PolygonM
.
Creates a PolygonM
from the given rings
.
Returns the GeoJSON term of a PolygonM
.
Returns the WKB representation for a PolygonM
.
Returns the WKT representation for a PolygonM
. With option :srid
an
EWKT representation with the SRID is returned.
Link to this section Types
Specs
t() :: %Geometry.PolygonM{rings: [Geometry.coordinates()]}
Link to this section Functions
Specs
Returns true
if the given PolygonM
is empty.
Examples
iex> PolygonM.empty?(PolygonM.new())
true
iex> PolygonM.empty?(
...> PolygonM.new([
...> LineStringM.new([
...> PointM.new(35, 10, 14),
...> PointM.new(45, 45, 24),
...> PointM.new(10, 20, 34),
...> PointM.new(35, 10, 14)
...> ])
...> ])
...> )
false
Specs
from_coordinates([Geometry.coordinate()]) :: t()
Creates a PolygonM
from the given coordinates.
Examples
iex> PolygonM.from_coordinates([
...> [[1, 1, 1], [2, 1, 3], [2, 2, 2], [1, 1, 1]]
...> ])
%PolygonM{
rings: [
[[1, 1, 1], [2, 1, 3], [2, 2, 2], [1, 1, 1]]
]
}
Specs
from_geo_json(Geometry.geo_json_term()) :: {:ok, t()} | Geometry.geo_json_error()
Returns an :ok
tuple with the PolygonM
from the given GeoJSON term.
Otherwise returns an :error
tuple.
Examples
iex> ~s(
...> {
...> "type": "Polygon",
...> "coordinates": [
...> [[35, 10, 12],
...> [45, 45, 22],
...> [15, 40, 33],
...> [10, 20, 55],
...> [35, 10, 12]]
...> ]
...> }
...> )
iex> |> Jason.decode!()
iex> |> PolygonM.from_geo_json()
{:ok, %PolygonM{
rings: [
[
[35, 10, 12],
[45, 45, 22],
[15, 40, 33],
[10, 20, 55],
[35, 10, 12]
]
]
}}
iex> ~s(
...> {
...> "type": "Polygon",
...> "coordinates": [
...> [[35, 10, 12],
...> [45, 45, 22],
...> [15, 40, 33],
...> [10, 20, 55],
...> [35, 10, 12]],
...> [[20, 30, 11],
...> [35, 35, 55],
...> [30, 20, 45],
...> [20, 30, 11]]
...> ]
...> }
...> )
iex> |> Jason.decode!()
iex> |> PolygonM.from_geo_json()
{:ok, %PolygonM{
rings: [[
[35, 10, 12],
[45, 45, 22],
[15, 40, 33],
[10, 20, 55],
[35, 10, 12]
], [
[20, 30, 11],
[35, 35, 55],
[30, 20, 45],
[20, 30, 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(), Geometry.mode()) :: {:ok, t()} | {:ok, t(), Geometry.srid()} | Geometry.wkb_error()
Returns an :ok
tuple with the PolygonM
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.PointM.from_wkb/2
function.
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 PolygonM
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> PolygonM.from_wkt("
...> POLYGON M (
...> (35 10 22, 45 45 33, 15 40 44, 10 20 66, 35 10 22),
...> (20 30 55, 35 35 66, 30 20 99, 20 30 55)
...> )
...> ")
{:ok,
%PolygonM{
rings: [
[
[35, 10, 22],
[45, 45, 33],
[15, 40, 44],
[10, 20, 66],
[35, 10, 22]
], [
[20, 30, 55],
[35, 35, 66],
[30, 20, 99],
[20, 30, 55]
]
]
}}
iex> "
...> SRID=789;
...> POLYGON M (
...> (35 10 22, 45 45 33, 15 40 44, 10 20 66, 35 10 22),
...> (20 30 55, 35 35 66, 30 20 99, 20 30 55)
...> )
...> "
iex> |> PolygonM.from_wkt()
{:ok,
%PolygonM{
rings: [
[
[35, 10, 22],
[45, 45, 33],
[15, 40, 44],
[10, 20, 66],
[35, 10, 22]
], [
[20, 30, 55],
[35, 35, 66],
[30, 20, 99],
[20, 30, 55]
]
]
}, 789}
iex> PolygonM.from_wkt("Polygon M EMPTY")
{:ok, %PolygonM{}}
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 PolygonM
.
Examples
iex> PolygonM.new()
%PolygonM{rings: []}
Specs
new([Geometry.LineStringM.t()]) :: t()
Creates a PolygonM
from the given rings
.
Examples
iex> 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)
...> ])
...> ])
%PolygonM{
rings: [
[[35, 10, 14], [45, 45, 24], [10, 20, 34], [35, 10, 14]],
[[20, 30, 14], [35, 35, 24], [30, 20, 34], [20, 30, 14]]
]
}
iex> PolygonM.new()
%PolygonM{}
Specs
to_geo_json(t()) :: Geometry.geo_json_term()
Returns the GeoJSON term of a PolygonM
.
Examples
iex> PolygonM.to_geo_json(
...> 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)
...> ])
...> ])
...> )
%{
"type" => "Polygon",
"coordinates" => [
[
[35, 10, 14],
[45, 45, 24],
[10, 20, 34],
[35, 10, 14]
], [
[20, 30, 14],
[35, 35, 24],
[30, 20, 34],
[20, 30, 14]
]
]
}
Specs
to_wkb(t(), opts) :: Geometry.wkb() when opts: [ endian: Geometry.endian(), srid: Geometry.srid(), mode: Geometry.mode() ]
Returns the WKB representation for a PolygonM
.
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.
Specs
to_wkt(t(), opts) :: Geometry.wkt() when opts: [{:srid, Geometry.srid()}]
Returns the WKT representation for a PolygonM
. With option :srid
an
EWKT representation with the SRID is returned.
Examples
iex> PolygonM.to_wkt(PolygonM.new())
"Polygon M EMPTY"
iex> PolygonM.to_wkt(PolygonM.new(), srid: 1123)
"SRID=1123;Polygon M EMPTY"
iex> PolygonM.to_wkt(
...> 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)
...> ])
...> ])
...> )
"Polygon M ((35 10 14, 45 45 24, 10 20 34, 35 10 14), (20 30 14, 35 35 24, 30 20 34, 20 30 14))"