ipeaGIT / geobr

Easy access to official spatial data sets of Brazil in R and Python
https://ipeagit.github.io/geobr/
794 stars 119 forks source link

create QGIS Plugin #251

Open rafapereirabr opened 3 years ago

pedro-andrade-inpe commented 3 years ago

Maybe it would be interesting to make the data available as Web Feature Services (WFS).

JoaoCarabetta commented 3 years ago

Web Features Services seems to be the right tool to make geobr data available.

A tutorial on how it works: https://docs.qgis.org/2.18/en/docs/training_manual/online_resources/wfs.html

I couldn't find a tutorial, though. Does anyone know how to build it?

rafapereirabr commented 3 years ago

I'm not familiar with Web Feature Services (WFS). What is the advanted of WFS instead of the plugin download the geopackage files into QGIS?

pedro-andrade-inpe commented 3 years ago

You do not need to develop a graphical interface, as the user will need only to configure how to access the data through the available funcionalities of QGIS. Additionally, the data will be available to any tool that can read this standard. The disadvantage is that you need a server to provide the data. Tipically we use Geoserver.

sandrofsousa commented 3 years ago

This might be a stupid comment from a newbie on the package, so please feel free to educate me. Perhaps we should step back a bit and define which problem exactly the plugin would solve on QGIS? I'd say the typical QGIS user would download the data, merge it with a shapefile and move on with his/her spatial analysis. In the Segreg plugin that I developed, the data is stored locally as a table of features that can be saved with the shapefile and reused later. Do you all have in mind cases where this data would be consumed without a shapefile? This contextualisation might also help others to hop in and contribute.

rafapereirabr commented 3 years ago

Hi @sandrofsousa . Thanks for chipping in. The aim of geobr is to help users easily and efficiently download official spatial data sets of Brazil. Currently, each data set is stored as a geopackage file at our server in Ipea. The Python and R packages basically download those geopackge files from the server given parameters of geography, year, etc etc. We currenly have over 3200 data files summing aprox. 16GB. This means that storaing the data set locally or withing the plugin / r/python pacakges is not an option.

The idea I have in mind for the QGIS plugin would be a simple interface to the Python package. So the user would select a few parameters (basically the same parameters used in the functions of the Python package), and the pluging would download the geopackage data and read it to memory.

sandrofsousa commented 3 years ago

Oh I see @rafapereirabr, thanks for clarifying. In fact your idea is exactly what I tough, but I failed to articulate it. By downloading I meant only the required data, not the full dataset. The idea proposed by @pedro-andrade-inpe and @JoaoCarabetta seems to be the way, I'll look into it.

JoaoCarabetta commented 3 years ago

As far as I understood, we have three options:

1. Integrate to QGIS through WFS by creating a geoserver.

Advantages:

Drawbacks:

2. Integrate to QGIS through WFS by creating a Flask server on top of Python geobr

Advantages:

Drawbacks:

3. Integrate to QGIS through Plugin

Advantages:

Drawbacks:

rafapereirabr commented 3 years ago

An important thing to note regarding data filters. When the user runs :

m <- geobr::read_municipality(code_muni = 4106902 )

the behavior of geobr is to first download one geopackage of all municipalities in the state 41, and only then filter the data to keep the observations where code_muni = 4106902. This means that geobr filters the data set locally. I wanted to clarify this point because it might affect what route we take from here give the 3 options listed by @JoaoCarabetta above.

Not being familiar with WFS nor Flask servers, I would prefer to stick with option 3. Do you guys know any other QGIS plugins that download data that I could have look at?

sandrofsousa commented 3 years ago

With option 3, the following plugins do something similar. They simply provide an interface that allows to navigate the dataset and select which table is needed, then, the data is saved as a QGIS virtual layer. istacqgis cbers4a

Developing the plugin interface is not a big issue, it's done using Qt I can help with that. I had a few breaking points when I updated my plugin from QGIS 2 to 3, besides that it is quite stable.

JoaoCarabetta commented 3 years ago

I also think that option 3 might be the easiest to implement and maintain.

@sandrofsousa do you mind building a POC that calls a geobr API, maybe read_country, so that we can start developing from there?

If you can, open a PR and add the plugin on a folder called qgis_plugin.

sandrofsousa commented 3 years ago

I will work on that @JoaoCarabetta and open a PR when I get a minimal example working, it might take a while though :)

JoaoCarabetta commented 2 years ago

@sandrofsousa did you manage to work on it?