Renders a Meridian.Graph as GeoJSON.
Requires the optional :jason dependency for JSON output.
Examples
graph =
Meridian.Graph.new()
|> Meridian.Graph.add_node(:a, %{geometry: %Geo.Point{coordinates: {0.0, 0.0}}, name: "A"})
|> Meridian.Graph.add_node(:b, %{geometry: %Geo.Point{coordinates: {1.0, 1.0}}, name: "B"})
|> Meridian.Graph.add_edge_ensure(:a, :b, %{distance: 10.0})
geojson = Meridian.Render.GeoJSON.to_string(graph)
Summary
Functions
Writes a spatial graph to a GeoJSON file.
Converts a spatial graph to a GeoJSON FeatureCollection string.
Functions
@spec to_file(Meridian.Graph.t(), Path.t(), keyword()) :: :ok | {:error, File.posix()}
Writes a spatial graph to a GeoJSON file.
Options
Accepts the same options as to_string/2.
@spec to_string( Meridian.Graph.t(), keyword() ) :: String.t()
Converts a spatial graph to a GeoJSON FeatureCollection string.
Options
:include_edges— emit edges asLineStringfeatures (defaulttrue):edge_properties_fn— function(from, to, weight) -> mapfor edge props:node_properties_fn— function(id, data) -> mapfor node props
Examples
iex> g = Meridian.Graph.new()
iex> g = g
...> |> Meridian.Graph.add_node(:a, %{geometry: %Geo.Point{coordinates: {0.0, 0.0}}, label: "A"})
...> |> Meridian.Graph.add_node(:b, %{geometry: %Geo.Point{coordinates: {1.0, 1.0}}, label: "B"})
...> |> Meridian.Graph.add_edge_ensure(:a, :b, %{distance: 10.0})
iex> json = Meridian.Render.GeoJSON.to_string(g)
iex> String.contains?(json, "FeatureCollection")
true