Produces a map image for a selected region by cropping/masking a NetCDF raster, handling longitude wrap (0–360 -> -180–180), CRS alignment, and setting sane plot limits/aspect. Designed for use in the CM SAF R Toolbox.
render_region_plot(
infile,
outfile = NULL,
fileExtension = ".png",
visualizeVariables,
visualizeDataMax,
lon_bounds,
lat_bounds,
lon_loc_vec,
lat_loc_vec,
name_loc_vec,
division,
selectedRegion,
region_data,
timestep,
num_tick,
num_rmin,
num_rmax,
location,
text1,
text2,
text3,
PAL,
palettes,
num_brk,
reverse,
textsize,
bordercolor,
plot_grid,
grid_col,
image_def,
ihsf,
nc = NULL
)A named list with src (file path), contentType, width, height.
Character path to the NetCDF input file.
Optional path for the output image file. If NULL, a temp file is used.
Output file extension, one of ".png", ".jpg", ".pdf".
List with at least $vn (variable name) and $date.time.
Numeric; used for colorbar tick calculation.
Numeric vectors of visible longitude/latitude bounds (unused here but part of API).
Optional location markers (lon/lat + labels).
Character name of the attribute/level used to select the region (e.g. "COUNTRY" or a shapefile field).
Character code/value of the selected region (e.g. ISO3).
Spatial or sf object with user-provided regions (when division != "COUNTRY").
Selected timestep (should match an entry of visualizeVariables$date.time).
Numeric settings for legend ticks and z range.
Logical; draw location markers if TRUE.
Character strings for title, footer, and legend label.
Color palette settings passed to getColors().
Numeric base text size used in plotting.
Color for region borders and markers.
Currently unused plotting options (kept for API compatibility).
Image sizing settings from the Toolbox.
Optional opened NetCDF handle; if provided, infile <- nc$filename.
The function:
Loads the raster brick for the requested variable.
Normalizes longitudes to -180 to 180 if input is 0–360 (via raster::rotate).
Validates/aligns the region geometry (sf -> Spatial, EPSG:4326, transform to raster CRS).
Crops/masks the raster by the region and draws the image with geographic aspect.
The package lwgeom is used optionally (via requireNamespace) to fix invalid geometries;
a st_buffer(., 0) fallback is applied if lwgeom is not available.