Geometry.Point (Geometry v0.3.0) View Source
A point struct, representing a 2D point.
Link to this section Summary
Functions
Returns true
if the given Point
is empty.
Creates a Point
from the given coordinate.
Returns an :ok
tuple with the Point
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 Point
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 Point
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 Point
.
Creates a Point
from the given coordinate
.
Creates a Point
from the given x
and y
.
Returns the GeoJSON term of a Point
.
Returns the WKB representation for a Point
.
Returns the WKT representation for a Point
. With option :srid
an EWKT
representation with the SRID is returned.
Link to this section Types
Specs
t() :: %Geometry.Point{coordinate: Geometry.coordinate() | nil}
Link to this section Functions
Specs
Returns true
if the given Point
is empty.
Examples
iex> Point.empty?(Point.new())
true
iex> Point.empty?(Point.new(1, 2))
false
Specs
from_coordinates(Geometry.coordinate() | [nil, ...]) :: t()
Creates a Point
from the given coordinate.
Examples
iex> Point.from_coordinates([[-1, 1]])
%Point{coordinate: [-1, 1]}
Specs
from_geo_json(Geometry.geo_json_term()) :: {:ok, t()} | Geometry.geo_json_error()
Returns an :ok
tuple with the Point
from the given GeoJSON term.
Otherwise returns an :error
tuple.
Examples
iex> ~s({"type": "Point", "coordinates": [1.1, 2.2]})
iex> |> Jason.decode!()
iex> |> Point.from_geo_json()
{:ok, %Point{coordinate: [1.1, 2.2]}}
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() | {t(), Geometry.srid()}} | Geometry.wkb_error()
Returns an :ok
tuple with the Point
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
.
Examples
iex> Point.from_wkb(
...> "00000000017FF80000000000007FF8000000000000",
...> :hex
...> )
{:ok, %Point{coordinate: nil}}
iex> Point.from_wkb(
...> "00000000013FF199999999999A400199999999999A",
...> :hex
...> )
{:ok, %Point{coordinate: [1.1, 2.2]}}
iex> Point.from_wkb(
...> "01010000009A9999999999F13F9A99999999990140",
...> :hex
...> )
{:ok, %Point{coordinate: [1.1, 2.2]}}
iex> Point.from_wkb(
...> "0020000001000012673FF199999999999A400199999999999A",
...> :hex
...> )
{:ok, {%Point{coordinate: [1.1, 2.2]}, 4711}}
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()} | {t(), Geometry.srid()} | Geometry.wkt_error()
Returns an :ok
tuple with the Point
from the given WKT string. Otherwise
returns an :error
tuple.
If the geometry contains an SRID the id is added to the tuple.
Examples
iex> Point.from_wkt("Point (-5.1 7.8)")
{:ok, %Point{coordinate: [-5.1, 7.8]}}
iex> Point.from_wkt("SRID=7219;Point (-5.1 7.8)")
{:ok, {%Point{coordinate: [-5.1, 7.8]}, 7219}}
iex> Point.from_wkt("Point EMPTY")
{:ok, %Point{}}
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 Point
.
Examples
iex> Point.new()
%Point{coordinate: nil}
Specs
new(Geometry.coordinate()) :: t()
Creates a Point
from the given coordinate
.
Examples
iex> Point.new([1.5, -2.1])
%Point{coordinate: [1.5, -2.1]}
Specs
Creates a Point
from the given x
and y
.
Examples
iex> Point.new(-1.1, 2.2)
%Point{coordinate: [-1.1, 2.2]}
Specs
to_geo_json(t()) :: Geometry.geo_json_term()
Returns the GeoJSON term of a Point
.
Examples
iex> Point.to_geo_json(Point.new(1, 2))
%{"type" => "Point", "coordinates" => [1, 2]}
Specs
to_wkb(t(), opts) :: Geometry.wkb() when opts: [ endian: Geometry.endian(), srid: Geometry.srid(), mode: Geometry.mode() ]
Returns the WKB representation for a Point
.
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
.
Examples
iex> Point.to_wkb(Point.new(), mode: :hex)
"00000000017FF80000000000007FF8000000000000"
iex> Point.to_wkb(Point.new(), endian: :ndr, mode: :hex)
"0101000000000000000000F87F000000000000F87F"
iex> Point.to_wkb(Point.new(1.1, 2.2), endian: :xdr, mode: :hex)
"00000000013FF199999999999A400199999999999A"
iex> Point.to_wkb(Point.new(1.1, 2.2), endian: :ndr, mode: :hex)
"01010000009A9999999999F13F9A99999999990140"
iex> Point.to_wkb(Point.new(1.1, 2.2), srid: 4711, endian: :xdr, mode: :hex)
"0020000001000012673FF199999999999A400199999999999A"
Specs
to_wkt(t(), opts) :: Geometry.wkt() when opts: [{:srid, Geometry.srid()}]
Returns the WKT representation for a Point
. With option :srid
an EWKT
representation with the SRID is returned.
Examples
iex> Point.to_wkt(Point.new())
"Point EMPTY"
iex> Point.to_wkt(Point.new(1.1, 2.2))
"Point (1.1 2.2)"
iex> Point.to_wkt(Point.new(1.1, 2.2), srid: 4711)
"SRID=4711;Point (1.1 2.2)"