View Source Geometry (Geometry v0.3.1)
A set of geometry types for WKT/WKB and GeoJson.
Link to this section Summary
Types
An n-dimensional coordinate.
A list of n-dimensional coordinates.
Byte order.
Errors that can occur when a geometry is generating from GeoJson.
A GeoJson term.
The Spatial Reference System Identifier to identify projected, unprojected, and local spatial coordinate system definitions.
A geometry is one of the provided geometries or geometry-collections.
Well-known binary The binary representation of WKT.
Errors that can occur when a geometry is generating from WKT.
Well-known text (WKT) is a text markup language for representing vector geometry objects.
Errors that can occur when a geometry is generating from WKT.
Functions
Returns true if a geometry is empty.
Returns an :ok
tuple with the geometry from the given GeoJSON term.
Otherwise returns an :error
tuple.
The same as from_geo_josn/1
, but raises a Geometry.Error
exception if it
fails.
Returns an :ok
tuple with the geometry from the given WKT 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 geometry 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.
Returns the GeoJSON term representation of a geometry.
Returns the WKB representation of a geometry.
Returns the WKT representation of a geometry. An optional :srid
can be set
in the options.
Link to this section Types
Specs
coordinate() :: [number(), ...]
An n-dimensional coordinate.
Specs
coordinates() :: [coordinate()]
A list of n-dimensional coordinates.
Specs
endian() :: :ndr | :xdr
Byte order.
:ndr
: Little endian byte order encoding:xdr
: Big endian byte order encoding
Specs
geo_json_error() :: {:error, :coordinates_not_found | :geometries_not_found | :invalid_data | :type_not_found | :unknown_type}
Errors that can occur when a geometry is generating from GeoJson.
Specs
geo_json_term() :: map()
A GeoJson term.
Specs
mode() :: :binary | :hex
Specs
srid() :: non_neg_integer()
The Spatial Reference System Identifier to identify projected, unprojected, and local spatial coordinate system definitions.
Specs
t() :: Geometry.GeometryCollection.t() | Geometry.GeometryCollectionM.t() | Geometry.GeometryCollectionZ.t() | Geometry.GeometryCollectionZM.t() | Geometry.LineString.t() | Geometry.LineStringM.t() | Geometry.LineStringZ.t() | Geometry.LineStringZM.t() | Geometry.MultiLineString.t() | Geometry.MultiLineStringM.t() | Geometry.MultiLineStringZ.t() | Geometry.MultiLineStringZM.t() | Geometry.MultiPoint.t() | Geometry.MultiPointM.t() | Geometry.MultiPointZ.t() | Geometry.MultiPointZM.t() | Geometry.MultiPolygon.t() | Geometry.MultiPolygonM.t() | Geometry.MultiPolygonZ.t() | Geometry.MultiPolygonZM.t() | Geometry.Polygon.t() | Geometry.PolygonM.t() | Geometry.PolygonZ.t() | Geometry.PolygonZM.t() | Geometry.Point.t() | Geometry.PointM.t() | Geometry.PointZ.t() | Geometry.PointZM.t()
A geometry is one of the provided geometries or geometry-collections.
Specs
wkb() :: binary()
Well-known binary The binary representation of WKT.
Specs
wkb_error() :: {:error, %{expected: t(), got: t()}} | {:error, message :: String.t(), rest :: binary(), offset :: non_neg_integer()}
Errors that can occur when a geometry is generating from WKT.
Specs
wkt() :: String.t()
Well-known text (WKT) is a text markup language for representing vector geometry objects.
Specs
wkt_error() :: {:error, %{expected: t(), got: t()}} | {:error, message :: String.t(), rest :: String.t(), {line :: pos_integer(), offset :: non_neg_integer()}, offset :: non_neg_integer()}
Errors that can occur when a geometry is generating from WKT.
Link to this section Functions
Specs
Returns true if a geometry is empty.
Examples
iex> Geometry.empty?(Point.new(1, 2))
false
iex> Geometry.empty?(Point.new())
true
iex> Geometry.empty?(LineString.new([]))
true
Specs
from_geo_json(geo_json_term(), opts) :: {:ok, t() | Geometry.Feature.t() | Geometry.FeatureCollection.t()} | geo_json_error() when opts: [{:type, :z | :m | :zm}]
Returns an :ok
tuple with the geometry from the given GeoJSON term.
Otherwise returns an :error
tuple.
The :type
option specifies which type is expected. The
possible values are :z
, :m
, and :zm
.
Examples
iex> ~s({"type": "Point", "coordinates": [1, 2]})
iex> |> Jason.decode!()
iex> |> Geometry.from_geo_json()
{:ok, %Point{coordinate: [1, 2]}}
iex> ~s({"type": "Point", "coordinates": [1, 2, 3, 4]})
iex> |> Jason.decode!()
iex> |> Geometry.from_geo_json(type: :zm)
{:ok, %PointZM{coordinate: [1, 2, 3, 4]}}
Specs
from_geo_json!(geo_json_term(), opts) :: t() | Geometry.Feature.t() | Geometry.FeatureCollection.t() when opts: [{:type, :z | :m | :zm}]
The same as from_geo_josn/1
, but raises a Geometry.Error
exception if it
fails.
Specs
Returns an :ok
tuple with the geometry from the given WKT string. Otherwise
returns an :error
tuple.
If WKB contains an SRID the tuple is extended by the id.
The optional second argument determines if a :hex
-string or a :binary
input is expected. The default is :binary
.
Examples
iex> Geometry.from_wkb("0101000080000000000000F03F00000000000000400000000000000840", :hex)
{:ok, %PointZ{coordinate: [1.0, 2.0, 3.0]}}
iex> Geometry.from_wkb("0020000001000012673FF00000000000004000000000000000", :hex)
{:ok, {%Point{coordinate: [1.0, 2.0]}, 4711}}
Specs
The same as from_wkb/2
, but raises a Geometry.Error
exception if it fails.
Specs
Returns an :ok
tuple with the geometry 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> Geometry.from_wkt("Point ZM (1 2 3 4)")
{:ok, %PointZM{coordinate: [1, 2, 3, 4]}}
iex> Geometry.from_wkt("SRID=42;Point (1.1 2.2)")
{:ok, {%Point{coordinate: [1.1, 2.2]}, 42}}
Specs
The same as from_wkt/1
, but raises a Geometry.Error
exception if it fails.
Specs
to_geo_json(t() | Geometry.Feature.t() | Geometry.FeatureCollection.t()) :: geo_json_term()
Returns the GeoJSON term representation of a geometry.
Examples
iex> Geometry.to_geo_json(PointZ.new(1.2, 3.4, 5.6))
%{"type" => "Point", "coordinates" => [1.2, 3.4, 5.6]}
iex> Geometry.to_geo_json(LineString.new([Point.new(1, 2), Point.new(3, 4)]))
%{"type" => "LineString", "coordinates" => [[1, 2], [3, 4]]}
Specs
Returns the WKB representation of a geometry.
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> Geometry.to_wkb(PointZ.new(1, 2, 3), endian: :ndr, mode: :hex)
"0101000080000000000000F03F00000000000000400000000000000840"
iex> Geometry.to_wkb(Point.new(1, 2), srid: 4711) |> Hex.from_binary()
"0020000001000012673FF00000000000004000000000000000"
Specs
Returns the WKT representation of a geometry. An optional :srid
can be set
in the options.
Examples
iex> Geometry.to_wkt(Point.new(1, 2))
"Point (1 2)"
iex> Geometry.to_wkt(PointZ.new(1.1, 2.2, 3.3), srid: 4211)
"SRID=4211;Point Z (1.1 2.2 3.3)"
iex> Geometry.to_wkt(LineString.new([Point.new(1, 2), Point.new(3, 4)]))
"LineString (1 2, 3 4)"