From prior test we are fairly confident that the following function works:
SkovnaturGenerator <- function(DF){
if (is.null(DF$Subclass)) {
DF$Subclass <- NA
}
DF$Subclass <- ifelse((
(!is.na(DF$Urort_Skov) | # It has to untouched forest
(!is.na(DF$Forest) & is.na(DF$Urort_Skov) & (!is.na(DF$National_Parks) | !is.na(DF$Fondsejede) | !is.na(DF$p3_klit)))) & # If it is forest but it is not urort skov it has to be P3, Fond or NP
(DF$p3_klit != "S.f8." | is.na(DF$p3_klit)) & # IT cant be a lake
(DF$markblokkort != "INT_AGG" | is.na(DF$markblokkort)) # it cant be intensive aggriculture
), "Skovnatur", DF$Subclass)
return(DF)
}
This takes any Data Frame and generates a Subclass column if it does not exist, and if a row complies with certain characteristics, in this case it will need to comply with 3 different conditions
The first check is that it either has to be Urort skov or be Forest land use in base-map. All of urort skov will be considered. However from base-map, only the pixels that are within Naturnationalparks, Paragraph 3 and Klit, or funds this is shown in the following part of the code:
(!is.na(DF$Urort_Skov) | # It has to untouched forest
(!is.na(DF$Forest) & is.na(DF$Urort_Skov) & (!is.na(DF$National_Parks) | !is.na(DF$Fondsejede) | !is.na(DF$p3_klit)))) & # Or if it is forest but it is not urort skov it has to be P3, Fond or NP