Geometry.PolygonZ (Geometry v0.2.0) View Source

A polygon struct, representing a 3D polygon.

A none empty line-string requires at least one ring with four points.

Link to this section Summary

Functions

Returns true if the given PolygonZ is empty.

Creates a PolygonZ from the given coordinates.

Returns an :ok tuple with the PolygonZ 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 PolygonZ 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 PolygonZ 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 PolygonZ.

Creates a PolygonZ from the given rings.

Returns the GeoJSON term of a PolygonZ.

Returns the WKB representation for a PolygonZ.

Returns the WKT representation for a PolygonZ. With option :srid an EWKT representation with the SRID is returned.

Link to this section Types

Specs

t() :: %Geometry.PolygonZ{rings: [Geometry.coordinates()]}

Link to this section Functions

Specs

empty?(t()) :: boolean()

Returns true if the given PolygonZ is empty.

Examples

iex> PolygonZ.empty?(PolygonZ.new())
true

iex> PolygonZ.empty?(
...>   PolygonZ.new([
...>     LineStringZ.new([
...>       PointZ.new(35, 10, 13),
...>       PointZ.new(45, 45, 23),
...>       PointZ.new(10, 20, 33),
...>       PointZ.new(35, 10, 13)
...>     ])
...>   ])
...> )
false

Specs

from_coordinates([Geometry.coordinate()]) :: t()

Creates a PolygonZ from the given coordinates.

Examples

iex> PolygonZ.from_coordinates([
...>   [[1, 1, 1], [2, 1, 2], [2, 2, 3], [1, 1, 1]]
...> ])
%PolygonZ{
  rings: [
    [[1, 1, 1], [2, 1, 2], [2, 2, 3], [1, 1, 1]]
  ]
}

Specs

from_geo_json(Geometry.geo_json_term()) ::
  {:ok, t()} | Geometry.geo_json_error()

Returns an :ok tuple with the PolygonZ from the given GeoJSON term. Otherwise returns an :error tuple.

Examples

iex> ~s(
...>   {
...>     "type": "Polygon",
...>     "coordinates": [
...>       [[35, 10, 11],
...>        [45, 45, 21],
...>        [15, 40, 31],
...>        [10, 20, 11],
...>        [35, 10, 11]]
...>     ]
...>   }
...> )
iex> |> Jason.decode!()
iex> |> PolygonZ.from_geo_json()
{:ok, %PolygonZ{
  rings: [
    [
      [35, 10, 11],
      [45, 45, 21],
      [15, 40, 31],
      [10, 20, 11],
      [35, 10, 11]
    ]
  ]
}}

iex> ~s(
...>   {
...>     "type": "Polygon",
...>     "coordinates": [
...>       [[35, 10, 11],
...>        [45, 45, 21],
...>        [15, 40, 31],
...>        [10, 20, 11],
...>        [35, 10, 11]],
...>       [[20, 30, 11],
...>        [35, 35, 14],
...>        [30, 20, 12],
...>        [20, 30, 11]]
...>     ]
...>   }
...> )
iex> |> Jason.decode!()
iex> |> PolygonZ.from_geo_json()
{:ok, %PolygonZ{
  rings: [[
    [35, 10, 11],
    [45, 45, 21],
    [15, 40, 31],
    [10, 20, 11],
    [35, 10, 11]
  ], [
    [20, 30, 11],
    [35, 35, 14],
    [30, 20, 12],
    [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.

Link to this function

from_wkb(wkb, mode \\ :binary)

View Source

Specs

from_wkb(Geometry.wkb(), Geometry.mode()) ::
  {:ok, t()} | {:ok, t(), Geometry.srid()} | Geometry.wkb_error()

Returns an :ok tuple with the PolygonZ 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.PointZ.from_wkb/2 function.

Link to this function

from_wkb!(wkb, mode \\ :binary)

View Source

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 PolygonZ 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> PolygonZ.from_wkt("
...>   POLYGON Z (
...>     (35 10 11, 45 45 22, 15 40 33, 10 20 55, 35 10 11),
...>     (20 30 22, 35 35 33, 30 20 88, 20 30 22)
...>   )
...> ")
{:ok,
 %PolygonZ{
   rings: [
     [
       [35, 10, 11],
       [45, 45, 22],
       [15, 40, 33],
       [10, 20, 55],
       [35, 10, 11]
     ], [
       [20, 30, 22],
       [35, 35, 33],
       [30, 20, 88],
       [20, 30, 22]
     ]
   ]
}}

iex> "
...>   SRID=789;
...>   POLYGON Z (
...>     (35 10 11, 45 45 22, 15 40 33, 10 20 55, 35 10 11),
...>     (20 30 22, 35 35 33, 30 20 88, 20 30 22)
...>   )
...> "
iex> |> PolygonZ.from_wkt()
{:ok,
 %PolygonZ{
   rings: [
     [
       [35, 10, 11],
       [45, 45, 22],
       [15, 40, 33],
       [10, 20, 55],
       [35, 10, 11]
     ], [
       [20, 30, 22],
       [35, 35, 33],
       [30, 20, 88],
       [20, 30, 22]
     ]
   ]
 }, 789}

iex> PolygonZ.from_wkt("Polygon Z EMPTY")
{:ok, %PolygonZ{}}

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 PolygonZ.

Examples

iex> PolygonZ.new()
%PolygonZ{rings: []}

Specs

new([Geometry.LineStringZ.t()]) :: t()

Creates a PolygonZ from the given rings.

Examples

iex> 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)
...>   ])
...> ])
%PolygonZ{
  rings: [
    [[35, 10, 13], [45, 45, 23], [10, 20, 33], [35, 10, 13]],
    [[20, 30, 13], [35, 35, 23], [30, 20, 33], [20, 30, 13]]
  ]
}

iex> PolygonZ.new()
%PolygonZ{}

Specs

to_geo_json(t()) :: Geometry.geo_json_term()

Returns the GeoJSON term of a PolygonZ.

Examples

iex> PolygonZ.to_geo_json(
...>   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)
...>     ])
...>   ])
...> )
%{
  "type" => "Polygon",
  "coordinates" => [
    [
      [35, 10, 13],
      [45, 45, 23],
      [10, 20, 33],
      [35, 10, 13]
    ], [
      [20, 30, 13],
      [35, 35, 23],
      [30, 20, 33],
      [20, 30, 13]
    ]
  ]
}
Link to this function

to_wkb(polygon_z, opts \\ [])

View Source

Specs

to_wkb(t(), opts) :: Geometry.wkb()
when opts: [
       endian: Geometry.endian(),
       srid: Geometry.srid(),
       mode: Geometry.mode()
     ]

Returns the WKB representation for a PolygonZ.

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.

Link to this function

to_wkt(polygon_z, opts \\ [])

View Source

Specs

to_wkt(t(), opts) :: Geometry.wkt() when opts: [{:srid, Geometry.srid()}]

Returns the WKT representation for a PolygonZ. With option :srid an EWKT representation with the SRID is returned.

Examples

iex> PolygonZ.to_wkt(PolygonZ.new())
"Polygon Z EMPTY"

iex> PolygonZ.to_wkt(PolygonZ.new(), srid: 1123)
"SRID=1123;Polygon Z EMPTY"

iex> PolygonZ.to_wkt(
...>   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)
...>     ])
...>   ])
...> )
"Polygon Z ((35 10 13, 45 45 23, 10 20 33, 35 10 13), (20 30 13, 35 35 23, 30 20 33, 20 30 13))"