Skip to content

Commit 2a08cc3

Browse files
committed
Merge branch 'master' into issue-287
2 parents 61c0963 + 79ac551 commit 2a08cc3

File tree

139 files changed

+6381
-2633
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+6381
-2633
lines changed
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
on:
2+
push:
3+
paths:
4+
- python-package/**
5+
branches:
6+
- main
7+
- master
8+
- dev
9+
pull_request:
10+
paths:
11+
- python-package/**
12+
branches:
13+
- main
14+
- master
15+
- dev
16+
17+
name: Python-CMD-check
18+
19+
jobs:
20+
Python-CMD-check:
21+
runs-on: ${{ matrix.os }}
22+
23+
name: ${{ matrix.os }} (${{ matrix.python-version }})
24+
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
os: [ubuntu-latest, macOS-latest, windows-latest]
29+
python-version: ["3.9", "3.10", "3.11"]
30+
# Python 3.8 support ends in 2024-10
31+
# Python 3.12 support starts in 2023-10
32+
# Check Python maintenance status at: https://www.python.org/downloads/
33+
34+
env:
35+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
36+
37+
steps:
38+
- name: Check out geobr
39+
uses: actions/checkout@v3
40+
41+
- name: Setup Python ${{ matrix.python-version }}
42+
uses: actions/setup-python@v4
43+
with:
44+
python-version: ${{ matrix.python-version }}
45+
cache: "pip"
46+
47+
- name: Install Poetry
48+
run: |
49+
python -m pip install --upgrade pip
50+
pip install poetry
51+
52+
- name: Install dependencies with Poetry
53+
run: poetry install
54+
working-directory: python-package
55+
56+
- name: Run tests with Poetry
57+
run: |
58+
poetry run pytest ./tests
59+
working-directory: python-package
60+
61+
- name: Upload check results
62+
if: always()
63+
uses: actions/upload-artifact@v3
64+
with:
65+
name: test-results
66+
path: python-package/test-results.txt
67+
if-no-files-found: warn
+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
2+
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
3+
on:
4+
push:
5+
paths:
6+
- r-package/**
7+
branches:
8+
- main
9+
- dev
10+
pull_request:
11+
paths:
12+
- r-package/**
13+
branches:
14+
- main
15+
- dev
16+
17+
name: R-CMD-check-as-CRAN
18+
19+
jobs:
20+
R-CMD-check:
21+
runs-on: ${{ matrix.config.os }}
22+
23+
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
24+
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
config:
29+
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
30+
31+
env:
32+
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
33+
RSPM: ${{ matrix.config.rspm }}
34+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
35+
36+
steps:
37+
- uses: actions/checkout@v2
38+
39+
- uses: r-lib/actions/setup-r@v2
40+
with:
41+
r-version: ${{ matrix.config.r }}
42+
43+
- uses: r-lib/actions/setup-pandoc@v2
44+
45+
- name: Query dependencies
46+
run: |
47+
install.packages('remotes')
48+
saveRDS(remotes::dev_package_deps(dependencies = TRUE), "../.github/depends.Rds", version = 2)
49+
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), "../.github/R-version")
50+
shell: Rscript {0}
51+
working-directory: r-package
52+
53+
- name: Cache R packages
54+
uses: actions/cache@v2
55+
with:
56+
path: ${{ env.R_LIBS_USER }}
57+
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
58+
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
59+
60+
- name: Install system dependencies
61+
run: |
62+
while read -r cmd
63+
do
64+
eval sudo $cmd
65+
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
66+
working-directory: r-package
67+
68+
- name: Install dependencies
69+
run: |
70+
remotes::install_deps(dependencies = TRUE)
71+
remotes::install_cran("rcmdcheck")
72+
shell: Rscript {0}
73+
working-directory: r-package
74+
75+
- name: Check
76+
env:
77+
_R_CHECK_CRAN_INCOMING_REMOTE_: false
78+
NOT_CRAN: false
79+
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
80+
shell: Rscript {0}
81+
working-directory: r-package
82+
83+
- name: Upload check results
84+
if: failure()
85+
uses: actions/upload-artifact@main
86+
with:
87+
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
88+
path: check

.github/workflows/R-CMD-check.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- {os: windows-latest, r: 'release'}
3232
- {os: windows-latest, r: 'oldrel'}
3333
- {os: macOS-latest, r: 'release'}
34-
- {os: macOS-latest, r: 'oldrel'}
34+
# - {os: macOS-latest, r: 'oldrel'}
3535
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
3636
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
3737
- {os: ubuntu-20.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
@@ -44,11 +44,11 @@ jobs:
4444
steps:
4545
- uses: actions/checkout@v2
4646

47-
- uses: r-lib/actions/setup-r@v1
47+
- uses: r-lib/actions/setup-r@v2
4848
with:
4949
r-version: ${{ matrix.config.r }}
5050

51-
- uses: r-lib/actions/setup-pandoc@v1
51+
- uses: r-lib/actions/setup-pandoc@v2
5252

5353
- name: Query dependencies
5454
run: |

.github/workflows/pkgdown.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v2
1515

16-
- uses: r-lib/actions/setup-r@v1
16+
- uses: r-lib/actions/setup-r@v2
1717

18-
- uses: r-lib/actions/setup-pandoc@v1
18+
- uses: r-lib/actions/setup-pandoc@v2
1919

2020
- name: Query dependencies
2121
run: |

.github/workflows/test-coverage.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
steps:
2525
- uses: actions/checkout@v2
2626

27-
- uses: r-lib/actions/setup-r@v1
27+
- uses: r-lib/actions/setup-r@v2
2828
id: install-r
2929

3030
- name: Install pak and query dependencies

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
*.out
99
*.toc
1010
*.ind
11+
*.gpkg
12+
*.rds
1113
*.Rhistory
1214
/R/.Rhistory
1315
/r-package/.Rhistory
1416
/.Rhistory
1517
/man/figures/.Rhistory
1618
/r-package/.Rhistory
1719
/prep_data/.Rhistory
18-
/data-raw/
20+
/data_prep/data/*
21+
/data_prep/data_raw/*
22+
/data_prep/_targets/*
1923

2024
inst/doc
2125
Meta

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ The package is currently available in [**R**](https://CRAN.R-project.org/package
1111

1212
| ***R*** | ***Python*** | ***Repo***|
1313
|-----|-----|----|
14-
| [![CRAN/METACRAN Version](https://www.r-pkg.org/badges/version/geobr)](https://CRAN.R-project.org/package=geobr) <br /> [![CRAN/METACRAN Total downloads](http://cranlogs.r-pkg.org/badges/grand-total/geobr?color=blue)](https://CRAN.R-project.org/package=geobr) <br /> [![CRAN/METACRAN downloads per month](http://cranlogs.r-pkg.org/badges/geobr?color=yellow)](https://CRAN.R-project.org/package=geobr) <br /> [![Codecov test coverage](https://codecov.io/gh/ipeaGIT/geobr/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ipeaGIT/geobr?branch=master) <br /> [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) | [![PyPI version](https://badge.fury.io/py/geobr.svg)](https://badge.fury.io/py/geobr) <br /> [![Downloads](https://pepy.tech/badge/geobr)](https://pepy.tech/project/geobr) <br /> [![Downloads](https://pepy.tech/badge/geobr/month)](https://pepy.tech/project/geobr/month) <br /> [![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing) |<img alt="GitHub stars" src="https://img.shields.io/github/stars/ipeaGIT/geobr.svg?color=orange"> <br /> [![R build status](https://github.com/ipeaGIT/geobr/workflows/R-CMD-check/badge.svg)](https://github.com/ipeaGIT/geobr/actions) <br /> [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) |
14+
| [![CRAN/METACRAN Version](https://www.r-pkg.org/badges/version/geobr)](https://CRAN.R-project.org/package=geobr) <br /> [![CRAN/METACRAN Total downloads](http://cranlogs.r-pkg.org/badges/grand-total/geobr?color=blue)](https://CRAN.R-project.org/package=geobr) <br /> [![CRAN/METACRAN downloads per month](http://cranlogs.r-pkg.org/badges/geobr?color=yellow)](https://CRAN.R-project.org/package=geobr) <br /> [![Codecov test coverage](https://codecov.io/gh/ipeaGIT/geobr/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ipeaGIT/geobr?branch=master) <br /> [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) <br /> [![R build status](https://github.com/ipeaGIT/geobr/workflows/R-CMD-check/badge.svg)](https://github.com/ipeaGIT/geobr/actions) | [![PyPI version](https://badge.fury.io/py/geobr.svg)](https://badge.fury.io/py/geobr) <br /> [![Downloads](https://static.pepy.tech/badge/geobr)](https://pepy.tech/project/geobr) <br /> [![Downloads](https://static.pepy.tech/badge/geobr/month)](https://pepy.tech/project/geobr) <br /> [![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing) <br /> [![Python build status](https://github.com/ipeaGIT/geobr/workflows/Python-CMD-check/badge.svg)](https://github.com/ipeaGIT/geobr/actions) |<img alt="GitHub stars" src="https://img.shields.io/github/stars/ipeaGIT/geobr.svg?color=orange"> <br /> <br /> [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) |
15+
1516

1617

1718

@@ -95,7 +96,7 @@ More examples [here](https://github.com/ipeaGIT/geobr/tree/master/python-package
9596
|`read_micro_region`| Micro region | 2000, 2001, 2010, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 | IBGE |
9697
|`read_intermediate_region`| Intermediate region | 2017, 2019, 2020 | IBGE |
9798
|`read_immediate_region`| Immediate region | 2017, 2019, 2020 | IBGE |
98-
|`read_municipality`| Municipality | 1872, 1900, 1911, 1920, 1933, 1940, 1950, 1960, 1970, 1980, 1991, 2000, 2001, 2005, 2007, 2010, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 | IBGE |
99+
|`read_municipality`| Municipality | 1872, 1900, 1911, 1920, 1933, 1940, 1950, 1960, 1970, 1980, 1991, 2000, 2001, 2005, 2007, 2010, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 | IBGE |
99100
|`read_municipal_seat`| Municipality seats (sedes municipais) | 1872, 1900, 1911, 1920, 1933, 1940, 1950, 1960, 1970, 1980, 1991, 2010 | IBGE |
100101
|`read_weighting_area`| Census weighting area (área de ponderação) | 2010 | IBGE |
101102
|`read_census_tract`| Census tract (setor censitário) | 2000, 2010, 2017, 2019, 2020 | IBGE |
@@ -108,10 +109,10 @@ More examples [here](https://github.com/ipeaGIT/geobr/tree/master/python-package
108109
|`read_disaster_risk_area` | Disaster risk areas | 2010 | CEMADEN and IBGE |
109110
|`read_indigenous_land` | Indigenous lands | 201907, 202103 | FUNAI |
110111
|`read_semiarid` | Semi Arid region | 2005, 2017 | IBGE |
111-
|`read_health_facilities` | Health facilities | 2015 | CNES, DataSUS |
112+
|`read_health_facilities` | Health facilities | 201505, 202303 | CNES, DataSUS |
112113
|`read_health_region` | Health regions and macro regions | 1991, 1994, 1997, 2001, 2005, 2013 | DataSUS |
113114
|`read_neighborhood` | Neighborhood limits | 2010 | IBGE |
114-
|`read_schools` | Schools | 2020 | INEP |
115+
|`read_schools` | Schools | 2020, 2023 | INEP |
115116
|`read_comparable_areas` | Historically comparable municipalities, aka Areas minimas comparaveis (AMCs) | 1872,1900,1911,1920,1933,1940,1950,1960,1970,1980,1991,2000,2010 | IBGE |
116117
|`read_urban_concentrations` | Urban concentration areas (concentrações urbanas) | 2015 | IBGE |
117118
|`read_pop_arrangements` | Population arrangements (arranjos populacioanis) | 2015 | IBGE |

data_prep/.RData

2.53 KB
Binary file not shown.

data_prep/R/census_tract_2022.R

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
library(sf)
2+
library(data.table)
3+
library(dplyr)
4+
5+
6+
year <- 2022
7+
8+
# create dest dir
9+
raw_dir <- paste0('./data_raw/census_tracts/',year)
10+
dest_dir <- paste0('./data/census_tracts/',year)
11+
dir.create(raw_dir, recursive = T)
12+
dir.create(dest_dir, recursive = T)
13+
14+
15+
16+
17+
#### 0. Download original data sets from IBGE ftp -----------------
18+
19+
if(year == 2022){
20+
21+
dest_file <- download_file(file_url = ftp, dest_dir = raw_dir)
22+
23+
}
24+
25+
26+
#### 1. unzip -----------------
27+
28+
temp_dir <- tempdir()
29+
30+
unzip(dest_file, exdir = temp_dir)
31+
32+
local_file <- unzip_fun(dest_file)
33+
34+
35+
36+
df <- sf::st_read('./data_raw/census_tracts/2022/BR_Malha_Preliminar_2022.gpkg')
37+
saveRDS(df, './data_raw/census_tracts/2022/BR_Malha_Preliminar_2022.rds')
38+
39+
40+
41+
#### 1. clean and save data -----------------
42+
43+
df$AREA_KM2 <- NULL
44+
45+
temp_sf <- dplyr::rename(df,
46+
code_tract = CD_SETOR,
47+
code_muni = CD_MUN,
48+
name_muni = NM_MUN,
49+
code_subdistrict = CD_SUBDIST,
50+
name_subdistrict = NM_SUBDIST,
51+
code_district = CD_DIST,
52+
name_district = NM_DIST,
53+
code_urban_concentration = CD_CONCURB,
54+
name_urban_concentration = NM_CONCURB,
55+
code_state = CD_UF,
56+
name_state = NM_UF,
57+
code_micro = CD_MICRO,
58+
name_micro = NM_MICRO,
59+
code_meso = CD_MESO,
60+
name_meso = NM_MESO,
61+
code_immediate = CD_RGI,
62+
name_immediate = NM_RGI,
63+
code_intermediate = CD_RGINT,
64+
name_intermediate = NM_RGINT,
65+
code_region = CD_REGIAO,
66+
name_region = NM_REGIAO
67+
)
68+
head(temp_sf)
69+
70+
71+
# remove P from code tract
72+
temp_sf <- mutate(temp_sf, code_tract = gsub("P","", code_tract))
73+
head(temp_sf)
74+
75+
76+
# make all columns as character
77+
char_cols <- names(temp_sf)
78+
char_cols <- char_cols[char_cols %like% 'code_|name_']
79+
temp_sf <- mutate(temp_sf, across(all_of(char_cols), as.character))
80+
81+
82+
# Use UTF-8 encoding
83+
temp_sf <- use_encoding_utf8(temp_sf)
84+
85+
# Harmonize spatial projection CRS, using SIRGAS 2000 epsg (SRID): 4674
86+
temp_sf <- harmonize_projection(temp_sf)
87+
gc()
88+
89+
90+
# harmonize and save
91+
92+
save_state <- function(code_uf){ # code_uf <- 33
93+
94+
temp_sf2 <- subset(temp_sf, code_state == code_uf)
95+
# temp_sf2 <- subset(temp_sf2, code_muni == '3304557')
96+
97+
# convert to MULTIPOLYGON
98+
temp_sf2 <- to_multipolygon(temp_sf2)
99+
100+
# simplify
101+
temp_sf_simplified <- simplify_temp_sf(temp_sf2, tolerance = 10)
102+
103+
# Save cleaned sf in the cleaned directory
104+
sf::st_write(temp_sf2, paste0(dest_dir,'/', code_uf,'census_tract_', year, '.gpkg'))
105+
sf::st_write(temp_sf_simplified, paste0(dest_dir,'/', code_uf,'census_tract_', year, '_simplified.gpkg'))
106+
107+
}
108+
109+
110+
all_states <- unique(temp_sf$code_state)
111+
112+
# Apply function to save the data
113+
gc(reset = T)
114+
115+
# tictoc::tic()
116+
# future::plan(strategy = 'multisession')
117+
# furrr::future_map(.x=all_states, .f=save_state, .progress = T)
118+
# tictoc::toc()
119+
120+
121+
tictoc::tic()
122+
pbapply::pblapply(X=all_states, FUN=save_state)
123+
tictoc::toc()

0 commit comments

Comments
 (0)