-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspatial.qmd
More file actions
61 lines (42 loc) · 1.2 KB
/
spatial.qmd
File metadata and controls
61 lines (42 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: "Spatial"
format: html
editor: source
---
```{r, include = FALSE}
source("setup.R")
```
We should think about how these data frames play with the [sf R package](https://r-spatial.github.io/sf/). We provide a selection of buoy metadata from the [buoydata R package](https://github.com/NOAA-EDAB/buoydata) where each buoy has a spatial location.
**tldr** `sf` plays well with each of the data frames.
```{r}
buoys = readr::read_csv("data/buoys.csv")
```
Or you can read from the github repos...
```{r}
buoys = read.csv("https://raw.githubusercontent.com/BigelowLab/dataframes/refs/heads/main/data/buoys.csv",
stringsAsFactors = FALSE)
```
As a first pass, can we coerce this data frame into each of the spatial objects.
## data.frame
```{r}
df = sf::st_as_sf(buoys, coords = c("LON", "LAT"), crs = 4326)
df
```
## tibble
```{r}
tbl = dplyr::as_tibble(buoys)
tbl = sf::st_as_sf(tbl, coords = c("LON", "LAT"), crs = 4326)
tbl
```
## tidytable
```{r}
tt = tidytable::as_tidytable(buoys)
tt = sf::st_as_sf(tt, coords = c("LON", "LAT"), crs = 4326)
tt
```
## data.table
```{r}
dt = data.table::as.data.table(buoys)
dt = sf::st_as_sf(dt, coords = c("LON", "LAT"), crs = 4326)
dt
```