Skip to contents

This function allows you to download the latest version of MIDAGRI geographic data. For more information you can visit the following page https://siea.midagri.gob.pe/.

Usage

get_midagri_data(layer = NULL, dsn = NULL, show_progress = TRUE, quiet = TRUE)

Arguments

layer

A string. Specifies the layer to download. Available layers are detailed in the 'Details' section.

dsn

Character. The output filename in .shp or .gpkg format. If not provided, a temporary file will be created.

show_progress

Logical. If TRUE, displays a progress bar during the download.

quiet

Logical. If TRUE, suppresses informational messages.

Value

An `sf` object containing the downloaded geographic data.

Details

Available layers are:

  • vegetation_cover: Polygons representing agricultural areas of Peru, produced from high-resolution satellite images (RapidEye and Sentinel-2).

  • agriculture_sector: Polygons representing the new national register of agricultural statistical sectors for the year 2024.

  • oil_palm_areas: Polygons representing areas cultivated with oil palm in Peru for the period 2016 to 2020.

  • experimental_stations: Points representing agricultural experimental stations in Peru.

Examples

# \donttest{
library(geoidep)
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
# Disable the use of S2 geometry for accurate spatial operations
sf_use_s2(use_s2 = FALSE)
#> Spherical geometry (s2) switched off

# Retrieve the polygon for Coronel Portillo province
coronel_portillo <- get_provinces(show_progress = FALSE) |>
  subset(NOMBPROV == "CORONEL PORTILLO") |>
  st_transform(crs = 32718)

# Download and extract the oil palm layer for Coronel Portillo
oil_palm <- get_midagri_data(
  layer = "oil_palm_areas",
  show_progress = FALSE
) |>
  st_intersection(coronel_portillo)
#> Warning: attribute variables are assumed to be spatially constant throughout all geometries

# Visualize the oil palm layer
plot(st_geometry(oil_palm))

# }