library(sf)
## Linking to GEOS 3.8.1, GDAL 3.1.3, PROJ 7.1.1
# Read
dat = st_read("/home/michael/Dropbox/Courses/R_2021/_book/data/nafot.shp")
## Reading layer `nafot' from data source `/home/michael/Dropbox/Courses/R_2021/_book/data/nafot.shp' using driver `ESRI Shapefile'
## Simple feature collection with 15 features and 4 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: 620662.1 ymin: 3263494 xmax: 770624.4 ymax: 3691834
## projected CRS: WGS 84 / UTM zone 36N
# Plot - before
plot(st_geometry(dat))
text(st_coordinates(st_centroid(dat)), dat$name_eng, col = "red")
## Warning in st_centroid.sf(dat): st_centroid assumes attributes are constant over
## geometries of x

# Dissolve
sel = c("Kinneret", "Zefat", "Golan")
dat$group = dat$name_eng
dat$group[dat$group %in% sel] = "North"
dat = aggregate(dat["Area_dunam"], st_drop_geometry(dat["group"]), sum)
# Plot - after
plot(st_geometry(dat))
text(st_coordinates(st_centroid(dat)), dat$group, col = "red")
## Warning in st_centroid.sf(dat): st_centroid assumes attributes are constant over
## geometries of x
