2

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 
2
  • Hi Caroline, as far as I remember those warnings appeared also on sf pre-s2. Still the package warns you that for some operations with sf is better to project the shapes. Commented Apr 18, 2022 at 13:47
  • Thank you. Do you think this might be causing an error in the analyses or is it just a warning? Commented Apr 18, 2022 at 14:18

1 Answer 1

2

The error is letting you know that your coordinate reference system (CRS 4326, or WGS84) is unprojected, or in lat/lon format. You'll want to convert it to a CRS that is projected using st_transform. The best choice of CRS will depend on the geographic location & scale of your dataset. Sf will run and produce results on unprojected data, but particularly when it comes to distance calculations and intersections, your results won't be accurate.

See here for a longer discussion of this issue with the st_simplify function: https://www.r-bloggers.com/2021/03/simplifying-geospatial-features-in-r-with-sf-and-rmapshaper/

And see here for help picking an appropriate CRS: https://projectionwizard.org/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.