Spatial

We should think about how these data frames play with the sf R package. We provide a selection of buoy metadata from the buoydata R package where each buoy has a spatial location.

tldr sf plays well with each of the data frames.

buoys = readr::read_csv("data/buoys.csv")
Rows: 1329 Columns: 17
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (11): ID, STATION_LOC, TTYPE, TIMEZONE, OWNER, OWNERNAME, COUNTRY, HULL...
dbl   (5): Y1, YN, nYEARS, LAT, LON
dttm  (1): lastMeasurement

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Or you can read from the github repos…

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.

1 data.frame

df = sf::st_as_sf(buoys, coords = c("LON", "LAT"), crs = 4326) 
df
Simple feature collection with 1329 features and 15 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: -177.75 ymin: -55 xmax: 179.001 ymax: 71.758
Geodetic CRS:  WGS 84
First 10 features:
      ID   Y1   YN nYEARS      lastMeasurement                     STATION_LOC
1  0Y2W3 2012 2015      4 2015-08-18T11:40:00Z     Sturgeon Bay CG Station, WI
2  18CI3 2014 2015      2 2015-09-21T13:25:00Z    Michigan City CG Station, IN
3  20CM4 2014 2015      2 2015-09-20T16:55:00Z       St. Joseph CG Station, MI
4  23020 2008 2010      3 2010-12-18T11:50:00Z                         Red Sea
5  31201 2005 2005      1 2005-08-19T15:00:00Z           Floripa, Brazil (109)
6  32012 2007 2018     12 2018-04-09T11:50:00Z Woods Hole Stratus Wave Station
7  32301 1984 1986      3 1986-07-12T16:00:00Z                                
8  32302 1986 1995     10 1995-04-03T12:00:00Z                                
9  32487 2008 2010      3 2010-01-08T20:25:00Z          Buenaventura, Colombia
10 32488 2008 2009      2 2009-10-16T02:10:00Z          Bahia Solano, Colombia
                   TTYPE TIMEZONE OWNER
1        Weather Station        C    CG
2        Weather Station        E    CG
3        Weather Station        E    CG
4                   Buoy        ?    KA
5         Waverider Buoy        ?     R
6  2.4-meter discus buoy        C    WH
7    3-meter discus buoy        C     N
8    3-meter discus buoy        C     N
9          Offshore Buoy        E    DC
10         Offshore Buoy        E    DC
                                               OWNERNAME COUNTRY   HULL
1                     U.S.C.G. Marine Reporting Stations      US       
2                     U.S.C.G. Marine Reporting Stations      US       
3                     U.S.C.G. Marine Reporting Stations      US       
4  King Abdullah University for Science and Tech (KAUST)      SA 2.8DX1
5                                                SCRIPPS      US       
6                   Woods Hole Oceanographic Institution      US       
7                                                   NDBC      US       
8                                                   NDBC      US       
9                                  DIMAR Colombia - CCCP      CO       
10                                 DIMAR Colombia - CCCP      CO       
          PAYLOAD FORECAST
1                         
2                         
3                         
4  WAMDAS payload         
5                         
6  WAMDAS payload         
7    DACT payload         
8    DACT payload         
9                         
10                        
                                                                                                                                 NOTE
1                                                                                                                                    
2                                                                                                                                    
3                                                                                                                                    
4                                                                                                                                    
5                                                                                                                                    
6  MET data from this station is available at <a title=32st0 href=https://www.ndbc.noaa.gov/station_page.php?station=32st0>32ST0</a>.
7                                                                                                                                    
8                                                                                                                                    
9                                                                                                                                    
10                                                                                                                                   
                  geometry
1   POINT (-87.313 44.794)
2     POINT (-86.91 41.73)
3     POINT (-86.49 42.09)
4      POINT (38.5 22.162)
5  POINT (-48.134 -27.705)
6  POINT (-85.384 -19.616)
7      POINT (-105.2 -9.9)
8        POINT (-85.1 -18)
9    POINT (-77.737 3.517)
10   POINT (-77.511 6.258)

2 tibble

tbl = dplyr::as_tibble(buoys)
tbl = sf::st_as_sf(tbl, coords = c("LON", "LAT"), crs = 4326) 
tbl
Simple feature collection with 1329 features and 15 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: -177.75 ymin: -55 xmax: 179.001 ymax: 71.758
Geodetic CRS:  WGS 84
# A tibble: 1,329 × 16
   ID       Y1    YN nYEARS lastMeasurement     STATION_LOC TTYPE TIMEZONE OWNER
 * <chr> <int> <int>  <int> <chr>               <chr>       <chr> <chr>    <chr>
 1 0Y2W3  2012  2015      4 2015-08-18T11:40:0… "Sturgeon … Weat… C        CG   
 2 18CI3  2014  2015      2 2015-09-21T13:25:0… "Michigan … Weat… E        CG   
 3 20CM4  2014  2015      2 2015-09-20T16:55:0… "St. Josep… Weat… E        CG   
 4 23020  2008  2010      3 2010-12-18T11:50:0… "Red Sea"   Buoy  ?        KA   
 5 31201  2005  2005      1 2005-08-19T15:00:0… "Floripa, … Wave… ?        R    
 6 32012  2007  2018     12 2018-04-09T11:50:0… "Woods Hol… 2.4-… C        WH   
 7 32301  1984  1986      3 1986-07-12T16:00:0… ""          3-me… C        N    
 8 32302  1986  1995     10 1995-04-03T12:00:0… ""          3-me… C        N    
 9 32487  2008  2010      3 2010-01-08T20:25:0… "Buenavent… Offs… E        DC   
10 32488  2008  2009      2 2009-10-16T02:10:0… "Bahia Sol… Offs… E        DC   
# ℹ 1,319 more rows
# ℹ 7 more variables: OWNERNAME <chr>, COUNTRY <chr>, HULL <chr>,
#   PAYLOAD <chr>, FORECAST <chr>, NOTE <chr>, geometry <POINT [°]>

3 tidytable

tt = tidytable::as_tidytable(buoys)
tt = sf::st_as_sf(tt, coords = c("LON", "LAT"), crs = 4326) 
tt
Simple feature collection with 1329 features and 15 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: -177.75 ymin: -55 xmax: 179.001 ymax: 71.758
Geodetic CRS:  WGS 84
# A tidytable: 1,329 × 16
   ID       Y1    YN nYEARS lastMeasurement     STATION_LOC TTYPE TIMEZONE OWNER
 * <chr> <int> <int>  <int> <chr>               <chr>       <chr> <chr>    <chr>
 1 0Y2W3  2012  2015      4 2015-08-18T11:40:0… "Sturgeon … Weat… C        CG   
 2 18CI3  2014  2015      2 2015-09-21T13:25:0… "Michigan … Weat… E        CG   
 3 20CM4  2014  2015      2 2015-09-20T16:55:0… "St. Josep… Weat… E        CG   
 4 23020  2008  2010      3 2010-12-18T11:50:0… "Red Sea"   Buoy  ?        KA   
 5 31201  2005  2005      1 2005-08-19T15:00:0… "Floripa, … Wave… ?        R    
 6 32012  2007  2018     12 2018-04-09T11:50:0… "Woods Hol… 2.4-… C        WH   
 7 32301  1984  1986      3 1986-07-12T16:00:0… ""          3-me… C        N    
 8 32302  1986  1995     10 1995-04-03T12:00:0… ""          3-me… C        N    
 9 32487  2008  2010      3 2010-01-08T20:25:0… "Buenavent… Offs… E        DC   
10 32488  2008  2009      2 2009-10-16T02:10:0… "Bahia Sol… Offs… E        DC   
# ℹ 1,319 more rows
# ℹ 7 more variables: OWNERNAME <chr>, COUNTRY <chr>, HULL <chr>,
#   PAYLOAD <chr>, FORECAST <chr>, NOTE <chr>, geometry <POINT [°]>

4 data.table

dt = data.table::as.data.table(buoys)
dt = sf::st_as_sf(dt, coords = c("LON", "LAT"), crs = 4326) 
dt
Simple feature collection with 1329 features and 15 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: -177.75 ymin: -55 xmax: 179.001 ymax: 71.758
Geodetic CRS:  WGS 84
First 10 features:
      ID   Y1   YN nYEARS      lastMeasurement                     STATION_LOC
1  0Y2W3 2012 2015      4 2015-08-18T11:40:00Z     Sturgeon Bay CG Station, WI
2  18CI3 2014 2015      2 2015-09-21T13:25:00Z    Michigan City CG Station, IN
3  20CM4 2014 2015      2 2015-09-20T16:55:00Z       St. Joseph CG Station, MI
4  23020 2008 2010      3 2010-12-18T11:50:00Z                         Red Sea
5  31201 2005 2005      1 2005-08-19T15:00:00Z           Floripa, Brazil (109)
6  32012 2007 2018     12 2018-04-09T11:50:00Z Woods Hole Stratus Wave Station
7  32301 1984 1986      3 1986-07-12T16:00:00Z                                
8  32302 1986 1995     10 1995-04-03T12:00:00Z                                
9  32487 2008 2010      3 2010-01-08T20:25:00Z          Buenaventura, Colombia
10 32488 2008 2009      2 2009-10-16T02:10:00Z          Bahia Solano, Colombia
                   TTYPE TIMEZONE OWNER
1        Weather Station        C    CG
2        Weather Station        E    CG
3        Weather Station        E    CG
4                   Buoy        ?    KA
5         Waverider Buoy        ?     R
6  2.4-meter discus buoy        C    WH
7    3-meter discus buoy        C     N
8    3-meter discus buoy        C     N
9          Offshore Buoy        E    DC
10         Offshore Buoy        E    DC
                                               OWNERNAME COUNTRY   HULL
1                     U.S.C.G. Marine Reporting Stations      US       
2                     U.S.C.G. Marine Reporting Stations      US       
3                     U.S.C.G. Marine Reporting Stations      US       
4  King Abdullah University for Science and Tech (KAUST)      SA 2.8DX1
5                                                SCRIPPS      US       
6                   Woods Hole Oceanographic Institution      US       
7                                                   NDBC      US       
8                                                   NDBC      US       
9                                  DIMAR Colombia - CCCP      CO       
10                                 DIMAR Colombia - CCCP      CO       
          PAYLOAD FORECAST
1                         
2                         
3                         
4  WAMDAS payload         
5                         
6  WAMDAS payload         
7    DACT payload         
8    DACT payload         
9                         
10                        
                                                                                                                                 NOTE
1                                                                                                                                    
2                                                                                                                                    
3                                                                                                                                    
4                                                                                                                                    
5                                                                                                                                    
6  MET data from this station is available at <a title=32st0 href=https://www.ndbc.noaa.gov/station_page.php?station=32st0>32ST0</a>.
7                                                                                                                                    
8                                                                                                                                    
9                                                                                                                                    
10                                                                                                                                   
                  geometry
1   POINT (-87.313 44.794)
2     POINT (-86.91 41.73)
3     POINT (-86.49 42.09)
4      POINT (38.5 22.162)
5  POINT (-48.134 -27.705)
6  POINT (-85.384 -19.616)
7      POINT (-105.2 -9.9)
8        POINT (-85.1 -18)
9    POINT (-77.737 3.517)
10   POINT (-77.511 6.258)
Back to top