Introduction to geoidep"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  dpi = 300,
  out.width = "100%" 
)

1. Introduction

This package aims to provide R users with a new way of accessing official Peruvian cartographic data on various topics that are managed by the country's Spatial Data Infrastructure.

By offering a new approach to accessing this official data, both from technical-scientific entities and from regional and local governments, it facilitates the automation of processes, thereby optimizing the analysis and use of geospatial information across various fields.

However, this project is still under construction, for more information you can visit the GitHub official repository https://github.com/ambarja/geoidep.

If you want to support this project, you can support me with a coffee for my programming moments.

2. Package installation

install.packages("geoidep")

Also, you can install the development version as follows:

install.packages('pak')
pak::pkg_install('ambarja/geoidep')
library(geoidep)

3. Basic usage

providers <- get_data_sources()
providers
layers_available <- get_providers()
layers_available

4. Download Official Administrative Boundaries by INEI

# Region boundaries download 
loreto_prov <- get_provinces(show_progress = FALSE) |> 
  subset(NOMBDEP == 'LORETO')
library(leaflet)
library(sf)
loreto_prov |> 
  leaflet() |> 
  addTiles() |> 
  addPolygons()
# Defined Ubigeo 
loreto_prov[["ubigeo"]] <- paste0(loreto_prov[["CCDD"]],loreto_prov[["CCPP"]])
# The first five rows
head(loreto_prov)

5. Working with Geobosque data

my_fun <- function(x){
  data <- get_forest_loss_data(
    layer = 'stock_bosque_perdida_provincia',
    ubigeo = loreto_prov[["ubigeo"]][x],
    show_progress = FALSE )
  return(data)
}
historico_list <- lapply(X = 1:nrow(loreto_prov),FUN = my_fun)
historico_df <- do.call(rbind.data.frame,historico_list)
# The first five rows
head(historico_df)

6. Simple visualization with ggplot

library(ggplot2)
library(dplyr)
historico_df |> 
  inner_join(y = loreto_prov,by = "ubigeo") |> 
  ggplot(aes(x = anio,y = perdida)) + 
  geom_point(size = 1) + 
  geom_line() + 
  facet_wrap(NOMBPROV~.,ncol = 3) + 
  theme_minimal(base_size = 5) + 
  labs(
    title = "Pérdida de bosque histórico del 2001-2023 \npara las provincias de Loreto",
    caption = "Fuente: Geobosque",
    x = "",
    y = "") 


Try the geoidep package in your browser

Any scripts or data that you put into this service are public.

geoidep documentation built on Sept. 23, 2024, 1:06 a.m.