Skip to contents

A generic function to extract an area of interest for user-provided GPS coordinates.

Usage

extract_area(xy, spatial, area, locations = NULL, lonlat = NULL)

Arguments

xy

A list or data.frame object with names containing pairings of longitude and latitude values expressed as decimal degree values in that order. A data.frame may also be an sf points object. See Details for more.

spatial

a user-supplied sf::sf() or terra::SpatVector() object that contains information from which to derive location information, area.

area

the field in spatial that should be returned.

locations

The column in which the location names are located as an Integer value. Defaults to 1.

lonlat

A vector of integer values indicating the column index in which the longitude and latitude values are contained. Defaults to 2:3.

Value

A data.table::data.table() with the provided GPS coordinates and the respective area value from spatial.

xy

xy as a List Object

If xy is a list object, each individual vector's items should be named “x” (longitude) and “y” (latitude), respectively. The list item names should be descriptive of the individual vectors and will be included in a “location” column of the output.

xy as a Data Frame Object

If xy is a data.frame, it should be a three column object with the first column being the location name, the second longitude and the third, latitude both as decimal degrees in numeric format.

xy as an sf Object

If xy is an sf object, it should only be point geometry. If the data are projected, they will be reprojected to "EPSG:4326", Geographic Coordinate System WGS 84 before the extraction.

Examples

# load the `aez` data included in the package for use in example only.
# the `extract_ae_zone()` performs this exact task, this is strictly for
# demonstration purposes only

library(sf)
#> Linking to GEOS 3.13.0, GDAL 3.8.5, PROJ 9.5.1; sf_use_s2() is TRUE

aez <- st_read(system.file(
  "extdata",
  "aez.gpkg",
  package = "fifo",
  mustWork = TRUE
))
#> Reading layer `aez' from data source 
#>   `/Users/283204f/Library/R/arm64/4.5/library/fifo/extdata/aez.gpkg' 
#>   using driver `GPKG'
#> Simple feature collection with 18 features and 1 field
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 113.9652 ymin: -42.28128 xmax: 152.2734 ymax: -13.74142
#> Geodetic CRS:  WGS 84

locs <- list(
  "Merredin" = c(x = 118.28, y = -31.48),
  "Corrigin" = c(x = 117.87, y = -32.33),
  "Tamworth" = c(x = 150.84, y = -31.07)
)

extract_area(xy = locs, spatial = aez, area = "AEZ")
#>    location      x      y           AEZ
#>      <char>  <num>  <num>        <char>
#> 1: Corrigin 117.87 -32.33    WA Central
#> 2: Merredin 118.28 -31.48    WA Eastern
#> 3: Tamworth 150.84 -31.07 NSW NE/Qld SE