I have two example datasets with lat/long coordinates called data1 and data2, shown below:
data1
longitude latitude
739988.7 7181125
731198.0 7192405
707692.8 7207291
704707.8 7227053
713522.9 7190833
722008.5 7187554
728945.9 7192522
729411.5 7202546
734045.5 7203942
718694.5 7221503
data2
longitude latitude
561852.0 7307774
496053.0 7128101
619513.7 7173470
657022.3 7178750
654221.8 7183023
653387.6 7183496
649752.3 7183097
642717.0 7182999
639332.8 7183266
633958.1 7205380
I have calculated the home range of both datasets and generated polygons from those home ranges using the following code:
library(ks)
library(dplyr)
#Home range 1
h1 <- Hpi(data1, pilot = "samse", binned = T)
kernPI1 <- kde(data1, H = h1)
cont = contourLevels(kernPI1, cont = 95)
line1 = contourLines(x = kernPI1$eval.points[[1]], y =
kernPI1$eval.points[[2]],
z = kernPI1$estimate,
level = cont)
x1<-line1[[1]][["x"]]
y1<-line1[[1]][["y"]]
dataline1<-data.frame(x1,y1)
polygon1 <- dataline1 %>%
st_as_sf(coords = c("x1", "y1"), crs = 5321) %>%
summarise(geometry = st_combine(geometry)) %>%
st_cast("POLYGON")
# home range 2
h2 <- Hpi(data2, pilot = "samse", binned = T)
kernPI2 <- kde(data2, H = h2)
cont = contourLevels(kernPI2, cont = 95)
line2 = contourLines(x = kernPI2$eval.points[[1]], y =
kernPI2$eval.points[[2]],
z = kernPI2$estimate,
level = cont)
x2<-line2[[1]][["x"]]
y2<-line2[[1]][["y"]]
dataline2<-data.frame(x2,y2)
polygon2 <- dataline2 %>%
st_as_sf(coords = c("x2", "y2"), crs = 5322) %>%
summarise(geometry = st_combine(geometry)) %>%
st_cast("POLYGON")
I would like to find the area of overlap between those two polygons, either as a number in m2 or as a percentage. How can I code this in R?