Clarification on usage with QGIS
Ari Meyer
Note: I originally submitted this as a github issue, as I'd like to see an update to the documentation regarding using Rasterio with QGIS (and perhaps for integrating with any apps that use GDAL). We're looking to simplify our code for a QGIS plugin to use Rasterio/Shapely in place of GDAL/OGR. Shapely is included in the standard QGIS distribution, but Rasterio is not (not sure why). In any case, I found on Does this imply that we may have problems if we try to port the GDAL Python code of our QGIS plugin to Rasterio that we may run into problems, as QGIS is built on GDAL? Can you add a section to rasterio.readthedocs.io clarifying interoperability with QGIS? |
|
Ari Meyer
FYI, Sean Gillies responded on https://github.com/mapbox/rasterio/issues/2096 : I'm certain that until rasterio is included with QGIS, shared library compatibility ("DLL Hell") will be a problem for your plugin. For a compiled program like QGIS, it's fairly simple to make sure that only one instance of a library is loaded, this is the job of the linker. In a Python program, there's no built in way to prevent conflicts when different extension modules cause different instances of the same shared library to be loaded. If I were writing QGIS plugins, I would try to stick to using https://qgis.org/pyqgis/master/. |
|
Ari Meyer
Looking through the older messages, it seems like integration with QGIS, in particular, is a common enough use case that it really should be discussed separately in the docs. I will be making a request to the QGIS team that Rasterio be included in the core distribution. A couple questions for the group:
1) Does anyone have experience writing QGIS plugins using Rasterio? If so, did you run into any problems, particularly those related to issue I pointed to above? 2) Is there a technical reason why Shapely was included in QGIS but Rasterio was not? Thanks, Ari |
|
Ratcliff, Christina (A&F, Waite Campus)
I've successfully developed the PAT plugin for QGIS using rasterio, geopandas (uses fiona, shapely). All of these libraries are available in the osgeo4w installer through the advanced install. You will also have to ensure the correct GDAL dll is also installed for the version of rasterio you are using.
My method was to create a windows bat file containing the relevant installation which then can be run as administrator to install the libraries. This will use a command line install of rasterio, geopandas and GDAL dll via OSGeo4W. Have a look at the following osgeo4w and QGIS tickets for answers to some of the issues I came across. For some older versions of QGIS see Installing Fiona, Geopandas or rasterio using OSGeo4W breaks QGIS python
I hope this helps. Christina |
|
Ari Meyer
That's exactly what I hoped to hear, Christina -- thank you so much!
One question: are there any other libraries commonly used in the QGIS space that depend upon a particular version of GDAL? I'm hoping I won't be facing any version conflicts with this setup. Ari |
|
Ratcliff, Christina (A&F, Waite Campus)
Ari, I've been running the Geopandas (pandas, shapely fiona), RasterIO configuration since early 2019, and as long as you have access to those gdal backwards compatibility dll's you should be fine.
With libraries depending on GDAL, where possible use those available in osgeo4w. Osgeo4w will then properly install and get them talking to both GDAL and QGIS. Good luck. |
|
Ari Meyer
Much appreciated, Christina. Will try this out.
Cheers! Ari |
|
Ari Meyer
Hi Christina, FYI, I just installed QGIS 3.18.1 and added rasterio. Here's the relevant snippet of the installer output: gdal (3.1.4-3) The GDAL/OGR library and commandline tools Required by: grass, python3-rasterio, gpsbabel, python3-gdal, python3-fiona, qgis-common gdal111dll (1.11.3-1) The GDAL/OGR 1.11 DLL (backward compability package) Required by: liblas gdal204dll (2.4.3-1) The GDAL/OGR 2.4 DLL (backward compability package) Required by: saga-ltr ... liblas (1.8.0-1) The libLAS commandline utilities Required by: grass So it appears that QGIS actually installed 3 versions of GDAL based on the requirements we have (including GRASS and SAGA). Do you think this could be an issue? So far we haven't seen any actual problems because of this. Thanks, Ari Much appreciated, Christina. Will try this out. |
|
Ratcliff, Christina (A&F, Waite Campus)
Hi Ari,
Yes, I've also confirmed my plugin & rasterio runs in QGIS 3.18 without any problems. I have similar GDAL & GDAL backwards compatibility packages installed and haven't experienced issues with QGIS so it should be fine. I'm not a big user of Grass or SAGA, so can't comment on them. Christina |
|
Ari Meyer
That's good to hear, Christina -- thanks! Ari On Thu, Mar 25, 2021 at 6:59 PM Ratcliff, Christina (A&F, Waite Campus) <christina.ratcliff@...> wrote: Hi Ari, |
|