This function gets the extent of an area of interest (AOI) in GDAL format (xmin, ymin, xmax, ymax). The extent is provided both in latitude and longitude and in the projected coordinate reference system (CRS) specified by the user. The area of interest can be specified either by a country iso3 code, a vector file, or an extent (in latlon or projected CRS). When the area of interest is specified with a country iso3 code, the country borders are downloaded from the GADM (Global ADMinistrative areas database) at https://gadm.org.

get_aoi_extent(
  country_iso = NULL,
  vector_file = NULL,
  extent_proj = NULL,
  extent_latlon = NULL,
  EPSG_proj = 4326,
  resol = ifelse(EPSG_proj == 4326, 0.01, 1000),
  output_dir = "gadm",
  rm_output_dir = TRUE
)

Arguments

country_iso

character. Country iso3 code used to download the country borders from the GADM database. To be used when the AOI is a country. Default is NULL.

vector_file

character. Path to a vector file of polygons (such as .shp or .gpkg file) with AOI borders. The first layer will be used. Default is NULL.

extent_proj

num vector. Extent of the AOI in the projected coordinate reference system (see EPSG_proj). Vector of length 4, in this order c(xmin, ymin, xmax, ymax). Default is NULL.

extent_latlon

num vector. Extent of the AOI with latitudes and longitudes. Vector of length 4, in this order c(lonmin, latmin, lonmax, latmax). Default is NULL.

EPSG_proj

int. EPSG code of the projected coordinate reference system for the AOI. Default is 4326.

resol

num. Resolution used to align the coordinates of the extent (see tap parameter in GDAL for target aligned pixel). The resolution unit is the one of the EPSG code defined with EPSG_proj. Default is 1 degree for EPSG:4326 and 1000 meters otherwise.

output_dir

character. Output directory where the vector file for the country borders is downloaded. Default is "gadm".

rm_output_dir

boolean. If FALSE, does not remove the output directory. Default is TRUE.

Value

list. With extent_latlon: extent in latitude and longitude (lonmin, latmin, lonmax, latmax), extent_proj: projected extent (xmin, ymin, xmax, ymax), extent_latlon_orig: original extent (without tap) in latlon, and gpkg_file: path to .gpkg country vector file if downloaded.

Details

The projected extent (extent_proj) is always greater than the original extent and aligned with pixels (see tap parameter in GDAL for target aligned pixels). The extent in latitude and longitude (extent_latlon) is also aligned to the nearest 0.01 degree (about 1.1 km at the equator) and is always greater than the projected extent so that the projected extent is included in the latlon extent. This is done to reduce edge effects in later computations.