# `Geostatex.GeoFrame`
[🔗](https://github.com/CountlinkX-Solutions/geostatex/blob/v0.6.0/lib/geostatex/geo_frame.ex#L1)

Adapter between [GeoFrame](https://github.com/CountlinkX-Solutions/geoframe) and Geostatex.

Geostatex 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, ...}` to your own dependencies to use it.

The observations are the centroids of the geometries of a `GeoFrame.GeoDataFrame` (a point is
its own centroid) and the values one of its numeric columns:

  * `variogram/3` - a `Geostatex.Variogram`;
  * `kriging/4` - a `Geostatex.Kriging` model (`:ordinary` or `:universal`);
  * `cross_validate/4` - `Geostatex.Kriging.cross_validate/4`;
  * `predict/3` - predictions and kriging variances at the centroids of another frame, as
    columns of that frame;
  * `grid/3` - predictions on a regular grid, as a frame of points.

## Geographic coordinates

Variograms and universal kriging are Euclidean, so they raise `ArgumentError` on a geographic
CRS unless `allow_geographic: true`. `kriging/4` with `:ordinary` instead uses great-circle
distances on a geographic frame (`coordinates_type: :geographic`) unless told otherwise.

## Examples

    samples = GeoFrame.read_file!("meuse.gpkg")
    model = Geostatex.GeoFrame.kriging(samples, "log_zinc", :ordinary, variogram_model: :spherical)
    Geostatex.GeoFrame.grid(model, samples, cell: 40.0)

# `cross_validate`

```elixir
@spec cross_validate(struct(), String.t() | atom(), :ordinary | :universal, keyword()) ::
  map()
```

Leave-one-out cross-validation (`Geostatex.Kriging.cross_validate/4`) of `column` at the frame's
centroids, with the options of `kriging/4` (and `:n_closest_points`).

# `grid`

```elixir
@spec grid(Geostatex.Kriging.t(), struct() | tuple(), keyword()) :: struct()
```

Predictions on a regular grid of points, as a `GeoFrame.GeoDataFrame` with the columns `"x"`,
`"y"`, `"prediction"` and `"variance"`. `extent` is a frame (its total bounds) or
`{min_x, min_y, max_x, max_y}`. Options:

  * `:cell` - the grid spacing, or `:nx` and `:ny`, the number of columns and rows (default 50
    each);
  * `:max_distance` - drop the cells farther than this from every observation;
  * `:crs` - the CRS of the result (default the extent frame's);
  * other options go to `Geostatex.Kriging.execute/5` (`:n_closest_points`).

# `kriging`

```elixir
@spec kriging(struct(), String.t() | atom(), :ordinary | :universal, keyword()) ::
  Geostatex.Kriging.t()
```

A kriging model of `column` at the frame's centroids: `kind` is `:ordinary` (default) or
`:universal`, with the options of `Geostatex.Kriging.ordinary/3` or `universal/3`. A geographic
frame uses great-circle distances for ordinary kriging unless `:coordinates_type` is given.

# `points`

```elixir
@spec points(struct()) :: {[float()], [float()]}
```

The centroid coordinates of a frame's (or series') geometries, as `{xs, ys}` lists.

# `predict`

```elixir
@spec predict(Geostatex.Kriging.t(), struct(), keyword()) :: struct()
```

Predicts at the centroids of `targets` (a `GeoFrame.GeoDataFrame`) and returns it with two new
columns, `"prediction"` and `"variance"` (or `prefix <> "prediction"` with `prefix:`). Other
options go to `Geostatex.Kriging.execute/5` (`:n_closest_points`, `:specified_drift_arrays`).

# `variogram`

```elixir
@spec variogram(struct(), String.t() | atom(), keyword()) :: Geostatex.Variogram.t()
```

The experimental variogram (`Geostatex.Variogram.new/3`) of `column` at the frame's centroids.
Options of `Geostatex.Variogram.new/3`, plus `allow_geographic: true`.

---

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