---
title: "Linkage to the sf package"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Linkage to the `sf` package}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---
<style>
body {
text-align: justify}
</style>
```{r, echo = FALSE, eval=TRUE, include=FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
options(knitr.table.format = "html", rmarkdown.html_vignette.check_title = FALSE)

library(eRTG3D)
set.seed(123)
```

The `sf` package delivers a standardized way to encode spatial vector data, the so called Simple Features (SF). It binds to GDAL for reading and writing data, to GEOS for geometrical operations, and to Proj.4 for projection conversions and datum transformations. Therefore the `eRTG3D` package comes with some wrapper functions to convert the generated tracks to simple features. The resulting `sf, data.frame` objects enable access to the functionality of the sf package, which also includes an easy way to access spatial databases (PostGIS).

## Convert to sf
To convert tracks to a an object of type `sf, data.frame` use the `track2sf.3d()` function, which can take data.frames, matrices and move objects (containing one track!) as input. In case of data.frames and matrices, it is important that the coordinates are stored in the first three rows.

```{r eval=TRUE, fig.height=5, fig.width=7}
niclas <- track2sf.3d(niclas, CRS = 2056)
is.sf.3d(niclas)
head(niclas, 3)
```

## Convert from sf
To test if a track is of type `sf, data.frame` use the `is.sf()` function, and to convert a `sf, data.frame` back to a track data.frame use `sf2df.3d()`.

```{r eval=TRUE, fig.height=5, fig.width=7}
niclas <- sf2df.3d(niclas)
is.sf.3d(niclas)
```
