Skip to content

Commit 73ca8cb

Browse files
committed
Merge branch 'master' of https://github.com/ipeaGIT/geobr
2 parents b7aa130 + 7049f63 commit 73ca8cb

22 files changed

+527
-179
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ 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://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 /> [![Travis-CI Build Status](https://travis-ci.org/ipeaGIT/geobr.svg?branch=master)](https://travis-ci.org/ipeaGIT/geobr) <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://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) |
1515

1616

1717

@@ -168,11 +168,11 @@ As of today, there is another R package with similar functionalities: [simplefea
168168
- Brazil: [geobr](https://ipeagit.github.io/geobr/)
169169
- Canada: [cancensus](https://mountainmath.github.io/cancensus/index.html)
170170
- Chile: [chilemapas](https://pacha.dev/chilemapas/)
171+
- Czech Republic: [RCzechia](https://github.com/jlacko/RCzechia)
171172
- Finland: [geofi](https://ropengov.github.io/geofi/)
172173
- Uruguay: [geouy](https://github.com/RichDeto/geouy)
173174
- USA: [tigris](https://github.com/walkerke/tigris)
174-
- Global (political administrative boundaries): [rgeoboundaries](https://dickoa.gitlab.io/rgeoboundaries/)
175-
175+
- Global (political administrative boundaries): [rgeoboundaries](https://dickoa.gitlab.io/rgeoboundaries/)
176176

177177
-----
178178

python-package/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# log history of geobr package development in Python
22

33
-------------------------------------------------------
4+
5+
# 0.1.9
6+
* Adds read_schools
7+
* Adds read_comparable_areas
8+
* Adds read_urban_concentrations
9+
* Adds read_intermediate_region
10+
* updates read_health_region
411
# v0.1.7
512

613
* Adds read_health_region.py

python-package/geobr/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@
2020
from .read_weighting_area import read_weighting_area
2121
from .read_neighborhood import read_neighborhood
2222
from .read_health_region import read_health_region
23-
from .read_pop_arrangements import read_pop_arrangements
23+
from .read_pop_arrangements import read_pop_arrangements
24+
from .lookup_muni import lookup_muni
25+
from .read_intermediate_region import read_intermediate_region
26+
from .read_urban_concentrations import read_urban_concentrations
27+
from .read_schools import read_schools
28+
from .read_comparable_areas import read_comparable_areas

python-package/geobr/lookup_muni.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
try:
2-
import utils
3-
except ModuleNotFoundError:
4-
import geobr.utils as utils
1+
from geobr import utils
52

63

74
def lookup_muni(name_muni=None, code_muni=None, verbose=False):
8-
""" Lookup municipality codes and names.
5+
"""Lookup municipality codes and names.
96
107
By default, it looks for all municipalities. You can also use 'all' to in
11-
`name_muni` or `code_muni` to get all municipalities.
8+
`name_muni` or `code_muni` to get all municipalities.
129
13-
Input a municipality NAME or CODE and get the names and codes of
14-
the municipality's corresponding state, meso, micro, intermediate, and
10+
Input a municipality NAME or CODE and get the names and codes of
11+
the municipality's corresponding state, meso, micro, intermediate, and
1512
immediate regions. You should not select both code_muni and name_muni
1613
1714
Parameters
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from geobr.utils import select_metadata, download_gpkg
2+
3+
4+
def read_comparable_areas(
5+
start_year=1970, end_year=2010, simplified=True, verbose=False
6+
):
7+
r"""Download spatial data of historically comparable municipalities
8+
9+
This function downloads the shape file of minimum comparable area of
10+
municipalities, known in Portuguese as 'Areas minimas comparaveis (AMCs)'.
11+
The data is available for any combination of census years between 1872-2010.
12+
These data sets are generated based on the Stata code originally developed by
13+
\doi{10.1590/0101-416147182phe}{Philipp Ehrl}, and translated
14+
into `R` by the `geobr` team.
15+
16+
Years available:
17+
1872,1900,1911,1920,1933,1940,1950,1960,1970,1980,1991,2000,2010
18+
19+
Parameters
20+
----------
21+
year : int, optional
22+
Year of the data, by default
23+
simplified: boolean, by default True
24+
Data 'type', indicating whether the function returns the 'original' dataset
25+
with high resolution or a dataset with 'simplified' borders (Default)
26+
verbose : bool, optional
27+
by default False
28+
29+
Returns
30+
-------
31+
gpd.GeoDataFrame
32+
Metadata and geopackage of selected states
33+
34+
Raises
35+
------
36+
Exception
37+
If parameters are not found or not well defined
38+
39+
Example
40+
-------
41+
>>> from geobr import read_comparable_areas
42+
43+
# Read specific state at a given year
44+
>>> df = read_comparable_areas(year=)
45+
"""
46+
47+
years_available = [
48+
1872,
49+
1900,
50+
1911,
51+
1920,
52+
1933,
53+
1940,
54+
1950,
55+
1960,
56+
1970,
57+
1980,
58+
1991,
59+
2000,
60+
2010,
61+
]
62+
63+
if (start_year not in years_available) or (end_year not in years_available):
64+
raise ValueError(
65+
"Invalid `start_year` or `end_year`."
66+
f"It must be one of the following: {years_available}"
67+
)
68+
69+
metadata = select_metadata("amc", year=start_year, simplified=simplified)
70+
71+
metadata = metadata.query(f'download_path.str.contains("{start_year}_{end_year}")')
72+
73+
gdf = download_gpkg(metadata)
74+
75+
return gdf

python-package/geobr/read_health_region.py

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
11
from geobr.utils import select_metadata, download_gpkg
22

33

4-
def read_health_region(year=2013, simplified=True, verbose=False):
5-
""" Download official data of Brazilian health regions as an sf object.
6-
7-
@param year Year of the data (defaults to 2013, latest available)
8-
@param simplified Logic FALSE or TRUE, indicating whether the function returns the
9-
data set with 'original' resolution or a data set with 'simplified' borders (Defaults to TRUE).
10-
For spatial analysis and statistics users should set simplified = FALSE. Borders have been
11-
simplified by removing vertices of borders using st_simplify{sf} preserving topology with a dTolerance of 100.
12-
@param showProgress Logical. Defaults to (TRUE) display progress bar
13-
@param tp Argument deprecated. Please use argument 'simplified
14-
15-
Parameters
16-
----------
17-
year : int, optional
18-
Year of the data, by default 2013
19-
simplified: boolean, by default True
20-
Data 'type', indicating whether the function returns the 'original' dataset
21-
with high resolution or a dataset with 'simplified' borders (Default)
22-
verbose : bool, optional
23-
by default False
24-
25-
Returns
26-
-------
27-
gpd.GeoDataFrame
28-
Metadata and geopackage of selected states
29-
30-
Raises
31-
------
32-
Exception
33-
If parameters are not found or not well defined
34-
35-
Example
36-
-------
37-
>>> from geobr import read_health_region
38-
39-
# Read specific state at a given year
40-
>>> df = read_health_region(year=2013)
4+
def read_health_region(year=2013, macro=False, simplified=True, verbose=False):
5+
"""Download official data of Brazilian health regions as an sf object.
6+
7+
Health regions are used to guide the the regional and state planning of health services.
8+
Macro health regions, in particular, are used to guide the planning of high complexity
9+
health services. These services involve larger economics of scale and are concentrated in
10+
few municipalities because they are generally more technology intensive, costly and face
11+
shortages of specialized professionals. A macro region comprises one or more health regions.
12+
13+
Parameters
14+
----------
15+
year : int, optional
16+
Year of the data, by default 2013
17+
macro: If `False` (default), the function downloads health regions data.
18+
If `True`, the function downloads macro regions data.
19+
simplified: boolean, by default True
20+
Data 'type', indicating whether the function returns the 'original' dataset
21+
with high resolution or a dataset with 'simplified' borders (Default)
22+
verbose : bool, optional
23+
by default False
24+
25+
Returns
26+
-------
27+
gpd.GeoDataFrame
28+
Metadata and geopackage of selected states
29+
30+
Raises
31+
------
32+
Exception
33+
If parameters are not found or not well defined
34+
35+
Example
36+
-------
37+
>>> from geobr import read_health_region
38+
39+
# Read specific state at a given year
40+
>>> df = read_health_region(year=2013)
4141
"""
4242

43-
metadata = select_metadata("health_region", year=year, simplified=simplified)
43+
if macro:
44+
metadata = select_metadata(
45+
"health_region_macro", year=year, simplified=simplified
46+
)
47+
else:
48+
metadata = select_metadata("health_region", year=year, simplified=simplified)
4449

4550
gdf = download_gpkg(metadata)
4651

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from geobr.utils import select_metadata, download_gpkg
2+
3+
4+
def read_intermediate_region(
5+
code_intermadiate="all", year=2019, simplified=True, verbose=False
6+
):
7+
r"""Download spatial data of Brazil's Intermediate Geographic Areas
8+
9+
The intermediate Geographic Areas are part of the geographic division of
10+
Brazil created in 2017 by IBGE. These regions were created to replace the
11+
"Meso Regions" division. Data at scale 1:250,000, using Geodetic reference
12+
system "SIRGAS2000" and CRS(4674)
13+
14+
Parameters
15+
----------
16+
code_intermadiate: str or int, by default "all"
17+
4-digit code of an intermediate region. If the two-digit code or a
18+
two-letter uppercase abbreviation of a state is passed,
19+
(e.g. 33 or "RJ") the function will load all intermediate regions of that
20+
state. If `code_intermediate="all"` (Default), all intermediate regions of
21+
the country are loaded.
22+
year : int, optional
23+
Year of the data, by default 2019
24+
simplified: boolean, by default True
25+
Data 'type', indicating whether the function returns the 'original' dataset
26+
with high resolution or a dataset with 'simplified' borders (Default)
27+
verbose : bool, optional
28+
by default False
29+
30+
Returns
31+
-------
32+
gpd.GeoDataFrame
33+
Metadata and geopackage of selected states
34+
35+
Raises
36+
------
37+
Exception
38+
If parameters are not found or not well defined
39+
40+
Example
41+
-------
42+
>>> from geobr import read_intermediate_region
43+
44+
# Read specific state at a given year
45+
>>> df = read_intermediate_region(year=2019)
46+
"""
47+
48+
metadata = select_metadata("intermediate_regions", year=year, simplified=simplified)
49+
50+
gdf = download_gpkg(metadata)
51+
52+
if code_intermadiate == "all":
53+
return gdf
54+
55+
for col in ["abbrev_state", "code_state", "code_intermediate"]:
56+
if code_intermadiate in gdf[col].unique():
57+
return gdf[gdf[col] == code_intermadiate]
58+
else:
59+
raise ValueError(
60+
f"Invalid value to argumet `code_intermadiate`: {code_intermadiate}"
61+
)

python-package/geobr/read_schools.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from geobr.utils import select_metadata, download_gpkg
2+
3+
4+
def read_schools(year=2020, verbose=False):
5+
r"""Download geolocated data of schools
6+
7+
Data comes from the School Census collected by INEP, the National Institute
8+
for Educational Studies and Research Anisio Teixeira. The date of the last
9+
data update is registered in the database in the column 'date_update'. These
10+
data uses Geodetic reference system "SIRGAS2000" and CRS(4674). The coordinates
11+
of each school if collected by INEP. Periodically the coordinates are revised
12+
with the objective of improving the quality of the data. More information
13+
available at \url{https://www.gov.br/inep/pt-br/acesso-a-informacao/dados-abertos/inep-data/catalogo-de-escolas/}
14+
15+
Parameters
16+
----------
17+
year : int, optional
18+
Year of the data, by default 2020
19+
verbose : bool, optional
20+
by default False
21+
22+
Returns
23+
-------
24+
gpd.GeoDataFrame
25+
Metadata and geopackage of selected states
26+
27+
Raises
28+
------
29+
Exception
30+
If parameters are not found or not well defined
31+
32+
Example
33+
-------
34+
>>> from geobr import read_schools
35+
36+
# Read specific state at a given year
37+
>>> df = read_schools(year=2020)
38+
"""
39+
40+
metadata = select_metadata("schools", year=year, simplified=False)
41+
42+
gdf = download_gpkg(metadata)
43+
44+
return gdf
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
from geobr.utils import select_metadata, download_gpkg
3+
4+
5+
def read_urban_concentrations(year=2015, simplified=True, verbose=False):
6+
r""" Download urban concentration areas in Brazil
7+
8+
@description
9+
This function reads the official data on the urban concentration areas (Areas
10+
de Concentracao de Populacao) of Brazil. Original data were generated by the
11+
Institute of Geography and Statistics (IBGE) For more information about the
12+
methodology, see details at \url{https://www.ibge.gov.br/apps/arranjos_populacionais/2015/pdf/publicacao.pdf}
13+
14+
Parameters
15+
----------
16+
year : int, optional
17+
Year of the data, by default 2015
18+
simplified: boolean, by default True
19+
Data 'type', indicating whether the function returns the 'original' dataset
20+
with high resolution or a dataset with 'simplified' borders (Default)
21+
verbose : bool, optional
22+
by default False
23+
24+
Returns
25+
-------
26+
gpd.GeoDataFrame
27+
Metadata and geopackage of selected states
28+
29+
Raises
30+
------
31+
Exception
32+
If parameters are not found or not well defined
33+
34+
Example
35+
-------
36+
>>> from geobr import read_urban_concentrations
37+
38+
# Read specific state at a given year
39+
>>> df = read_urban_concentrations(year=2015)
40+
"""
41+
42+
metadata = select_metadata('urban_concentrations', year=year, simplified=simplified)
43+
44+
gdf = download_gpkg(metadata)
45+
46+
return gdf

0 commit comments

Comments
 (0)