[QGIS-Developer] QGIS standalone script examples
Paul Wittle
paul.wittle at dorsetcouncil.gov.uk
Mon May 24 05:54:11 PDT 2021
Hi,
So I've now run another test using your script with literally just the read then save commands and the result is the same so I think we can pretty much ignore anything related to adding the layer as it is more a case of it just losing lots of the project file on save...which is odd...but as you say perhaps it is an Oracle issue.
Unfortunately I can't simply exclude Oracle as that is currently our spatial database provider and whilst we are migrating to PostgresSQL that will be a while so I do need a solution that leaves those layers alone really.
I've run the function you suggest and the prefix path should be:
QgsApplication.setPrefixPath('C:/programs/QGIS_3/apps/qgis', True)
So that is <%install_dir%/apps/qgis> if anyone else is trying to work out where that would be.
I didn't have that set correctly...but I do now... and it still has the same result.
I will investigate the Oracle side a bit more to see if that is the issue but I should point out that python is not generally available (banned by our security policy) so the script is run using the same method as the Windows batch files which open the application. It is possible that the batch file mounts things in all sorts of places so perhaps you are right and it can't find the Oracle libraries.
The batch commands I'm referring to include o4w_env.bat, qt5_env.bat and py3_env.bat which I believe are default with the install so hopefully you can see them.
That said, I would have expected a script that simply says Open > Save with no changes would not save anything but the changes so standalone scripts don't seem particularly safe to use. On the flip side; the documentation doesn't really say they are particularly safe so that is not really a complaint so much as an observation that the write command is basically a rewrite of the project file even if you don't change anything at all.
My joys of being stuck with Windows and Oracle continue...I will continue to try and work it out.
Thanks again for your help,
Paul
-----Original Message-----
From: Richard Duivenvoorde <rdmailings at duif.net>
Sent: 24 May 2021 13:10
To: Paul Wittle <paul.wittle at dorsetcouncil.gov.uk>
Cc: qgis-dev <Qgis-developer at lists.osgeo.org>
Subject: Re: [QGIS-Developer] QGIS standalone script examples
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
This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed. It may contain unclassified but sensitive or protectively marked material and should be handled accordingly. Unless you are the named addressee (or authorised to receive it for the addressee) you may not copy or use it, or disclose it to anyone else. If you have received this transmission in error please notify the sender immediately. All traffic may be subject to recording and/or monitoring in accordance with relevant legislation. Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of Dorset Council. Dorset Council does not accept service of documents by fax or other electronic means. Virus checking: Whilst all reasonable steps have been taken to ensure that this electronic communication and its attachments whether encoded, encrypted or otherwise supplied are free from computer viruses, Dorset Council accepts no liability in respect of any loss, cost, damage or expense suffered as a result of accessing this message or any of its attachments. For information on how Dorset Council processes your information, please see www.dorsetcouncil.gov.uk/data-protection
More information about the QGIS-Developer
mailing list