Geometry.LineString (Geometry v0.2.0) View Source
A line-string struct, representing a 2D line.
A none empty line-string requires at least two points.
Link to this section Summary
Functions
Returns true
if the given LineString
is empty.
Creates a LineString
from the given coordinates.
Returns an :ok
tuple with the LineString
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 LineString
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 LineString
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 LineString
.
Creates a LineString
from the given Geometry.Point
s.
Returns the GeoJSON term of a LineString
.
Returns the WKB representation for a LineString
.
Returns the WKT representation for a LineString
. With option :srid
an
EWKT representation with the SRID is returned.
Link to this section Types
Specs
t() :: %Geometry.LineString{points: Geometry.coordinates()}
Link to this section Functions
Specs
Returns true
if the given LineString
is empty.
Examples
iex> LineString.empty?(LineString.new())
true
iex> LineString.empty?(
...> LineString.new(
...> [Point.new(1, 2), Point.new(3, 4)]
...> )
...> )
false
Specs
from_coordinates([Geometry.coordinate()]) :: t()
Creates a LineString
from the given coordinates.
Examples
iex> LineString.from_coordinates(
...> [[-1, 1], [-2, 2], [-3, 3]]
...> )
%LineString{
points: [
[-1, 1],
[-2, 2],
[-3, 3]
]
}
Specs
from_geo_json(Geometry.geo_json_term()) :: {:ok, t()} | Geometry.geo_json_error()
Returns an :ok
tuple with the LineString
from the given GeoJSON term.
Otherwise returns an :error
tuple.
Examples
iex> ~s(
...> {
...> "type": "LineString",
...> "coordinates": [
...> [1.1, 1.2],
...> [20.1, 20.2]
...> ]
...> }
...> )
iex> |> Jason.decode!()
iex> |> LineString.from_geo_json()
{:ok, %LineString{points: [
[1.1, 1.2],
[20.1, 20.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()} | {:ok, t(), Geometry.srid()} | Geometry.wkb_error()
Returns an :ok
tuple with the LineString
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.Point.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 LineString
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> LineString.from_wkt(
...> "LineString (-5.1 7.8, 0.1 0.2)"
...> )
{:ok, %LineString{
points: [
[-5.1, 7.8],
[0.1, 0.2]
]
}}
iex> LineString.from_wkt(
...> "SRID=7219;LineString (-5.1 7.8, 0.1 0.2)"
...> )
{:ok, %LineString{
points: [
[-5.1, 7.8],
[0.1, 0.2]
]
}, 7219}
iex> LineString.from_wkt("LineString EMPTY")
{:ok, %LineString{}}
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 LineString
.
Examples
iex> LineString.new()
%LineString{points: []}
Specs
new([Geometry.Point.t()]) :: t()
Creates a LineString
from the given Geometry.Point
s.
Examples
iex> LineString.new([Point.new(1, 2), Point.new(3, 4)])
%LineString{points: [[1, 2], [3, 4]]}
Specs
to_geo_json(t()) :: Geometry.geo_json_term()
Returns the GeoJSON term of a LineString
.
Examples
iex> LineString.to_geo_json(
...> LineString.new([
...> Point.new(-1.1, -2.2),
...> Point.new(1.1, 2.2)
...> ])
...> )
%{
"type" => "LineString",
"coordinates" => [
[-1.1, -2.2],
[1.1, 2.2]
]
}
Specs
to_wkb(line_string, opts) :: wkb when line_string: t() | Geometry.coordinates(), opts: [ endian: Geometry.endian(), srid: Geometry.srid(), mode: Geometry.mode() ], wkb: Geometry.wkb()
Returns the WKB representation for a LineString
.
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.Point.to_wkb/1
function.
Specs
to_wkt(t(), opts) :: Geometry.wkt() when opts: [{:srid, Geometry.srid()}]
Returns the WKT representation for a LineString
. With option :srid
an
EWKT representation with the SRID is returned.
Examples
iex> LineString.to_wkt(LineString.new())
"LineString EMPTY"
iex> LineString.to_wkt(
...> LineString.new([
...> Point.new(7.1, 8.1),
...> Point.new(9.2, 5.2)
...> ])
...> )
"LineString (7.1 8.1, 9.2 5.2)"
iex> LineString.to_wkt(
...> LineString.new([
...> Point.new(7.1, 8.1),
...> Point.new(9.2, 5.2)
...> ]),
...> srid: 123
...> )
"SRID=123;LineString (7.1 8.1, 9.2 5.2)"