class: middle, inverse # Creating sf object .font100[ Bon Woo Koo & Subhro Guhathakurta 9/8/2022 ] --- ## sfg, sfc, and sf ### How simple features in R are organized: * **Simple feature geometry.** * `my_point <- st_point(c(-84.388, 33.749))`. * **my_point** is a point on an arbitrary plane. * It cannot be mapped on Earth. * **Simple feature geometry list-column.** * `my_sfc <- st_sfc(my_point, crs = 4326)`. * It adds **crs** information to sfg object. * With CRS defined, now R knows where that point is on Earth. * **CRS** must match the coordinates used to create sfg object. * The geometry column you see in sf objects = sfc --- * **Simple feature** * `my_sf <- st_sf(my_sfc)` * This is the combination of a **data frame** and **sfc** object. * e.g., dplyr verbs don't work for sfc, but they work for sf. <br> <img src="sf_structure.png" width="100%" /> --- To create (POINT) sf object from a pair of lng/lat coordinates, you need to do it in **sfg → sfc → sf**, in this order. .footnotesize[ 1. Create an .red[**sfg**] using coordinates. **my_sfg <- st_point(c(-84.388, 33.749))**. 2. Convert the .red[**sfg**] object into .blue[**sfc**] object with CRS info. **my_sfc <- my_sfg %>% st_sfc(crs = 4326)**. 3. Convert the .blue[**sfc**] object into .green[**sf**] object using **my_sf <- st_sf(my_sfc)**. ] <br> <img src="sf_structure.png" width="100%" />