Overview
Beyond tabular and visual summaries, OpenLand provides spatial analysis functions to map where and how frequently land use changes occur across the landscape.Available Functions
- acc_changes(): Map accumulated changes (how many times each pixel changed)
- summary_map(): Summarize pixel counts by category for a single raster
- summary_dir(): Check consistency across multiple rasters in a directory
Accumulated Changes
Theacc_changes() function calculates how many times each pixel changed during the analyzed period, revealing spatial patterns of change frequency.
How It Works
Basic Usage
Understanding the Output
Raster layer (element 1):- 89.5% of pixels never changed (value = 0)
- 8.9% changed once
- 1.5% changed twice (high turnover areas)
- 0.1% changed three times (very dynamic areas)
Input Formats
The function accepts multiple input types:Visualizing Accumulated Changes with tmap
OpenLand integrates with the tmap package for creating publication-quality maps.Complete Mapping Workflow
library(OpenLand)
library(tmap)
acc_result <- acc_changes(SaoLourencoBasin)
acc_raster <- acc_result[[1]]
acc_table <- acc_result[[2]]
# Set maximum raster size for plotting
tmap_options(max.raster = c(plot = 41711112, view = 41711112))
# Build the map
acc_map <- tm_shape(acc_raster) +
tm_raster(
style = "cat", # Categorical style
labels = c(
paste0(acc_table$PxValue[1], " Change",
" (", round(acc_table$Percent[1], 2), "%)"),
paste0(acc_table$PxValue[2], " Change",
" (", round(acc_table$Percent[2], 2), "%)"),
paste0(acc_table$PxValue[3], " Changes",
" (", round(acc_table$Percent[3], 2), "%)")
),
palette = c("#757575", "#FFD700", "#CD0000"), # Gray, Gold, Red
title = "Changes in the interval\n2002 - 2014"
) +
tm_legend(
position = c(0.01, 0.2),
legend.title.size = 1.2,
legend.title.fontface = "bold",
legend.text.size = 0.8
) +
tm_compass(
type = "arrow",
position = c("right", "top"),
size = 3
) +
tm_scale_bar(
breaks = c(seq(0, 40, 10)),
position = c(0.76, 0.001),
text.size = 0.6
) +
tm_graticules(
n.x = 6,
n.y = 6,
lines = FALSE,
labels.rot = c(0, 90)
) +
tm_layout(inner.margins = c(0.02, 0.02, 0.02, 0.02))
# Display the map
acc_map
Customizing the Map
Color palettes:Summary Functions for Raster Checking
summary_map() - Single Raster Summary
Get pixel counts by category for a single raster layer:- Verify category presence
- Check for unexpected pixel values
- Calculate category areas before running analysis
- Quality control after reclassification
summary_dir() - Multi-Raster Consistency Check
Check consistency of spatial parameters across all rasters:file_name: Raster layer namexmin,xmax,ymin,ymax: Extent boundariesres_x,res_y: Pixel resolutionnrow,ncol: Grid dimensionsmin_val,max_val: Category value rangecrs: Coordinate reference system
✓ All rows should have identical resolution
✓ All rows should have identical dimensions
✓ All rows should have identical CRS
✗ Category values (
min_val, max_val) can differ (land use changes over time)
Spatial Analysis Workflow Example
library(OpenLand)
library(tmap)
# Check raster consistency
summary_dir(raster::unstack(SaoLourencoBasin))
# Verify first layer
summary_map(SaoLourencoBasin[[1]])
acc_result <- acc_changes(SaoLourencoBasin)
acc_raster <- acc_result[[1]]
acc_table <- acc_result[[2]]
# View summary statistics
print(acc_table)
# Build map with tmap
acc_map <- tm_shape(acc_raster) +
tm_raster(
style = "cat",
labels = paste0(acc_table$PxValue, " change",
ifelse(acc_table$PxValue != 1, "s", ""),
" (", round(acc_table$Percent, 1), "%)"),
palette = c("#757575", "#FFD700", "#CD0000", "#8B0000"),
title = "Accumulated Changes"
) +
tm_legend(position = c(0.02, 0.25)) +
tm_compass(position = c("right", "top")) +
tm_scale_bar(position = c("left", "bottom")) +
tm_graticules()
acc_map
# Extract high-change areas (changed 2+ times)
high_change <- acc_raster >= 2
# Calculate percentage of high-change pixels
total_pixels <- sum(!is.na(raster::values(acc_raster)))
high_change_pixels <- sum(raster::values(high_change), na.rm = TRUE)
percent_high_change <- (high_change_pixels / total_pixels) * 100
cat("High-change areas:", round(percent_high_change, 2), "%\n")
# Save high-change mask
raster::writeRaster(high_change, "high_change_mask.tif")
Integration with Other Analysis
Combining Spatial and Intensity Analysis
Masking by Change Frequency
Tips for Spatial Analysis
Next Steps
- Learn about intensity analysis to quantify change patterns
- Explore visualization tools for creating transition diagrams
- Review raster input requirements for data preparation