[QGIS-Developer] QGIS standalone script examples

Richard Duivenvoorde rdmailings at duif.net
Mon May 24 05:09:30 PDT 2021


On 5/24/21 1:39 PM, Paul Wittle wrote:

> Thanks for that; it is great to see your script.
> 
> I tried running it with our own project file and the results are the same
> 
> (hence direct message so you can see the screenshot)
> 
> You can see it goes from 1250KB to 593KB and for some reason all the Oracle layers become invalid. I don’t think it is worth worrying so much about that though as that may be just a symptom rather than the cause.
> 
> Out of interest; what path is actually meant to go into the prefix path? Is it meant to point at the installation bin directory or the user profile?
> 
> I wonder if I’m just setting that field incorrectly.

Hi Paul ( bringing it to qgis-dev again :-) ),

The prefix path can be found by running in QGIS in the python console:

QgsApplication.prefixPath()

(from https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/intro.html#using-pyqgis-in-standalone-scripts)

This add's (for your script or for QGIS) the main directory for the application to search for libraries (in my case PREFIX/lib) and/or header files (in my case PREFIX/include). This is actually the install dir.

Thinking about that, for QGIS to be able to load Oracle layers, you have to have Oracle OCI libs installed (you probably have otherwise you would not be able to load Oracle layers in QGIS). But depending on HOW you installed them, maybe your script cannot load the Oracle dll's/lib's? And thus is unable to load them in your script?
In another case I installed the oci libs outside of the QGIS lib dir, and I really had to point to them (on Linux using the LD_LIBRARY path variable and the prefix path). 
Maybe that is indeed the problem?

Another observation is that you are referencing ogr modules in your script. Are you maybe mixing up different ogr-versions/libraries, by mixing the ogr from your QGIS install with an ogr from 'pip install'? Note that the QGIS Oracle-provider is NOT ogr based if I am correct (altough you CAN have an ogr which can open Oracle if compiled against the Oracle libs, to make it more difficult :-) )

So if you leave out the Oracle stuff, (or maybe instead use Postgis as test), it 'just works'?

Regards,

Richard



More information about the QGIS-Developer mailing list