# `Meridian.Render.GeoJSON`
[🔗](https://github.com/code-shoily/meridian/blob/v0.1.0/lib/meridian/render/geojson.ex#L1)

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)

# `to_file`

```elixir
@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`.

# `to_string`

```elixir
@spec to_string(
  Meridian.Graph.t(),
  keyword()
) :: String.t()
```

Converts a spatial graph to a GeoJSON FeatureCollection string.

## Options

  * `:include_edges` — emit edges as `LineString` features (default `true`)
  * `:edge_properties_fn` — function `(from, to, weight) -> map` for edge props
  * `:node_properties_fn` — function `(id, data) -> map` for 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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
