I want to create a gridded shapefile from point data I have stored in a csv file.
library(sf)
#First I read in the csv data:
data <- read.csv("latlong data.csv")
with columns 'lat'
,'lon'
and 'data'
.
#create a spatial data frame with my chosen projection:
points <- st_as_sf(data, coords = c("long", "lat"), crs = 4326)
#Then I create the grid for the data:
grid_resolution <- 0.1
grid_extent <- st_bbox(points)
#Create the grid
grid <- st_make_grid(grid_extent, cellsize = grid_resolution)
At this point, I need to ‘fill’ the grid with my data but I’m not sure how to do that?
It is worth noting that I have randomly picked the grid_resolution here, so if anyone has advice as to how to do this in an ‘intelligent’ fashion, I would appreciate it. From what I have read here on stack, it seems that the units are the same as the units used the projection chosen? So these would be degrees?