phelipetls / mapsbr

Get brazilian geospatial data with Python

Home Page:https://mapsbr.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MapsBR: Get brazilian geospatial data with Python

https://img.shields.io/pypi/v/mapsbr.svg https://travis-ci.org/phelipetls/mapsbr.svg?branch=master https://codecov.io/gh/phelipetls/mapsbr/branch/master/graph/badge.svg

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.

Main Features

  • Get and plot maps from IBGE.
  • Get and plot maps from an ArcGIS source.

Documentation

See our documentation at readthedocs.

Example Usage

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"

figs/brazilian_maps.png

License

MIT

Contributing

Please feel free to open an issue or a pull request in case you find any bugs or if you want to contribute. Thanks.

Support

If you like the package, give this repo a star!

About

Get brazilian geospatial data with Python

https://mapsbr.readthedocs.io

License:MIT License


Languages

Language:Python 98.8%Language:Makefile 1.2%