library(geodata)5 Data Processing
LogoClim integrates WorldClim data into NetLogo models through a multi-step conversion process that can introduce minor discrepancies between the original data and the values used in the model. We recommend verifying data accuracy by running the Near-Equality Tests notebook before proceeding with your analysis.
To convert the downloaded GeoTIFF files to Esri ASCII grid format, we developed the worldclim_to_ascii() function, also part of the orbis R package (Vartanian, 2026). Just like worldclim_download(), it is pretty straightforward to use. Here is a overview of its main parameters:
worldclim_to_ascii(
file,
shape = NULL
box = NULL
)worldclim_to_ascii allow you not only convert the GeoTIFF files to Esri ASCII format, but also crop the data to a specific region of interest. This is done using the shape or box parameters.
The first parameter, shape, expects a spatial object that defines the area to crop. The second parameter, box, allows you to specify a bounding box using numeric coordinates. You can use one or the other, but not both at the same time. If neither is provided, the function will convert the entire dataset without cropping.
5.1 Shapes
To obtain shapes of countries and their administrative boundaries, we recommend using the geodata R package (Hijmans et al., 2024), which provides access to shapes from the GADM database (Hijmans, n.d.). You can install in R with:
install.packages("geodata")And load it with:
With geodata loaded, use the gadm() function to download country shapes. This function identifies countries using the ISO 3166-1 alpha-3 standard and supports multiple resolutions, from country boundaries (level 0) to administrative subdivisions (levels 1, 2, and 3).
For example, if you want to crop WorldClim data to the boundaries of Brazil, you could use the following code:
country_shape <- gadm("BRA", level = 0)This code will download the shape of Brazil and store it in the country_shape variable, which can then be passed to the shape parameter of the worldclim_to_ascii function for cropping.
Code
library(leaflet)
library(sf)
leaflet() |>
addProviderTiles(providers$Esri.WorldStreetMap) |>
fitBounds(
lng1 = country_shape |>
st_bbox() |>
magrittr::extract("xmin") |>
unname(),
lat1 = country_shape |>
st_bbox() |>
magrittr::extract("ymin") |>
unname(),
lng2 = country_shape |>
st_bbox() |>
magrittr::extract("xmax") |>
unname(),
lat2 = country_shape |>
st_bbox() |>
magrittr::extract("ymax") |>
unname()
) |>
addPolygons(
data = country_shape,
fillColor = "transparent",
color = "blue",
weight = 2,
opacity = 1
)