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

Ingests GeoJSON into `Meridian.Graph` structures.

Requires the optional `:jason` dependency.

## Supported Geometry Types

  * `Point` — single node
  * `LineString` — edge path; intermediate vertices become nodes
  * `MultiLineString` — multiple edges
  * `Polygon` — ring of edges
  * `FeatureCollection` — iterated over features

## Examples

    geojson = ~s[{"type":"FeatureCollection","features":[...]}]
    {:ok, graph} = Meridian.IO.GeoJSON.from_string(geojson)

# `from_file`

```elixir
@spec from_file(
  Path.t(),
  keyword()
) :: {:ok, Meridian.Graph.t()} | {:error, String.t()}
```

Reads a GeoJSON file and builds a `Meridian.Graph`.

Returns `{:ok, graph}` on success or `{:error, reason}` on failure.

# `from_file!`

```elixir
@spec from_file!(
  Path.t(),
  keyword()
) :: Meridian.Graph.t()
```

Reads a GeoJSON file and builds a `Meridian.Graph`, raising on error.

# `from_map`

```elixir
@spec from_map(
  map(),
  keyword()
) :: Meridian.Graph.t()
```

Builds a graph from a decoded GeoJSON map.

# `from_string`

```elixir
@spec from_string(
  String.t(),
  keyword()
) :: {:ok, Meridian.Graph.t()} | {:error, String.t()}
```

Parses a GeoJSON string and builds a `Meridian.Graph`.

Returns `{:ok, graph}` on success or `{:error, reason}` on failure.

## Options

  * `:kind` — `:directed` (default) or `:undirected`
  * `:crs` — CRS string override, default `"EPSG:4326"`
  * `:weight_fn` — function `(%Geo.LineString{} -> number)` to compute edge weights

## Examples

    iex> geojson = ~s|{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"LineString","coordinates":[[0,0],[0,1]]},"properties":{}}]}|
    iex> {:ok, graph} = Meridian.IO.GeoJSON.from_string(geojson)
    iex> Meridian.Graph.node_count(graph) == 2
    true
    iex> Meridian.Graph.edge_count(graph) == 1
    true

# `from_string!`

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

Parses a GeoJSON string and builds a `Meridian.Graph`, raising on error.

---

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