I'm running the code below and I get several "warnings". I used the sf_use_s2(FALSE) function to work with plane coordinates following the old way of the 'sf' package but even so I keep getting some warnings that I didn't get before.
##locations####
#import dataframes and joining
loc <-
list.files(path = "./dados",
pattern = "*.csv",
full.names = T) %>%
purrr::map_df(~readr::read_csv(.))
############################ HEXAGON GRID ########################################
sf_use_s2(FALSE) #assume plane coordinates
#convert locations to obj sf
loc.sf <- loc %>%
sf::st_as_sf(coords = c("x", "y"), crs = 4326)
#hexagon grid
grid = sf::st_make_grid(sf::st_bbox(loc.sf),
cellsize = .1, square = FALSE) %>%
sf::st_as_sf()
#import brazil shp
brasil <- sf::st_read(here::here("shps", "BR_UF_2020.shp")) %>%
sf::st_transform(4326) %>% sf::st_union() %>% sf::st_as_sf()
#simplify geometry
brasil1<- sf::st_simplify(brasil,
preserveTopology = FALSE,
dTolerance = 0.05) %>% sf::st_as_sf()
#import zee shp
zee <- sf::st_read(here::here("shps", "zeee.shp")) %>%
sf::st_union() %>% sf::st_as_sf()
#simplify geometry
zee1<- sf::st_simplify(zee,
preserveTopology = FALSE,
dTolerance = 0.05) %>% sf::st_as_sf()
#crop grid by linecoast
grid1 <- sf::st_difference(grid, brasil1) %>% sf::st_as_sf()
#crop grid by zee limit
grid2 <- sf::st_intersection(grid1, zee1) %>% sf::st_as_sf()
#filter locations by zee limit
loc <- sf::st_intersection(zee1, loc.sf)
WARNINGS:
In st_simplify.sfc(st_geometry(x), preserveTopology, dTolerance) :
st_simplify does not correctly simplify longitude/latitude data,
dTolerance needs to be in decimal degrees
-
although coordinates are longitude/latitude, st_intersection assumes that they are planar
Warning message:
attribute variables are assumed to be spatially constant throughout all geometries
sfpre-s2. Still the package warns you that for some operations withsfis better to project the shapes.