The current issue I’m trying to solve is that of the “wetland category” in our layer. Out of my brood rearing birds, I have:
## [1] 140
Out of those 140 birds, you can see the following have this wetland category in them.
## [1] 81
| Landcover | id | percentage |
|---|---|---|
| wetland | 213720670_2022 | 1.6646043 |
| wetland | 213720674_2022 | 2.1272894 |
| wetland | 224780346_2022 | 11.0273304 |
| wetland | 213738411_2022 | 2.0209227 |
| wetland | 222780054_2022 | 2.0856645 |
| wetland | 224738015_2022 | 0.4794291 |
| wetland | 222779088_2022 | 1.2522138 |
| wetland | 225744046_2022 | 20.8747613 |
| wetland | 213738409_2022 | 0.1314237 |
| wetland | 225744076_2022 | 12.9549411 |
| wetland | 224739396_2022 | 1.9801681 |
| wetland | 225726229_2022 | 0.1754763 |
| wetland | 225705231_2022 | 0.4283307 |
| wetland | 216750042_2023 | 13.5714942 |
| wetland | 224738039_2023 | 0.2833411 |
| wetland | 224726249_2023 | 4.4371122 |
| wetland | 222758143_2023 | 57.4687535 |
| wetland | 225763224_2023 | 0.0586349 |
| wetland | 225744211_2023 | 8.4643166 |
| wetland | 224780410_2023 | 0.4959748 |
| wetland | 225736074_2023 | 0.7907082 |
| wetland | 225723152_2023 | 65.6121081 |
| wetland | 225771642_2023 | 0.5538367 |
| wetland | 225745134_2023 | 4.5996199 |
| wetland | 222758165_2023 | 1.3571580 |
| wetland | 213720127_2023 | 3.4083649 |
| wetland | 225791116_2023 | 5.4275627 |
| wetland | 224789214_2023 | 2.8907931 |
| wetland | 224780419_2023 | 0.0032172 |
| wetland | 225744678_2023 | 9.7939710 |
| wetland | 224789210_2023 | 1.0463972 |
| wetland | 224713205_2023 | 0.4733611 |
| wetland | 225763222_2023 | 26.7108745 |
| wetland | 225722520_2023 | 3.1136260 |
| wetland | 228718910_2023 | 0.8481434 |
| wetland | 222779129_2023 | 0.8052768 |
| wetland | 224788915_2023 | 2.5219702 |
| wetland | 225760227_2024 | 0.3642565 |
| wetland | 222724405_2024 | 2.0528304 |
| wetland | 213720139_2024 | 1.3967586 |
| wetland | 228775552_2024 | 0.5515172 |
| wetland | 228775608_2024 | 2.4343851 |
| wetland | 228775624_2024 | 5.8568331 |
| wetland | 224788915_2024 | 3.8308635 |
| wetland | 225743661_2024 | 0.2862123 |
| wetland | 228737351_2024 | 3.2663963 |
| wetland | 224779164_2024 | 0.7223657 |
| wetland | 225760459_2024 | 3.4158630 |
| wetland | 224780427_2024 | 1.0851117 |
| wetland | 222779129_2024 | 0.9164649 |
| wetland | 225739761_2024 | 0.7060638 |
| wetland | 228716718_2024 | 8.4831716 |
| wetland | 224728522_2024 | 0.6800668 |
| wetland | 228747555_2024 | 1.7367816 |
| wetland | 228737520_2024 | 0.8948796 |
| wetland | 228775690_2024 | 3.0123336 |
| wetland | 225744418_2024 | 1.3050207 |
| wetland | 225705711_2024 | 0.0966415 |
| wetland | 225763222_2024 | 49.3962874 |
| wetland | 228716711_2024 | 9.6244425 |
| wetland | 224728526_2024 | 2.6916223 |
| wetland | 228701162_2024 | 0.5589017 |
| wetland | 224728525_2024 | 8.3061379 |
| wetland | 225769676_2024 | 24.3566761 |
| wetland | 225722528_2024 | 6.3803370 |
| wetland | 222785799_2024 | 4.8745776 |
| wetland | 228747927_2024 | 8.9010325 |
| wetland | 228701835_2024 | 0.0380399 |
| wetland | 228716656_2024 | 3.0156050 |
| wetland | 228701834_2024 | 0.0302036 |
| wetland | 216789298_2025 | 0.0203516 |
| wetland | 222762439_2025 | 2.1022082 |
| wetland | 225743861_2025 | 1.3293247 |
| wetland | 228746654_2025 | 0.8830046 |
| wetland | 228748219_2025 | 8.5983151 |
| wetland | 211705291_2025 | 1.3734467 |
| wetland | 225769131_2025 | 7.8143026 |
| wetland | 225785391_2025 | 1.5831683 |
| wetland | 224780427_2025 | 0.8150489 |
| wetland | 249745503_2025 | 8.1989840 |
| wetland | 224727830_2025 | 0.1755579 |
This isn’t good, as this wetland category could be peatland, marsh, or swamp. To fix this, I first decided to read in the layer that Jake recommended. This layer is quite detailed, with over 300 specific classes (although from the map you can’t tell it’s that many).
I’m going to show you the methdology I’m using with two birds…the first one being a bird that had a wetland category replaced by this layer. That bird is 222779088_2022.
Let’s look at her current map:
You can see that she has about 20% wetland category (dark blue). She also has some forest and swamp.
Here are her current proportions of habitat. She has over 20% in that wetland category.
## # A tibble: 5 Ă— 2
## Landcover percentage
## <chr> <dbl>
## 1 forest 4.06
## 2 grassland 0.107
## 3 shrubland 0.405
## 4 swamp 71.1
## 5 wetland 24.4
Now, we can overlay the new habitat layer with only those pixels that were assigned wetland…and see what the new layer would assign them.
Here’s part of the code you should see. As there’s over 300 classes in the new layer, I had to make a quick ruleset. I based this off of words. For my birds, these categories worked and I wasn’t left with any Other values.
# grepl("swamp", ClassName, ignore.case = TRUE) ~ "24", # swamp
# grepl("marsh", ClassName, ignore.case = TRUE) ~ "23", # marsh
# grepl("forest|woodland|tree|pine", ClassName, ignore.case = TRUE) ~ "2", # forest
# grepl("shrubland", ClassName, ignore.case = TRUE) ~ "7", # shrub
# grepl("grassland|prairie|meadow", ClassName, ignore.case = TRUE) ~ "9", # grassland
# grepl("fen|bog", ClassName, ignore.case = TRUE) ~ "22",# peatland
# grepl("agriculture", ClassName, ignore.case = TRUE) ~ "15", #cropland
# grepl("developed", ClassName, ignore.case = TRUE) ~ "17", # urban
# grepl("rock|bluff|beach|cliff", ClassName, ignore.case = TRUE) ~ "13", # barren
# grepl("water", ClassName, ignore.case = TRUE) ~ "18", # water
# TRUE ~ "Other" # Catches anything that doesn't match the above
# )) %>%
# mutate(row_id = row_number()) %>%
# select(-ID, -weight)
Here’s the bird’s old proportions, and the new ones, updated with the layer. We can see that forest and swamp increased. The new layer also added some peatland and marsh. The new layer didn’t completely agree that all those wetland pixels should truly be wetland.
## # A tibble: 7 Ă— 3
## Landcover updated_prop old_prop
## <chr> <dbl> <dbl>
## 1 forest 7.24 4.06
## 2 grassland 0.113 0.107
## 3 marsh 7.08 NA
## 4 peatland 3.67 NA
## 5 shrubland 0.529 0.405
## 6 swamp 81.4 71.1
## 7 wetland NA 24.4
What does her updated map look like? You can toggle back and forth the habitat_crop (the original raster), and habitat_final_map, the updated raster with no wetland values to better see what was replaced.
Now, unfortuately, the following layer does not extend past southern Ontario and Quebec. From the above example, we tend to see that the pixels become similar to the pixels around it.
For individuals that still had the wetland category left (about 18), I took the ones with less than 10% of that wetland category, and just make those pixels the value of the pixel closest to them.
Here’s an example with bird: 225722520_2023
## # A tibble: 4 Ă— 2
## Landcover percentage
## <chr> <dbl>
## 1 peatland 69.5
## 2 swamp 0.863
## 3 water 28.0
## 4 wetland 1.58
This bird has a bit of the wetland category left. We can graph her and see that she’s in Northern Ontario. Her wetland’s seem to be on the edges of bodies of water.
Since the percentage is quite small, I’m going to take those wetland pixels and replace them with the class of the pixel nearest in the greatest proportion.
So, her percentages used to look like this:
## # A tibble: 4 Ă— 2
## Landcover percentage
## <chr> <dbl>
## 1 peatland 69.5
## 2 swamp 0.863
## 3 water 28.0
## 4 wetland 1.58
And now they look like this. It looks like a few of the pixels became water, and a few became peatland.
## # A tibble: 3 Ă— 2
## Landcover percentage
## <chr> <dbl>
## 1 peatland 70.3
## 2 swamp 0.863
## 3 water 28.9
So, at this point, I’m left with about four birds that have really high percentages of wetland. I’ll graph them all so you can see.
So, as you can see, a lot of these wetlands are just surrounded by forest. I did some previous analysis looking at if swamps, peatland, or marshes are more likely to be surrounded by forest but there wasn’t a clear answer.
We need to figure out what to do with these birds. Do we manually guess?