https://github.com/inbo/territoria
https://github.com/inbo/territoria
bird breeding cluster home-range r territory
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/inbo/territoria
- Owner: inbo
- License: gpl-3.0
- Created: 2021-06-08T07:29:31.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-06-04T11:32:08.000Z (about 1 year ago)
- Last Synced: 2025-06-04T19:08:02.330Z (about 1 year ago)
- Topics: bird, breeding, cluster, home-range, r, territory
- Language: R
- Homepage: https://inbo.github.io/territoria
- Size: 203 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Citation: CITATION.cff
- Zenodo: .zenodo.json
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = file.path("man", "figures", "README-"),
out.width = "100%"
)
```
# territoria
[](https://www.repostatus.org/#active)
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://www.gnu.org/licenses/gpl-3.0.html)

[](https://github.com/inbo/territoria/actions)
[](https://app.codecov.io/gh/inbo/territoria?branch=main)




The goal of `territoria` is to cluster observations from different breeding bird surveys into territoria.
## Installation
You can install the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("remotes")
remotes::install_github("inbo/territoria")
```
## Example
We start by simulating some observations.
We need for every observation their `x` and `y` coordinates in a projected coordinate system.
`survey` is an integer id for every survey.
A survey is a unique combination of an area and date.
`status` is an integer indication the breeding status.
A higher value assume more certainty about breeding.
Set this to a constant value if you don't distinct between different certainties.
In this example we use three classes: `1`, `2` and `3`.
```{r sim-data}
library(territoria)
set.seed(20210806)
obs <- simulate_observations()
names(obs)
summary(obs$centroids)
summary(obs$observations)
obs <- obs$observations[obs$observations$observed, ]
```
Once we have a data.frame with the observations, we connect to a SQLite database and import the observations.
This assigns every observation to its own cluster.
```{r import-data}
conn <- connect_db()
import_observations(observations = obs, conn = conn, max_dist = 336)
result <- get_cluster(conn = conn)
nrow(result$observations) == nrow(result$cluster)
```
Next, we need to calculate the distance matrix.
This is not the full distance matrix.
We omit all irrelevant distances, e.g. between observations from the same survey or with a distance larger than twice the maximum cluster distance.
```{r distance}
distance_matrix(conn = conn, max_dist = 366)
```
Now we can start the clustering.
The clustering takes into account all observations with a `status` greater than or equal to the set status.
```{r cluster-3}
cluster_observation(conn = conn, status = 3, max_dist = 336)
result3 <- get_cluster(conn = conn)
nrow(result3$observations) > nrow(result3$cluster)
```
Repeat the clustering for every status level.
Note that skipping levels implies that we combine them with the lower level.
```{r cluster-1}
cluster_observation(conn = conn, status = 1, max_dist = 336)
result1 <- get_cluster(conn = conn)
nrow(result1$observations) > nrow(result1$cluster)
nrow(result3$cluster) > nrow(result1$cluster)
summary(result1$observations)
summary(result1$cluster)
```