mapsbr is a Python package to help you get brazilian geospatial data from official sources like IBGE or ArcGIS API.
First it downloads a GeoJSON from the web with requests, which gets
parsed by shapely and passed into a geopandas structure, a GeoSeries
or a GeoDataFrame
, which is your typical pandas.DataFrame
but with
magic properties and methods regarding shapely
geometric objects on
top of it.
It’s then, for example, trivial to plot a map or to make a
choropleth map with geopandas
. It does it very well with the help of
descartes and matplotlib. But you can do many other things like
calculate area, get the interesection of two geometries etc.
This package is inspired by the R package geobr.
- Get and plot maps from IBGE.
- Get and plot maps from an ArcGIS source.
See our documentation at readthedocs.
As a simple example, let me demonstrate how one would plot the brazilian map including many sub geographical levels:
from mapsbr import ibgemaps
from matplotlib import pyplot as plt
fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(10, 8), clear=True)
geographic_levels = ["macroregions", "states", "mesoregions", "microregions", "municipalities"]
for level, ax in zip(geographic_levels, axes.flat):
ax.axis("off")
ax.set_title("Brazil map with\n{}".format(level))
ibgemaps.get_map("BR", including=level).plot(color="white", edgecolor="#2c3e50", ax=ax)
for ax in axes.flat:
if not ax.has_data():
fig.delaxes(ax)
fig.tight_layout()
fig.savefig("figs/brazilian_maps.png")
"figs/brazilian_maps.png"
Please feel free to open an issue or a pull request in case you find any bugs or if you want to contribute. Thanks.
If you like the package, give this repo a star!