get_smarter_geojson: Get SMARTER GeoJSON Samples

View source: R/geojson.R

get_smarter_geojsonR Documentation

Get SMARTER GeoJSON Samples

Description

Fetch SMARTER REST API samples with GPS coordinates and return them into as simple features. Cached token is used or a new token is generated if not provided when calling this function (see get_smarter_token for more information)

Usage

get_smarter_geojson(species, query = list(), token = NULL)

Arguments

species

a smarter species ("Goat", "Sheep")

query

a list of query arguments

token

a string with a valid token

Value

a sf data object

Examples

## Not run: 
# required to execute pipe operations and draw examples
library(dplyr)
library(leaflet)

# get goat samples with GPS coordinates as sf object
goat_data <- get_smarter_geojson(
  species = "Goat",
  query = list(
    type = "background",
    country = "Italy"
  )
)

# leaflet doesn't handle MULTIPOINT data (https://github.com/rstudio/leaflet/issues/352)
# Cast them into point considering only the first objects
# (https://r-spatial.github.io/sf/reference/st_cast.html)
goat_data <- goat_data %>% sf::st_cast("POINT", do_split=FALSE)

# draw samples in a leaflet map using markerCluser
leaflet(data = goat_data) %>%
  leaflet::addTiles() %>%
  leaflet::addMarkers(
    clusterOptions = leaflet::markerClusterOptions(), label = ~smarter_id
  )

## End(Not run)

cnr-ibba/r-smarter-api documentation built on Nov. 1, 2022, 4:24 a.m.