I am attempting to add a column that provides the area of my HUC_12 watershed polygons to a watershed data set, but the only code online that demonstrates how to do this is using the raster library, which is incompatible with the sf package and tidyverse. If you have an idea of how to create this is sf, please let me know.

Here is the code I was using for reference:

shape = shapefile("~/Downloads/all_borders.shp")
shape$Area_sqm = area(shape)

Thank you for your assistance.

  • You could just use the sf::st_area function – Jeffrey Evans Jun 30 '20 at 22:46
  • Maybe you could try library(sf); st_area(st_as_sf(shape)). – Edzer Pebesma Jul 1 '20 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.