Last active
August 9, 2022 20:55
-
-
Save fernandobarbalho/40f7e6c0cf925065e21084062e5ad513 to your computer and use it in GitHub Desktop.
script para leitura e tratamento de tabela do ibama sobre oleamento de praias do NE
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
library(tabulizer) | |
library(dplyr) | |
setwd("~/GitHub/oleogate/data") | |
#Extrai tabelas do arquivo pdf. | |
#Esse arquivo foi baixado do seguinte link | |
# https://politica.estadao.com.br/blogs/estadao-verifica/wp-content/uploads/sites/690/2019/10/Ibama.pdf | |
#A tabela é extraída para um arquivo csv de forma a poder trabalhar melhor questões de encoding | |
tabulizer::extract_tables("ibama.pdf", output = "csv",outdir = getwd()) | |
library(readr) | |
#lê o arquivo já com o formato de encoding apropriado | |
ibama <- read_csv("ibama-2.csv", locale = locale(encoding = "LATIN1")) | |
devtools::install_github("laresbernardo/lares") | |
library(lares) | |
library(stringr) | |
library(rlang) | |
names(ibama)[1]<- "Localidade" | |
names(ibama)[2]<-"Municipio" | |
names(ibama)[3]<-"data_avistamento" | |
names(ibama)[4]<-"uf" | |
#Converte tudo em maíusculo e faz limpeza de texto para facilitar joins com outras tabelas | |
ibama$Municipio<- str_to_upper(cleanText(ibama$Municipio)) | |
ibama$Localidade<- str_to_upper(cleanText(ibama$Localidade)) | |
#Corrige nomenclatura de alguns municípios | |
ibama[ibama$Municipio== "PORTO DE PEDRA",2]<- "PORTO DE PEDRAS" | |
ibama[ibama$Municipio== "CEARAMIRIM",2]<- "CEARA-MIRIM" | |
#Corrige UFs de alguns municípios | |
ibama[ibama$Municipio== "SAO CRISTOVAO",4]<- "SE" | |
ibama[ibama$Municipio== "SIRINHAEM",4]<- "PE" | |
ibama[ibama$Municipio== "ILHA GRANDE",4]<- "PI" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Provavelmente o município se acreditamos nas posições. (Fiz a checagem por elas.)