Created
March 29, 2021 19:50
-
-
Save gabrielzanlorenssi/fdd96f938ec0125d2591e2820d6bbbed to your computer and use it in GitHub Desktop.
Código de R para calcular a extensão das fronteiras dos estados brasileiros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bibliotecas ------------------------------------------------------------- | |
library(tidyverse) | |
library(sf) | |
library(sp) | |
library(rgeos) | |
# devtools::install_github("Nexo-Dados/nexo.utils") | |
library(nexo.utils) | |
# Trabalho dos dados ------------------------------------------------------ | |
# leitura do shapefile de estados do IBGE, | |
# disponível em https://www.ibge.gov.br/geociencias/organizacao-do-territorio/estrutura-territorial/15774-malhas.html?=&t=downloads | |
uf <- as(st_read('BR_UF_2019.shp'), Class="Spatial") | |
# funçao para determinar a intersecção entre os estados brasileiros | |
board <- function(x,y) { | |
b <- gIntersection(uf[x,], uf[y,] ) | |
l <- st_length(st_as_sf(b)) | |
return(l) | |
} | |
poss_board <- possibly(board, otherwise = 0) | |
# calcular o comprimento das fronteiras dos estados | |
len <- map(1:27, function(uf) { | |
map2_dbl(uf, 1:27, poss_board)}) | |
# consolidar as métricas com o shapefile | |
uf2 <- st_as_sf(uf) %>% | |
mutate(length = len) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment