qgis / qwc2-demo-app

QWC2 demo application
Other
241 stars 154 forks source link

Don't try to parse .qgz but warn the user instead #466

Closed kannes closed 1 year ago

kannes commented 1 year ago

Using modern QGIS one is used to projects being saved as .qgz files. QWC2 only supports .qgs though.

This is not obvious and it seems like the code triggered by the "Generate service configuration" button does discover the project file anyways and tries to parse it, leading to cryptic errors.

It would be nice to not try to parse the .qgz file as a .qgs (I assume this is what happens?) but show a helpful message to the user instead, prompting them to store the project as .qgs instead.

I was utterly confused for a while and at least one other user (https://github.com/qgis/qwc2-demo-app/issues/436#issuecomment-1490139407) was stuck because of this as well recently.

Example:

manisandro commented 1 year ago

Actually no, it does not try to parse the qgz, but it fails because it cannot find the a <mapname>.qgs file.

Whether qgs or qgz is searched is ultimately controlled by the rewrite rule here [1].

[1] https://github.com/qwc-services/qwc-qgis-server/blob/main/qgis3-server.conf.template#L16

kannes commented 1 year ago

But why does it even try to find <mapname>.qgs when there is a <mapname>.qgz in the directory? It does not seem to consider any file to be a QGIS project file, e.g. it won't try to search for foobar.qgs if I have a file named foobar there.

manisandro commented 1 year ago

This is controlled by the mentioned rewrite rule https://github.com/qwc-services/qwc-qgis-server/blob/main/qgis3-server.conf.template#L16, you can change the rule to map to a qgz file instead if you prefer.

kannes commented 1 year ago

Hm, I don't understand what a rewrite rule of QGIS server has to do with the scan dir at this initial stage? Probably I am missing some basic information or misunderstanding how things work? :D

manisandro commented 1 year ago

The config generator will query the service capabilities via

https://qwc-qgis-server/ows/mapname

The rewrite rule in the qgis server config will specify that /ows/mapname actually maps to

/cgi-bin/qgis_mapserv.fcgi?map=/data/<mapname>.qgs 

i.e. properly "redirects" the request to the actual qgis server executable with specifying the project file to read.

kannes commented 1 year ago

Thanks! But can't we stop it from trying https://qwc-qgis-server/ows/<mapname> if it is not a <mapname>.qgs file but a <mapname>.qgz?

manisandro commented 1 year ago

Again, qwc-config-generator needs to read the project capabilities and will invoke the qgis server to retreive those. Whether a qgs or qgz file is attempted to be read depends on the rewrite rule.

Closing as this is not a bug.

kannes commented 1 year ago

Ah, I did not know that the config generation would query the QGIS server and that the directory is something where QGIS server looks for project files. To me it sounded like QWC2 itself would scan the directory. Is that documented somewhere? I was following https://qwc-services.github.io/QuickStart/ and https://qwc-services.github.io/configuration/ThemesConfiguration/

Is there a reason to have only .qgs tried by default or would a pull request to try both be welcome? That would fix the confusion issue me and the other user had.

manisandro commented 1 year ago

Unfortunately the rewrite rule is just a path mapping, i.e. it is not that it "tries" one path or the other, it just transforms the query as specified and passes it on. You could add a rewrite rule like

RewriteRule ^${URL_PREFIX}/z/(.*)$ /cgi-bin/qgis_mapserv.fcgi?map=/data/$1.qgz [QSA,PT]

which would then map any requests to /ows/z/projectname to a projectname.qgz file. Or you could just change the default rewrite rule to always rewrite to qgz if you prefer the qgz file format.