View source: R/render_region_plot.R
| render_region_plot | R Documentation |
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
)
infile |
Character path to the NetCDF input file. |
outfile |
Optional path for the output image file. If |
fileExtension |
Output file extension, one of |
visualizeVariables |
List with at least |
visualizeDataMax |
Numeric; used for colorbar tick calculation. |
lon_bounds, lat_bounds |
Numeric vectors of visible longitude/latitude bounds (unused here but part of API). |
lon_loc_vec, lat_loc_vec, name_loc_vec |
Optional location markers (lon/lat + labels). |
division |
Character name of the attribute/level used to select the region (e.g. |
selectedRegion |
Character code/value of the selected region (e.g. ISO3). |
region_data |
Spatial or sf object with user-provided regions (when |
timestep |
Selected timestep (should match an entry of |
num_tick, num_rmin, num_rmax |
Numeric settings for legend ticks and z range. |
location |
Logical; draw location markers if |
text1, text2, text3 |
Character strings for title, footer, and legend label. |
PAL, palettes, num_brk, reverse |
Color palette settings passed to |
textsize |
Numeric base text size used in plotting. |
bordercolor |
Color for region borders and markers. |
plot_grid, grid_col |
Currently unused plotting options (kept for API compatibility). |
image_def, ihsf |
Image sizing settings from the Toolbox. |
nc |
Optional opened NetCDF handle; if provided, |
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.
A named list with src (file path), contentType, width, height.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.