write_raster_factors creates a template as a csv file for supplying code definition metadata for spatial rasters if raster values are categorical.

write_raster_factors(
  buildFromFile = FALSE,
  rangeStart,
  rangeEnd,
  rasterFile,
  overwrite = FALSE
)

Arguments

buildFromFile

Logical indicating whether the raster categories should be constructed from the contents of the raster (TRUE) or if the user will provide the range of categories (FALSE, default). If TRUE, the function will identify the smallest and largest raster values, and construct a sequence from these end points.

rangeStart

Starting range of categorical variables when provided by the user.

rangeEnd

End range of categorical variables when provided by the user.

rasterFile

Quoted full path to raster file. This parameter is required regardless of whether the template is build from user-provided values or raster content.

overwrite

A logical to force creating the template from raster content when raster values are not integers. When generating categorical variables from raster content, the function will identify the lowest and highest raster values. By generating the template content from the raster content, the user is indicating that the raster values are categorical. As such, the resulting values should be integers. The function will stop if it detects that the lowest or highest value is not an integer, but this can be overwritten by setting overwrite = TRUE.

Value

A template for providing code definition metadata as a csv file with the file name of the raster + "_factors.csv" is created in the directory where the raster resides.

Details

The csv template generated by write_raster_factors includes an arbitrary field name (raster_value). The number of categories can be estimated from the contents of the raster (buildFromFile = TRUE), or a range of categorical values (e.g., 1 through 15) can be provided by the user (buildFromFile = FALSE). If the user provides the range of categorical variables, the template will be constructed from the lowest to the highest number provided in increments of one but the template can be edited appropriately as constructed if this is not appropriate (e.g., remove 2 from the sequence if 2 is not in fact a categorial value included in the raster). The template supports the ability to provide a definition for each level. The csv file is written with the name of the raster file + "_factors". The create_spatialRaster function will search for this file when creating a EML spatial raster entity.

Note

Constructing the template from raster content (i.e., buildFromFile = TRUE) can be extremely computationally and time intensive for large rasters.

Examples

# example: write raster factors template file, allowing the function to # identify the unique raster values: # write_raster_factors(buildFromFile = TRUE, # rasterFile = '~/Desktop/smaller_raster.tif') # example: write raster factors template file, with the user setting the # starting and ending range of raster values: # write_raster_factors(rangeStart = 1, # rangeEnd = 12, # rasterFile = '~/Desktop/smaller_raster.tif') # example: write raster factors template file, with the user setting the # starting and ending range of raster values, and overwriting an existing # raster factors template file: # write_raster_factors(rangeStart = 1, # rangeEnd = 12, # rasterFile = '~/Desktop/smaller_raster.tif', # overwrite = TRUE)