/
ff_polygonize: creating actionable data from predictions

ff_polygonize: creating actionable data from predictions

ff_polygonize is used to create focused, discrete polygons from the prediction raster that comes out of ff_predict or ff_run. It creates vector data that can be written as a Shapefile, GeoJSON or other spatial data format.

Exercise

# Load required libraries library(ForestForesight) # Let's assume we have downloaded predictions for Suriname into our forestforesight_data folder prediction_file <- "forestforesight_data/predictions/SUR/SUR_2024-01-01_predictions.tif" # Basic usage with automatic thresholding for "high" risk areas high_risk_areas <- ff_polygonize( input_raster = prediction_file, threshold = "high", # Automatically determine threshold for high-risk areas verbose = TRUE # Show the chosen threshold value ) # Save the polygons to a shapefile ff_polygonize( input_raster = prediction_file, output_file = "high_risk_areas.shp", threshold = "high", minimum_pixel_count = 10, # Slightly larger minimum area smoothness = 3 # Increased smoothing ) # Create a series of risk levels to compare risk_levels <- c("medium", "high", "very high") risk_polygons <- lapply(risk_levels, function(level) { ff_polygonize( input_raster = prediction_file, threshold = level, verbose = TRUE ) }) names(risk_polygons) <- risk_levels

Key points about ff_polygonize:

  1. Automatic Thresholding:

    • "medium" - Uses a balanced threshold suitable for general risk areas

    • "high" - More selective, focusing on higher probability areas

    • "very high" - Most selective, only highest probability areas

  2. Important Parameters:

    • minimum_pixel_count: Controls minimum size of risk areas (default=5)

    • window_size: Controls initial smoothing (default=7)

    • smoothness: Controls polygon smoothing (default=2)

  3. Output Attributes:

    • risk: Average risk value within the polygon

    • size: Area in hectares

    • riskfactor: risk × size

    • threshold: The threshold value used

    • date: Generation date

  4. Tips:

    • Start with threshold = "high" for a balanced result

    • Increase minimum_pixel_count to remove small polygons

    • Adjust smoothness higher for smoother boundaries

    • Use verbose = TRUE to see the automatically chosen threshold

Related content

ff_prep: data preparation
ff_prep: data preparation
More like this
ff_analyze: Analyzing the results
ff_analyze: Analyzing the results
More like this
ff_run: using the Forest Foresight package for training and predicting
ff_run: using the Forest Foresight package for training and predicting
More like this
ff_predict: Predicting deforestation
ff_predict: Predicting deforestation
More like this
Web Interface
Web Interface
More like this
ff_train: training a model
ff_train: training a model
More like this