SICAR

Posted on Feb 2, 2022

“In God we trust, all others bring data.” - W. Edwards Deming


This tool is designed for students, researchers, data scientists or anyone who would like to have access to SICAR files.

What is SICAR?

“The National Rural Environmental Registry System - SICAR was created through Decree No. 7.830/2012 and defined as an electronic system of the national scope intended for the integration and management of environmental information of rural properties throughout the country. This information is intended to support policies, programs, projects, and activities for control, monitoring, environmental and economic planning, and combating illegal deforestation.” Sistema Nacional de Cadastro Ambiental Rural - SICAR

Why SICAR package?

Currently, to access the SICAR files, it is necessary to download the data for each city in Brazil one at a time. Brazil is a large country with 26 states and a federal district, and a total number of, 5570 cities. In addition to the insane number of cities to download manually, it is necessary to pass a captcha to access the data. This is a huge waste of time and resources.

That’s why I decided to create a package to download the files in an attempt to save our precious time that can be used for tasks that matter. This tool is a Python package that provides a mechanism to bypass captchas and helper methods for convenience. You can download a specific city or a custom list of cities, all cities in a state or the entire country.

Package

The source code is available on github.com/urbanogilson/SICAR.

Installation

Install SICAR with pip

pip install git+https://github.com/urbanogilson/SICAR

Usage/Examples

from SICAR import Sicar
import pprint

# Create Sicar instance
car = Sicar(email = "name@domain.com")

# Get cities codes in Roraima state
cities_codes = car.get_cities_codes(state='RR')

pprint.pprint(cities_codes)
# {'Alto Alegre': '1400050',
#  'Amajari': '1400027',
#  'Boa Vista': '1400100',
#  'Bonfim': '1400159',
#  'Cantá': '1400175',
#  'Caracaraí': '1400209',
#  'Caroebe': '1400233',
#  'Iracema': '1400282',
#  'Mucajaí': '1400308',
#  'Normandia': '1400407',
#  'Pacaraima': '1400456',
#  'Rorainópolis': '1400472',
#  'São João da Baliza': '1400506',
#  'São Luiz': '1400605',
#  'Uiramutã': '1400704'}

# Download 'Alto Alegre': '1400050'
car.download_city_code('1400050', folder='Roraima')

# Download specific cities
cities_codes = {
    'São Gabriel da Cachoeira': '1303809',
    'São Paulo de Olivença': '1303908'
}

car.download_cities(cities_codes=cities_codes, folder='cities')

# Download all cities in Roraima state
car.download_state(state='RR', folder='RR')

Run with Google Colab

Using Google Colab, you don’t need to install the dependencies on your computer and you can save files directly to your Google Drive.

Open In Collab

In the colab example you can find more examples of usage.

Run with Docker

Update the entry point file ./examples/docker.py to download data based on your needs.

Generate docker image

# using the docker build script
./docker-build.sh

Run to download all data defined in the ./examples/docker.py entry point to an external directory.

Make an external directory to store the downloaded data, /my/local/data/dir, and use a volume parameter in the run command to point to it.

# run the docker image in detached mode
docker run -d --rm -v /my/local/data/dir:/data softwarevale/download-sicar:v0.1

References

1 - Sicar - Sistema Nacional de Cadastro Ambiental Rural [PT-BR]

2 - Sicar - Base de Downloads [PT-BR]