# `Networkex.GeoFrame`
[🔗](https://github.com/CountlinkX-Solutions/networkex/blob/v0.3.0/lib/networkex/geo_frame.ex#L1)

Adapter between [GeoFrame](https://hexdocs.pm/geoframe), a library of geospatial data frames,
and Networkex.

Networkex does not depend on GeoFrame. This module calls GeoFrame's public API (and Explorer's,
which GeoFrame brings) at runtime, and raises an `ArgumentError` saying so when GeoFrame is not
loaded. Add `{:geoframe, "~> 0.3.4"}` to your own dependencies to use it.

  * `network/2` builds a `Networkex.Network` from the line geometries of a
    `GeoFrame.GeoDataFrame` or `GeoFrame.GeoSeries`;
  * `snap/2` snaps the centroids of a frame's geometries (points are their own centroid);
  * `arcs/2`, `points/2` and `paths/2` turn networks, point patterns and shortest paths back into
    `GeoFrame.GeoDataFrame`s, for maps (`GeoFrame.Kino.deck/2`) and further GeoFrame work.

## Geographic coordinates

Network lengths are Euclidean, so on longitude/latitude they measure degrees. `network/2`
raises `ArgumentError` for a geographic CRS unless `allow_geographic: true`; project the frame
first (`GeoFrame.GeoDataFrame.to_crs/2`).

## Examples

    streets = GeoFrame.read_file!("streets.shp")
    ntw = Networkex.GeoFrame.network(streets)
    crimes = Networkex.GeoFrame.snap(ntw, GeoFrame.read_file!("crimes.shp"))
    Networkex.GeoFrame.arcs(ntw, columns: %{"crimes" => Networkex.Network.counts_per_link(ntw, crimes)})

# `arcs`

```elixir
@spec arcs(Networkex.Network.t(), keyword()) :: struct()
```

The arcs of the network as a `GeoFrame.GeoDataFrame` of two-point lines with the columns
`"arc"` (index), `"i"`, `"j"` (vertex ids) and `"length"`. With `graph: true`, the graph edges
instead (straight lines between their end vertices). Options:

  * `:columns` - a map of extra columns, each a list with one value per arc (or edge), such as
    `Networkex.Network.counts_per_link/3`;
  * `:crs` - the CRS of the result.

# `network`

```elixir
@spec network(struct(), keyword()) :: Networkex.Network.t()
```

A network from the line geometries (`LineString` or `MultiLineString`) of a
`GeoFrame.GeoDataFrame` or `GeoFrame.GeoSeries`. Options of `Networkex.Network.new/2`, plus
`allow_geographic: true` to accept longitude/latitude.

# `paths`

```elixir
@spec paths([map()], keyword()) :: struct()
```

Shortest paths (`Networkex.Network.shortest_paths/3`) as a `GeoFrame.GeoDataFrame` of lines
with the columns `"source"`, `"dest"` and `"length"`; `:crs` as in `arcs/2`.

# `points`

```elixir
@spec points(Networkex.PointPattern.t(), keyword()) :: struct()
```

A point pattern as a `GeoFrame.GeoDataFrame` of points: the snapped points (default) or, with
`which: :observed`, the observations as given; with the columns `"i"`, `"j"` (the arc) and
`"snap_distance"`, plus `:columns` and `:crs` as in `arcs/2`.

# `snap`

```elixir
@spec snap(Networkex.Network.t(), struct()) :: Networkex.PointPattern.t()
```

Snaps the centroids of the geometries of a `GeoFrame.GeoDataFrame` or `GeoFrame.GeoSeries` to
the network (`Networkex.Network.snap/2`).

---

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