Geometry.FeatureCollection (Geometry v0.3.0) View Source
A collection of Geometry.Featre
s.
GeometryCollectionZM
implements the protocols Enumerable
and Collectable
.
Examples
iex> Enum.filter(
...> FeatureCollection.new([
...> Feature.new(
...> geometry: Point.new(11, 12),
...> properties: %{"facility" => "Hotel"}
...> ),
...> Feature.new(
...> geometry: Point.new(55, 55),
...> properties: %{"facility" => "Tower"}
...> )
...> ]),
...> fn %Feature{properties: properties} ->
...> Map.get(properties, "facility") == "Hotel"
...> end
...> )
[%Feature{geometry: %Point{coordinate: [11, 12]}, properties: %{"facility" => "Hotel"}}]
iex> Enum.into(
...> [Feature.new(geometry: Point.new(5, 1), properties: %{"area" => 51})],
...> FeatureCollection.new([
...> Feature.new(geometry: Point.new(4, 2), properties: %{"area" => 42})
...> ])
...> )
%FeatureCollection{
features:
MapSet.new([
%Feature{geometry: %Point{coordinate: [4, 2]}, properties: %{"area" => 42}},
%Feature{geometry: %Point{coordinate: [5, 1]}, properties: %{"area" => 51}}
])
}
Link to this section Summary
Functions
Returns true
for an empty FeatureCollection
.
Returns an :ok
tuple with the FeatureCollection
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.
Checks if FeatureCollection
contains geometry
.
Creates an empty FeatureCollection
.
Creates a FeatureCollection
.
Returns the number of elements in FeatureCollection
.
Returns the GeoJSON term of a FeatureCollection
.
Converts FeatureCollection
to a list.
Link to this section Types
Specs
t() :: %Geometry.FeatureCollection{features: MapSet.t(Geometry.Feature.t())}
Link to this section Functions
Specs
Returns true
for an empty FeatureCollection
.
Examples
iex> FeatureCollection.empty?(FeatureCollection.new())
true
Specs
from_geo_json(Geometry.geo_json_term(), opts) :: {:ok, t()} | Geometry.geo_json_error() when opts: [{:type, :z | :m | :zm}]
Returns an :ok
tuple with the FeatureCollection
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": "FeatureCollection",
...> "features": [
...> {
...> "type": "Feature",
...> "geometry": {"type": "Point", "coordinates": [1, 2, 3]},
...> "properties": {"facility": "Hotel"}
...> }, {
...> "type": "Feature",
...> "geometry": {"type": "Point", "coordinates": [4, 3, 2]},
...> "properties": {"facility": "School"}
...> }
...> ]
...> })
iex> |> Jason.decode!()
iex> |> FeatureCollection.from_geo_json(type: :z)
{
:ok,
%FeatureCollection{
features:
MapSet.new([
%Feature{
geometry: %PointZ{coordinate: [1, 2, 3]},
properties: %{"facility" => "Hotel"}
},
%Feature{
geometry: %PointZ{coordinate: [4, 3, 2]},
properties: %{"facility" => "School"}
}
])
}
}
Specs
from_geo_json!(Geometry.geo_json_term(), opts) :: t() when opts: [{:type, :z | :m | :zm}]
The same as from_geo_josn/1
, but raises a Geometry.Error
exception if it
fails.
Examples
iex> ~s({
...> "type": "FeatureCollection",
...> "features": [
...> {
...> "type": "Feature",
...> "geometry": {"type": "Point", "coordinates": [1, 2, 3]},
...> "properties": {"facility": "Hotel"}
...> }, {
...> "type": "Feature",
...> "geometry": {"type": "Point", "coordinates": [4, 3, 2]},
...> "properties": {"facility": "School"}
...> }
...> ]
...> })
iex> |> Jason.decode!()
iex> |> FeatureCollection.from_geo_json!(type: :m)
%FeatureCollection{
features:
MapSet.new([
%Feature{
geometry: %PointM{coordinate: [1, 2, 3]},
properties: %{"facility" => "Hotel"}
},
%Feature{
geometry: %PointM{coordinate: [4, 3, 2]},
properties: %{"facility" => "School"}
}
])
}
Specs
member?(t(), Geometry.t()) :: boolean()
Checks if FeatureCollection
contains geometry
.
Examples
iex> FeatureCollection.member?(
...> FeatureCollection.new([
...> Feature.new(geometry: Point.new(11, 12)),
...> Feature.new(geometry:
...> LineString.new([
...> Point.new(21, 22),
...> Point.new(31, 32)
...> ])
...> )
...> ]),
...> Feature.new(geometry: Point.new(11, 12))
...> )
true
iex> FeatureCollection.member?(
...> FeatureCollection.new([
...> Feature.new(geometry: Point.new(11, 12)),
...> Feature.new(geometry:
...> LineString.new([
...> Point.new(21, 22),
...> Point.new(31, 32)
...> ])
...> )
...> ]),
...> Feature.new(geometry: Point.new(1, 2))
...> )
false
Specs
new() :: t()
Creates an empty FeatureCollection
.
Examples
iex> FeatureCollection.new()
%FeatureCollection{}
Specs
new([Geometry.Feature.t()]) :: t()
Creates a FeatureCollection
.
Examples
iex> FeatureCollection.new([
...> Feature.new(
...> geometry: Point.new(1, 2),
...> properties: %{facility: :hotel}
...> ),
...> Feature.new(
...> geometry: Point.new(3, 4),
...> properties: %{facility: :school}
...> )
...> ])
%FeatureCollection{features: MapSet.new([
%Feature{
geometry: %Point{coordinate: [1, 2]},
properties: %{facility: :hotel}},
%Feature{
geometry: %Point{coordinate: [3, 4]},
properties: %{facility: :school}}
])}
Specs
size(t()) :: non_neg_integer()
Returns the number of elements in FeatureCollection
.
Examples
iex> FeatureCollection.size(
...> FeatureCollection.new([
...> Feature.new(geometry: Point.new(11, 12)),
...> Feature.new(geometry:
...> LineString.new([
...> Point.new(21, 22),
...> Point.new(31, 32)
...> ])
...> )
...> ])
...> )
2
Specs
to_geo_json(t()) :: Geometry.geo_json_term()
Returns the GeoJSON term of a FeatureCollection
.
Examples
iex> FeatureCollection.to_geo_json(FeatureCollection.new([
...> Feature.new(
...> geometry: Point.new(1, 2),
...> properties: %{facility: :hotel}
...> )
...> ]))
%{
"type" => "FeatureCollection",
"features" => [
%{
"type" => "Feature",
"geometry" => %{"coordinates" => [1, 2], "type" => "Point"},
"properties" => %{facility: :hotel}
}
]
}
Specs
to_list(t()) :: [Geometry.t()]
Converts FeatureCollection
to a list.
Examples
iex> FeatureCollection.to_list(
...> FeatureCollection.new([
...> Feature.new(geometry: Point.new(11, 12))
...> ])
...> )
[%Feature{geometry: %Point{coordinate: [11, 12]}, properties: %{}}]