Create Raster Masks

library(geodl)

When working with geospatial data, it is common for features to be stored as vector data as opposed to categorical raster data. However, deep learning semantic segmentation requires raster-based labels where each unique class is assigned a unique numeric code. The purpose of the makeMasks() function is to generate raster masks from input vector data. It can also generate a copy of the reference raster data and allow for the output mask and image to be cropped relative to a defined extent. The parameters for this function are as follows:

makeMasks(image = "C:/myFiles/data/toChipBinary/image/KY_Saxton_709705_1970_24000_geo.tif",
          features = "C:/myFiles/data/toChipBinary/msks/KY_Saxton_709705_1970_24000_geo.shp",
          crop = TRUE,
          extent = "C:/myFiles/data/toChipBinary/extent/KY_Saxton_709705_1970_24000_geo.shp",
          field = "classvalue",
          background = 0,
          outImage = "C:/myFiles/data/toChipBinary/output/topoOut.tif",
          outMask = "C:/myFiles/data/toChipBinary/output/mskOut.tif",
          mode = "Both")

The plotRGB() function from the terra package can be used to visualized the cropped topographic map since it is an RGB or three-band file. In contrast, the raster mask can be visualized with plot() since it consists of only a single band.

terra::plotRGB(terra::rast("C:/myFiles/data/toChipBinary/output/topoOut.tif"))
Example cropped image
Example cropped image
terra::plot(terra::rast("C:/myFiles/data/toChipBinary/output/mskOut.tif"))
Example raster mask
Example raster mask