---
title: "many-automap-examples"
output:
  rmarkdown::html_vignette:
    fig_width: 7
    fig_height: 7
vignette: >
  %\VignetteIndexEntry{many-automap-examples}
  %\VignetteEncoding{UTF-8}
  %\VignetteEngine{knitr::rmarkdown}
editor_options: 
  chunk_output_type: console
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r examples, eval = TRUE}
library(SOmap)

# lonrange, latrange
# lonvec, latvec
# sp, sf object
# raster, stars object
# file


set.seed(1)
SOmap_auto()
```

```{r examples1, eval = TRUE}
SOmap_auto(target = "+proj=laea +lat_0=-20 +ellps=WGS84")
```

```{r examples2, eval = TRUE}
llx <-  c(100, 120)
lly <- c(-60, -30)
SOmap_auto(llx, lly)
```

```{r examples3, eval = TRUE}
SOmap_auto(llx, lly, target = NULL)
```

```{r examples4, eval = TRUE}
SOmap_auto(cbind(llx, lly), target = NULL)
```

```{r examples5, eval = TRUE}
SOmap_auto(SOmap_data$mirounga_leonina$lon, SOmap_data$mirounga_leonina$lat, target = "laea")
```

```{r examples6, eval = TRUE}
SOmap_auto(SOmap_data$mirounga_leonina$lon, SOmap_data$mirounga_leonina$lat, centre_lon = 147)
```

```{r examples7, eval = TRUE}

SOmap_auto(SOmap_data$mirounga_leonina$lon, SOmap_data$mirounga_leonina$lat, target = NULL)
```

```{r examples8, eval = FALSE}
## causes crash for yet-to-be-investigated reasons
SOmap_auto(ice)
```


```{r examples13, eval=FALSE}
## causes crash for yet-to-be-investigated reasons
SOmap_auto(ice, target = "laea", centre_lon = 147, centre_lat = -42)
SOplot(ice, col = palr::ice_pal(100))
```

```{r examples14, eval = FALSE}
## causes crash for yet-to-be-investigated reasons
SOmap_auto(ice, centre_lon = 147, centre_lat = -42)
SOplot(ice, col = palr::ice_pal(100))
```

```{r examples15, eval = FALSE}
## causes crash for yet-to-be-investigated reasons
SOmap_auto(ice, target = "merc", centre_lon = 147, centre_lat = -42)
SOplot(ice, col = palr::ice_pal(100))
```

```{r examples16, eval = TRUE}
SOmap_auto(x = c(10, 60), y = c(-40, -70))
```

```{r examples17, eval = TRUE}
SOmap_auto(x=c(10,60), y=c(-40,-70), trim_background = FALSE)
```

```{r examples18, eval = TRUE}
x <- cbind(c(runif(50, -180, -160), runif(50, 160, 180)), runif(100, -65, -30))
SOmap_auto(x)
```


```{r examples19, eval = TRUE}
x <- cbind(c(runif(50, -180, -130), runif(50, 160, 180)), runif(100, -65, -30))
SOmap_auto(x)
```

```{r examples20, eval = TRUE}
x <- cbind(c(runif(50, -180, -130), runif(50, 130, 180)), runif(100, -65, -30))
SOmap_auto(x)
```

```{r examples21, eval = TRUE}
x <- cbind(c(runif(50, -180, -160), runif(50, 130, 180)), runif(100, -65, -30))
SOmap_auto(x)
```




```{r examples22, eval = TRUE}
x <- cbind(c(runif(50, -180, -160), runif(50, 160, 180)), runif(100, -85, -50))

SOmap_auto(x)
```


```{r examples23, eval = TRUE}
x <- cbind(c(runif(50, -180, -130), runif(50, 160, 180)), runif(100, -85, -50))

SOmap_auto(x)
```

```{r examples24, eval = TRUE}
x <- cbind(c(runif(50, -180, -130), runif(50, 130, 180)), runif(100, -85, -50))
SOmap_auto(x)
```

```{r examples25, eval = TRUE}
x <- cbind(c(runif(50, -180, -160), runif(50, 130, 180)), runif(100, -85, -50))
SOmap_auto(x)
```


Handle missing values in input data. 

temporarily turn this off ...

```{r examples26, eval = FALSE}
data("albatross", package = "adehabitatLT")
## convert the albatross data to a single matrix of lon, lat points
albatrack <- do.call(rbind, lapply(albatross, function(z) terra::project(rbind(as.matrix(z[, c("x", "y")]), NA), from  = "+proj=utm +zone=42 +south +datum=WGS84", to = "EPSG:4326")))

## construct the map and return it, but don't plot it
alb_map <- SOmap_auto(albatrack[, 1], albatrack[, 2])
alb_map
```
