Problem
dft_rast_transition() with from_class set keeps all pixels that started in that class — including ones that stayed in the same class. For example, from_class = "Trees" returns Trees→Trees (stable), Trees→Rangeland, Trees→Water, etc. all in the same raster.
For change detection workflows the unchanged transitions are noise — users want to see what actually changed. Currently they have to filter downstream:
- In
dft_transition_vectors() output: transition != "Trees -> Trees"
- In QGIS: same filter on the attribute table
- In summary tables: drop rows where
from_class == to_class
In a real example (restoration_wedzin_kwa_2024), 12,960 ha of Trees→Trees patches dominate the output while only ~1,100 ha of actual change is what matters.
Proposed Solution
Add an exclude_unchanged parameter to dft_rast_transition() (and dft_transition_vectors() could inherit or expose its own):
dft_rast_transition(x, from, to, from_class = NULL, to_class = NULL,
exclude_unchanged = FALSE, ...)
When TRUE, pixels where from_class == to_class are masked to NA before computing the summary and patches. Default FALSE preserves current behavior.
Same pattern in dft_transition_vectors() if it doesn't naturally inherit.
Why default FALSE
Backward compatible. Users opt in to filtering. Some workflows do want to see stable areas alongside change (e.g., reporting "X ha of Trees remained Trees, Y ha converted").
Alternative
Default TRUE and add include_unchanged = FALSE for users who want stable areas. Cleaner default for the common case (change detection) but breaks existing code.
Relates to NewGraphEnvironment/restoration_wedzin_kwa_2024#142
Problem
dft_rast_transition()withfrom_classset keeps all pixels that started in that class — including ones that stayed in the same class. For example,from_class = "Trees"returns Trees→Trees (stable), Trees→Rangeland, Trees→Water, etc. all in the same raster.For change detection workflows the unchanged transitions are noise — users want to see what actually changed. Currently they have to filter downstream:
dft_transition_vectors()output:transition != "Trees -> Trees"from_class == to_classIn a real example (restoration_wedzin_kwa_2024), 12,960 ha of Trees→Trees patches dominate the output while only ~1,100 ha of actual change is what matters.
Proposed Solution
Add an
exclude_unchangedparameter todft_rast_transition()(anddft_transition_vectors()could inherit or expose its own):When
TRUE, pixels wherefrom_class == to_classare masked to NA before computing the summary and patches. DefaultFALSEpreserves current behavior.Same pattern in
dft_transition_vectors()if it doesn't naturally inherit.Why default FALSE
Backward compatible. Users opt in to filtering. Some workflows do want to see stable areas alongside change (e.g., reporting "X ha of Trees remained Trees, Y ha converted").
Alternative
Default
TRUEand addinclude_unchanged = FALSEfor users who want stable areas. Cleaner default for the common case (change detection) but breaks existing code.Relates to NewGraphEnvironment/restoration_wedzin_kwa_2024#142