Title: | Neutral Landscape Generator with Targets on Landscape Indices |
---|---|
Description: | Interface to the 'flsgen' neutral landscape generator <https://github.com/dimitri-justeau/flsgen>. It allows to - Generate fractal terrain; - Generate landscape structures satisfying user targets over landscape indices; - Generate landscape raster from landscape structures. |
Authors: | Dimitri Justeau-Allaire, Grégoire Blanchard, Thomas Ibanez, Xavier Lorca, Ghislain Vieilledent, Philippe Birnbaum |
Maintainer: | Dimitri Justeau-Allaire <[email protected]> |
License: | GPL-3 |
Version: | 1.2.2 |
Built: | 2024-10-31 21:09:01 UTC |
Source: | CRAN |
Vector of available class targets
CLASS_LEVEL_TARGETS
CLASS_LEVEL_TARGETS
An object of class character
of length 16.
Creates a predefined landscape class structure that can be converted as JSON input for flsgen generate.
flsgen_create_class_structure(class_name, patch_areas, is_square = FALSE)
flsgen_create_class_structure(class_name, patch_areas, is_square = FALSE)
class_name |
Name of the class |
patch_areas |
Vector of patch areas |
is_square |
If true, all patches are required to be squares |
A landscape class structure
## Not run: cls_1 <- flsgen_class_structure("class 1", c(10, 100, 1000)) ## End(Not run)
## Not run: cls_1 <- flsgen_class_structure("class 1", c(10, 100, 1000)) ## End(Not run)
Creates a set of targets for a landscape class, which can be converted into JSON for flsgen.
flsgen_create_class_targets( class_name, NP = NULL, AREA = NULL, AREA_MN = NULL, CA = NULL, PLAND = NULL, PD = NULL, SPI = NULL, LPI = NULL, MESH = NULL, SPLI = NULL, NPRO = NULL, SDEN = NULL, COHE = NULL, DIVI = NULL, IS_SQUARE = FALSE, ALL_DIFFERENT = FALSE )
flsgen_create_class_targets( class_name, NP = NULL, AREA = NULL, AREA_MN = NULL, CA = NULL, PLAND = NULL, PD = NULL, SPI = NULL, LPI = NULL, MESH = NULL, SPLI = NULL, NPRO = NULL, SDEN = NULL, COHE = NULL, DIVI = NULL, IS_SQUARE = FALSE, ALL_DIFFERENT = FALSE )
class_name |
Name of the class |
NP |
number of patches target (must be a vector of length 2) |
AREA |
patch area target (must be a vector of length 2) |
AREA_MN |
mean patch area target (must be a vector of length 2) |
CA |
total class area target (must be a vector of length 2) |
PLAND |
proportion of landscape target (must be a vector of length 2) |
PD |
patch density target (must be a vector of length 2) |
SPI |
smallest patch index target (must be a vector of length 2) |
LPI |
largest patch index target (must be a vector of length 2) |
MESH |
effective mesh size target (must be a vector of length 2) |
SPLI |
splitting index target (must be a vector of length 2) |
NPRO |
net product target (must be a vector of length 2) |
SDEN |
splitting density target (must be a vector of length 2) |
COHE |
degree of coherence target (must be a vector of length 2) |
DIVI |
degree of landscape division target (must be a vector of length 2) |
IS_SQUARE |
if TRUE, the class is required to only produce square patches |
ALL_DIFFERENT |
if TRUE, the class is required to have differently sized patches |
Note that NP and AREA targets can be set as NULL, if the class targets is used within the 'generate_series' function to generate landscape series with varying NP and/or AREA. However, flsgen won't run is NP and AREA are not set elsewhere.
A class targets object which can be converted to JSON for flsgen
## Not run: cls_1 <- flsgen_create_class_targets("class 1", NP=c(1, 10), AREA=c(0, 1000)) ## End(Not run)
## Not run: cls_1 <- flsgen_create_class_targets("class 1", NP=c(1, 10), AREA=c(0, 1000)) ## End(Not run)
Creates a predefined landscape structure that can be converted as JSON converted as JSON Input for flsgen generate.
flsgen_create_landscape_structure( nb_rows, nb_cols, classes, mask_raster = NULL )
flsgen_create_landscape_structure( nb_rows, nb_cols, classes, mask_raster = NULL )
nb_rows |
Number of rows |
nb_cols |
Number of columns |
classes |
list of class structures |
mask_raster |
mask raster (path or terra::rast object) |
The class structures must be created prior to the call to this function
Either nb_rows and nb_cols, or mask_raster must be specified. The dimensions of the landscape are deduced from the mask raster if it is used.
A landscape structure object which can be converted to JSON for flsgen generate
## Not run: cls_1 <- flsgen_class_structure("class 1", c(10, 100, 1000)) cls_2 <- flsgen_class_structure("class 2", c(20, 200, 2000)) ls_struct <- flsgen_landscape_structure(200, 200, list(cls_1, cls_2)) ## End(Not run)
## Not run: cls_1 <- flsgen_class_structure("class 1", c(10, 100, 1000)) cls_2 <- flsgen_class_structure("class 2", c(20, 200, 2000)) ls_struct <- flsgen_landscape_structure(200, 200, list(cls_1, cls_2)) ## End(Not run)
Creates a set of targets for a landscape, which can be converted into JSON for flsgen.
flsgen_create_landscape_targets( nb_rows, nb_cols, classes, mask_raster = NULL, NON_FOCAL_PLAND = NULL )
flsgen_create_landscape_targets( nb_rows, nb_cols, classes, mask_raster = NULL, NON_FOCAL_PLAND = NULL )
nb_rows |
Number of rows |
nb_cols |
Number of columns |
classes |
list of class targets |
mask_raster |
mask raster (path or terra::rast object) |
NON_FOCAL_PLAND |
PLAND (proportion of landscape) target on the non-focal land-use class |
The class targets must be created prior to the call to this function
Either nb_rows and nb_cols, or mask_raster must be specified. The dimensions of the landscape are deduced from the mask raster if it is used.
A landscape targets object which can be converted to JSON for flsgen
## Not run: cls_1 <- flsgen_create_class_targets("class 1", NP=c(1, 10), AREA=c(0, 1000)) cls_2 <- flsgen_create_class_targets("class 2", NP=c(1, 10), AREA=c(0, 1000)) ls_targets <- flsgen_create_landscape_targets(200, 200, list(cls_1, cls_2)) ## End(Not run)
## Not run: cls_1 <- flsgen_create_class_targets("class 1", NP=c(1, 10), AREA=c(0, 1000)) cls_2 <- flsgen_create_class_targets("class 2", NP=c(1, 10), AREA=c(0, 1000)) ls_targets <- flsgen_create_landscape_targets(200, 200, list(cls_1, cls_2)) ## End(Not run)
Create a series of landscape targets, with one target for one class varying according to a specified sequence.
flsgen_create_target_series( landscape_targets, class_name = NULL, class_id = NULL, target_key, sequence )
flsgen_create_target_series( landscape_targets, class_name = NULL, class_id = NULL, target_key, sequence )
landscape_targets |
Number of rows |
class_name |
Name of the class for the varying target |
class_id |
Index of the class for the varying target |
target_key |
Varying target key |
sequence |
sequence (list) of targets for the varying target |
Either the class name of id must be given to identify the class to use for generating the series.
A list of landscape targets
## Not run: cls_1 <- flsgen_create_class_targets("class 1", NP=c(1, 10), AREA=c(0, 1000)) cls_2 <- flsgen_create_class_targets("class 2", AREA=c(0, 1000)) ls_targets <- flsgen_create_landscape_targets(200, 200, list(cls_1, cls_2)) target_series <- flsgen_create_target_series(ls_targets, class_name="class 2", target_key="NP", sequence=seq(1, 10, by=1)) ## End(Not run)
## Not run: cls_1 <- flsgen_create_class_targets("class 1", NP=c(1, 10), AREA=c(0, 1000)) cls_2 <- flsgen_create_class_targets("class 2", AREA=c(0, 1000)) ls_targets <- flsgen_create_landscape_targets(200, 200, list(cls_1, cls_2)) target_series <- flsgen_create_target_series(ls_targets, class_name="class 2", target_key="NP", sequence=seq(1, 10, by=1)) ## End(Not run)
Extracts a landscape structure from an existing raster
flsgen_extract_structure_from_raster( raster_file, focal_classes, connectivity = 4 )
flsgen_extract_structure_from_raster( raster_file, focal_classes, connectivity = 4 )
raster_file |
terra::rast object or path of the raster |
focal_classes |
vector of integers representing the raster values of the focal classes to extract the structure from |
connectivity |
Connectivity definition in the regular square grid (4 or 8)." |
A JSON landscape structure that can be used with flsgen generate
## Not run: ls_struct <- flsgen_extract_structure_from_raster(raster_path, c(0, 1, 2)) ## End(Not run)
## Not run: ls_struct <- flsgen_extract_structure_from_raster(raster_path, c(0, 1, 2)) ## End(Not run)
Generate landscape raster from landscape structure
flsgen_generate( structure_str, structure_file, terrain_file = NULL, roughness = 0.5, terrain_dependency = 0.5, min_distance = 2, min_max_distance = NULL, connectivity = 4, x = 0, y = 0, resolution_x = 1e-04, resolution_y = NULL, epsg = "EPSG:4326", max_try = 2, max_try_patch = 10, verbose = TRUE )
flsgen_generate( structure_str, structure_file, terrain_file = NULL, roughness = 0.5, terrain_dependency = 0.5, min_distance = 2, min_max_distance = NULL, connectivity = 4, x = 0, y = 0, resolution_x = 1e-04, resolution_y = NULL, epsg = "EPSG:4326", max_try = 2, max_try_patch = 10, verbose = TRUE )
structure_str |
JSON-formatted string describing the landscape structure to generate |
structure_file |
JSON file containing the landscape structure to generate |
terrain_file |
Path of input terrain raster file, or terra::rast object. If NULL a terrain is generated with the diamond-square algorithm |
roughness |
Roughness factor (or H), between 0 and 1 (only need when terrain_file is NULL) |
terrain_dependency |
Terrain dependency factor for landscape generation, between 0 and 1 |
min_distance |
Minimum distance between patches of a same class |
min_max_distance |
If defined, the minimum distance beween patches of a same class is defined by a variable buffer of width between min_distance and min_max_distance |
connectivity |
Connectivity definition in the regular square grid (4 or 8)." |
x |
X position (geographical coordinates) of the top-left output raster pixel |
y |
Y position (geographical coordinates) of the top-left output raster pixel |
resolution_x |
x spatial resolution (geographical units) of the output raster (i.e. pixel width) |
resolution_y |
y-spatial resolution (geographical units) of the output raster (i.e. pixel height), if null, resolution_x is used |
epsg |
EPSG identifier of the output projection |
max_try |
Maximum number of trials for landscape generation |
max_try_patch |
Maximum number of trials for patch generation |
verbose |
if TRUE print information about generation |
The input landscape structure must be either specified as a JSON-formatted string (structure_str parameter) or as a JSON file (structure_file parameter)
A terra::rast object
## Not run: json <- "{ \"nbRows\" : 200, \"nbCols\" : 200, \"classes\" : [ { \"name\" : \"Class A\", \"NP\" : [1, 10], \"AREA\" : [300, 4000], \"CA\" : [1000, 5000], \"MESH\" : [225, 225] }, { \"name\" : \"Class B\", \"NP\" : [2, 8], \"AREA\" : [200, 4000], \"PLAND\" : [40, 40] }, { \"name\" : \"Class C\", \"NP\" : [5, 7], \"AREA\" : [800, 1200] } ] }" structure <- flsgen_structure(targets_str = json) landscape <- flsgen_generate(structure_str = structure) ## End(Not run)
## Not run: json <- "{ \"nbRows\" : 200, \"nbCols\" : 200, \"classes\" : [ { \"name\" : \"Class A\", \"NP\" : [1, 10], \"AREA\" : [300, 4000], \"CA\" : [1000, 5000], \"MESH\" : [225, 225] }, { \"name\" : \"Class B\", \"NP\" : [2, 8], \"AREA\" : [200, 4000], \"PLAND\" : [40, 40] }, { \"name\" : \"Class C\", \"NP\" : [5, 7], \"AREA\" : [800, 1200] } ] }" structure <- flsgen_structure(targets_str = json) landscape <- flsgen_generate(structure_str = structure) ## End(Not run)
Find landscape structures satisfying user targets
flsgen_structure( targets_str, targets_file, nb_solutions = 1, time_limit = 60, search_strategy = "DEFAULT" )
flsgen_structure( targets_str, targets_file, nb_solutions = 1, time_limit = 60, search_strategy = "DEFAULT" )
targets_str |
JSON-formatted string describing user targets |
targets_file |
JSON file describing user targets |
nb_solutions |
Number of solutions to generate |
time_limit |
Time limit in seconds (if time_limit = 0, no time limit is set) |
search_strategy |
Choco solver search strategy (for more details refer to Choco solver documentation: https://choco-solver.org/docs/) |
The input user targets must be either specified as a JSON-formatted string (targets_str parameter) or as a JSON file (target_file parameter).
A vector of JSON-formatted landscape structures satisfying user targets.
## Not run: json <- "{ \"nbRows\" : 200, \"nbCols\" : 200, { \"name\" : \"Class A\", \"NP\" : [1, 10], \"AREA\" : [300, 4000], \"CA\" : [1000, 5000], \"MESH\" : [225, 225] }, { \"name\" : \"Class B\", \"NP\" : [2, 8], \"AREA\" : [200, 4000], \"PLAND\" : [40, 40] }, { \"name\" : \"Class C\", \"NP\" : [5, 7], \"AREA\" : [800, 1200] } ] }" structure <- flsgen_structure(targets_str = json) ## End(Not run)
## Not run: json <- "{ \"nbRows\" : 200, \"nbCols\" : 200, { \"name\" : \"Class A\", \"NP\" : [1, 10], \"AREA\" : [300, 4000], \"CA\" : [1000, 5000], \"MESH\" : [225, 225] }, { \"name\" : \"Class B\", \"NP\" : [2, 8], \"AREA\" : [200, 4000], \"PLAND\" : [40, 40] }, { \"name\" : \"Class C\", \"NP\" : [5, 7], \"AREA\" : [800, 1200] } ] }" structure <- flsgen_structure(targets_str = json) ## End(Not run)
Fractal terrain generation with the diamond-square algorithm
flsgen_terrain( width, height, roughness = 0.5, x = 0, y = 0, resolution = 1e-04, epsg = "EPSG:4326" )
flsgen_terrain( width, height, roughness = 0.5, x = 0, y = 0, resolution = 1e-04, epsg = "EPSG:4326" )
width |
Width (in pixels) of output raster |
height |
Height (in pixels) of output raster |
roughness |
Roughness factor (or H), between 0 and 1 |
x |
X position (geographical coordinates) of the top-left output raster pixel |
y |
Y position (geographical coordinates) of the top-left output raster pixel |
resolution |
Spatial resolution (geographical units) of the output raster (i.e. pixel dimension) |
epsg |
EPSG identifier of the output projection |
A terra::rast object
## Not run: terrain <- flsgen_terrain(200, 200) ## End(Not run)
## Not run: terrain <- flsgen_terrain(200, 200) ## End(Not run)