if (FALSE) {
# Example 1: Basic Otsu thresholds (global)
process_otsu_rasters(
raster_path = "data/rbr_1985.tif",
output_dir = "output/1985",
otsu_thresholds = c(0, 50, 100),
python_exe = "C:/Python/python.exe",
gdal_polygonize_script = "C:/Python/Scripts/gdal_polygonize.py"
)
# Example 2: Global with percentile trimming
process_otsu_rasters(
raster_path = "data/rbr_1985.tif",
output_dir = "output/1985",
trim_percentiles = data.frame(min = 0.01, max = 0.99),
python_exe = "C:/Python/python.exe",
gdal_polygonize_script = "C:/Python/Scripts/gdal_polygonize.py",
output_format = "geojson"
)
# Example 3: Stratified by reclassified CORINE
process_otsu_rasters(
raster_path = "data/rbr_1985.tif",
output_dir = "output/1985",
corine_raster_path = "data/corine_1990_etrs89.tif",
reclassify_corine = TRUE,
reclass_matrix = matrix(c(
22, 1, # grasslands ? 1
26, 1,
32, 1,
27, 2, # shrublands ? 2
29, 2,
33, 3, # burnt areas ? 3
23, 4, # broadleaved forest ? 4
25, 5, # mixed forest ? 5
24, 6 # coniferous ? 6
), ncol = 2, byrow = TRUE),
corine_classes = c(1, 2, 4, 5, 6),
peninsula_shapefile = "data/peninsula_clip.shp",
output_corine_raster_dir = "output/corine",
output_corine_vector_dir = "output/corine",
otsu_thresholds = c(50),
min_otsu_threshold_value = 150,
python_exe = "C:/Python/python.exe",
gdal_polygonize_script = "C:/Python/Scripts/gdal_polygonize.py"
)
# Example 4: Stratified by WWF ecoregions (default field: "EnS_name")
process_otsu_rasters(
raster_path = "data/rbr_1985.tif",
output_dir = "output/1985",
ecoregion_shapefile_path = "data/ecoregions_olson.shp",
otsu_thresholds = c(50),
min_otsu_threshold_value = 150,
python_exe = "C:/Python/python.exe",
gdal_polygonize_script = "C:/Python/Scripts/gdal_polygonize.py"
)
# Example 5: Stratified by WWF ecoregions with custom field
process_otsu_rasters(
raster_path = "data/rbr_1985.tif",
output_dir = "output/1985",
ecoregion_shapefile_path = "data/ecoregions_olson.shp",
ecoregion_field = "EnZ_name",
ecoregion_classes = c("Iberian Conifer Forests", "Mediterranean Shrublands"),
otsu_thresholds = c(50),
min_otsu_threshold_value = 150,
python_exe = "C:/Python/python.exe",
gdal_polygonize_script = "C:/Python/Scripts/gdal_polygonize.py"
)
# Example 6: Stratified by CORINE ? Ecoregion intersection
process_otsu_rasters(
raster_path = "data/rbr_1985.tif",
output_dir = "output/1985",
corine_raster_path = "data/corine_1990_etrs89.tif",
reclassify_corine = TRUE,
reclass_matrix = matrix(c(
22, 1, 26, 1, 32, 1, # grasslands
27, 2, 29, 2, # shrublands
23, 4, 25, 5, 24, 6 # forests
), ncol = 2, byrow = TRUE),
corine_classes = c(1, 2, 4, 5, 6),
peninsula_shapefile = "data/peninsula_clip.shp",
output_corine_raster_dir = "output/corine",
output_corine_vector_dir = "output/corine",
ecoregion_shapefile_path = "data/ecoregions_olson.shp",
ecoregion_field = "EnZ_name",
segment_by_intersection = TRUE,
otsu_thresholds = c(50),
min_otsu_threshold_value = 150,
python_exe = "C:/Python/python.exe",
gdal_polygonize_script = "C:/Python/Scripts/gdal_polygonize.py"
)
}
Run the code above in your browser using DataLab