---
title: "Obtaining information about many LTER Sites"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Obtaining information about many LTER Sites}
  %\VignetteEngine{knitr::knitr}
  %\usepackage[UTF-8]{inputenc}
author: "Alessandro Oggioni"
---

Taking into account the guide on ["How to obtain site info?"](./site_information.html), here are two examples on how to aggregate information of many eLTER sites.

## By get_network_* functions: {#firstExample}

Five functions were developed to access and download informationof an entire eLTER network.

### Get general information of the network's sites:

Knowing the network elTER id (DEIMS ID of the Network, e.g. LTER-Italy <https://deims.org/network/7fef6b73-e5cb-4cd2-b438-ed32eb1504b3>), the [`get_network_sites`](https://docs.ropensci.org/ReLTER/reference/get_network_sites.html) can download general info, such as name, DEIMS ID and spatial coordinates of the sites belonging to the network selected. A map of the sites can be produced.


```r
library(dplyr)
library(leaflet)
library(ReLTER)

listItaSites <- get_network_sites(
 networkDEIMSID =
   "https://deims.org/network/7fef6b73-e5cb-4cd2-b438-ed32eb1504b3"
) %>%
  filter(!grepl('^IT', title))

knitr::kable(
  listItaSites[1:10, ],
  caption = "The list of site for LTER-Italy network"
)
```



Table: The list of site for LTER-Italy network

|title                                                  |changed                  |uri                                                    |coordinates               |
|:------------------------------------------------------|:------------------------|:------------------------------------------------------|:-------------------------|
|Acquatina - Italy                                      |2023-10-25T21:48:55+0200 |https://deims.org/8e1909ae-afc0-4207-9314-68e234d57405 |POINT (18.24 40.44)       |
|Torgnon grassland Tellinod (IT19 Aosta Valley) - Italy |2023-10-27T10:46:01+0200 |https://deims.org/a03ef869-aa6f-49cf-8e86-f791ee482ca9 |POINT (7.579028 45.84606) |
|Renon BOL1 - Italy                                     |2023-10-27T10:44:32+0200 |https://deims.org/5d32cbf8-ab7c-4acb-b29f-600fec830a1d |POINT (11.4336 46.5868)   |
|Collelongo-Selva Piana ABR1 - Italy                    |2023-07-24T16:06:23+0200 |https://deims.org/9b1d144a-dc37-4b0e-8cda-1dda1d7667da |POINT (13.5881 41.8494)   |
|Colognole TOS1 - Italy                                 |2023-10-26T13:52:46+0200 |https://deims.org/fdd9b462-d2a9-441a-80a1-f4e8947f5577 |POINT (10.4386 43.5094)   |
|Tarvisio FRI2 - Italy                                  |2023-10-27T10:45:36+0200 |https://deims.org/5907d0b6-7b4d-4260-a669-4bc0f61d1696 |POINT (13.5933 46.4894)   |
|Val Masino LOM1 - Italy                                |2023-10-27T10:46:51+0200 |https://deims.org/68a5673c-9172-48cc-88e5-b9408b203309 |POINT (9.59829 46.24215)  |
|Alimini - Italy                                        |2023-10-26T13:51:11+0200 |https://deims.org/765cad42-25da-4893-b4cc-eb1f393b4b47 |POINT (18.441 40.202)     |
|Appennino centrale: Gran Sasso d'Italia - Italy        |2023-07-24T14:20:51+0200 |https://deims.org/c0738b00-854c-418f-8d4f-69b03486e9fd |POINT (13.55498 42.44625) |
|Appennino centrale: Velino-Duchessa - Italy            |2023-07-24T14:20:48+0200 |https://deims.org/12c79ecb-7890-4b75-9655-0883dacd8a29 |POINT (13.3682 42.15693)  |

```r
listItaSitesMap <- leaflet(listItaSites) %>%
  addProviderTiles(provider = "CartoDB.PositronNoLabels",
                            group = "Basemap",
                            layerId = 123) %>%
  addTiles("http://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png") %>%
  addCircleMarkers(
    data = listItaSites,
    radius = 3,
    weight = 2,
    opacity = 0.5,
    fill = TRUE,
    fillOpacity = 0.2
  )
listItaSitesMap
```

```
## Error in path.expand(path): invalid 'path' argument
```

### Get other information sites in the network:

Four additional functions were implemented to obtain site information in the network. Each function gets specific information:

* Environmental characteristics by [`get_network_envcharacts`](https://docs.ropensci.org/ReLTER/reference/get_network_envcharacts.html)
* Observed properties by [`get_network_observedProperties`](https://docs.ropensci.org/ReLTER/reference/get_network_observedProperties.html)
* Related resources  by [`get_network_related_resources`](https://docs.ropensci.org/ReLTER/reference/get_network_related_resources.html)

The following example perform the request to get all related resources (e.g. activities, datasets, etc.) of the network. The output is a table containing the title, id and time stamp of the last changes of the related resources shared by the network's sites.


```r
IT_DEIMS.ID <- "https://deims.org/network/7fef6b73-e5cb-4cd2-b438-ed32eb1504b3"
listRelatedResources <- get_network_related_resources(
  networkDEIMSID = IT_DEIMS.ID
)

# Table of the network's related resources
knitr::kable(
  head(listRelatedResources, 10),
  caption = "The list of sites for LTER-Italy network"
)
```



Table: The list of sites for LTER-Italy network

|relatedResourcesTitle                                                            |uri                                                            |relatedResourcesChanged |
|:--------------------------------------------------------------------------------|:--------------------------------------------------------------|:-----------------------|
|NA                                                                               |NA                                                             |NA                      |
|LTER_EU_IT_077 Soil Temperature                                                  |https://deims.org/dataset/a84c3800-0384-11e5-870c-005056ab003f |2020-01-07 14:49:00     |
|Deposition of N-NH4 and N-NO3 Renon Bol1 1985-207                                |https://deims.org/dataset/6499a7cc-df94-45ac-92ed-62f43360411d |2020-02-27 09:38:00     |
|LTER Collelongo-Selva Piana, Italy, Vegetation data 1999-2016                    |https://deims.org/dataset/28fe3227-fb9f-4e73-9a2a-30c07e90104d |2019-12-20 13:21:00     |
|LTER Collelongo-Selva Piana, Italy, Precipitation and Throughfall data 1998-2017 |https://deims.org/dataset/d1497375-56f5-4140-a399-adfb32f925af |2020-09-02 13:43:00     |
|LTER Val Masino, Italy, Vegetation data 1999-2012                                |https://deims.org/dataset/67727a8a-fe1f-44eb-88b5-bf98bc443104 |2019-12-20 13:21:00     |
|LTER Val Masino LOM1, Italy, Precipitation and throughfall data 1997-2015        |https://deims.org/dataset/94b8f6fb-2cba-4b45-90e2-afd45b3e655e |2019-12-20 13:21:00     |
|LTER_EU_IT_021: Vegetation monitoring by 10x10 m permanent plots                 |https://deims.org/dataset/1f49ee00-198f-11e5-a766-005056ab003f |2022-11-19 11:10:00     |
|LTER_EU_IT_025: Vegetation monitoring by 10x10 permanent plots                   |https://deims.org/dataset/0c540fe8-1984-11e5-a766-005056ab003f |2019-11-29 11:31:00     |
|LTER_EU_IT_025: Soil and air temperature measurement                             |https://deims.org/dataset/9edc9b28-1984-11e5-a766-005056ab003f |2019-11-29 11:31:00     |


## By get_site_info function:

Start with the list of the LTER-Italy network sites ([see first example above](#firstExample)), or by using any DEIMS ID list, through the [`get_site_info`](https://docs.ropensci.org/ReLTER/reference/get_site_info.html) function (already described [here](./site_information.html)).

The example below shows how to select, from the list of LTER-Italy sites,
only those with a lake environment and map those sites.


```r
sites <- as_tibble(listItaSites) %>%
  filter(grepl("Lago", title)) %>%
  filter(!row_number() %in% c(1, 21, 22))

allSitesBounds <- lapply(sites$uri, function(s) {
  get_site_info(s, category = "Boundaries")
})
allSitesBounds <- do.call(rbind, allSitesBounds) # Creates an `sf` object

# Map
leaflet(data = allSitesBounds) %>%
  addPolygons() %>% 
  addProviderTiles(provider = "CartoDB.PositronNoLabels",
                            group = "Basemap",
                            layerId = 123) %>%
  addTiles(
    "http://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png")
```

```
## Error in path.expand(path): invalid 'path' argument
```

Using the same LTER-Italy sites list, 
the next example provide a contact list of all lake site managers.


```r
# Using sites from previous example
allSitesContacts <- lapply(sites$uri, function(s) {
  get_site_info(s, category = "Contacts")
})
allSitesContacts <- do.call(rbind, allSitesContacts)

contacts <- tibble::tibble(
  siteName = NA,
  managerName = NA,
  managerEmail = NA,
  managerORCID = NA
)

for (i in seq_along(allSitesContacts)) {
  contacts <- contacts %>% 
    tibble::add_row(
      siteName = allSitesContacts$title[[i]],
      managerName = allSitesContacts$siteManager[[1]]$name,
      managerEmail = allSitesContacts$siteManager[[1]]$email,
      managerORCID = allSitesContacts$siteManager[[1]]$orcid
    )
}
# Contacts table
knitr::kable(
  head(contacts, 10),
  caption = "List of the contacts"
)
```



Table: List of the contacts

|siteName                    |managerName |managerEmail |managerORCID |
|:---------------------------|:-----------|:------------|:------------|
|NA                          |NA          |NA           |NA           |
|Lago Bidighinzu - Italy     |NA          |NA           |NA           |
|Lago Braies - Italy         |NA          |NA           |NA           |
|Lago Cedrino - Italy        |NA          |NA           |NA           |
|Lago Cuga - Italy           |NA          |NA           |NA           |
|Lago di Candia - Italy      |NA          |NA           |NA           |
|Lago di Como - Italy        |NA          |NA           |NA           |
|Lago di Garda - Italy       |NA          |NA           |NA           |
|Lago di Orta - Italy        |NA          |NA           |NA           |
|LTSER Lago di Tovel - Italy |NA          |NA           |NA           |
