Saturday, 28 March 2020

QGIS on Ubuntu 18.04

QGIS didn't work for me out of the box. Here's notes on what I had to do to get it going. Brief summary, out of the box the Open Street Map URL is missing. See 'Breakthrough' below for how to fix this. However, also, the version of qgis available from the Ubuntu package repository is at present quite out of date; alternative repositories are available but as yet I haven't tried them.

Firstly, if it isn't working and you've been tinkering to try to get it working, start by purging it completely:

sudo dpkg --purge qgis qgis-provider-grass qgis-plugin-grass
rm -rf ~/.qgis2/

Then reinstall it with all the extra bits that it actually needs - when I originally installed it, it did not automatically install saga, and I'm not sure whether it automatically installed the grass plugin.

sudo apt install python-qgis qgis-plugin-grass saga

This at the time of writing installs QGIS version 2.18.17.




Then start QGIS

qgis

QGIS, immediately on starting.
At this point the application window renders. I get one python warning in the 'Log Messages Panel':
2020-03-28T08:08:03 1 warning:/usr/lib/python2.7/dist-packages/qgis/utils.py:258: DeprecationWarning: This method will be removed in future versions. Use 'parser.read_file()' instead.
cp.readfp(f)

Because it's only a deprecation warning, I'm inclined to think this is not a significant issue.

I also get the following warnings in the console. Once again, they're only warnings:

Warning: loading of qgis translation failed [/usr/share/qgis/i18n//qgis_en_GB]
Warning: loading of qt translation failed [/usr/share/qt4/translations/qt_en_GB]
Warning: Object::connect: No such signal QgsMergedBookmarksTableModel::&QgsMergedBookmarksTableModel::selectItem( const QModelIndex &index )
Warning: Object::connect: (receiver name: 'QgsBookmarksBase')
Warning: QCss::Parser - Failed to load file "/style.qss"
QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed: No such file or directory
Warning: QFileSystemWatcher: failed to add paths: /home/simon/.qgis2//project_templates
Warning: QLayout: Attempting to add QLayout "" to QgsPanelWidgetStack "mWidgetStack", which already has a layout

I select, from the menus, Project -> New; the 'Recent Projects' heading disappears from the main pane, and it appears to be a map pane - but there's no map.

I type 'world' into the 'Coordinate' input and hit return, as directed by this tutorial, and still, no map. Comparing my screen to the screen shown in the tutorial, they are identical except that 
  1. No map is displayed, and
  2. Some icons in the second toolbar from the top which are coloured in the tutorial are greyed on my screen.
I take this to mean that not only can I not see the map, QGIS doesn't think there is a map from which I can make selections.

If I try to drag the 'osmraster' item from the 'Browser Panel' into the map area, I get a series of errors in the 'Log Messages Panel' of the general form:
2020-03-28T08:37:53 1 Tile request max retry error. Failed 3 requests for tile 11 of tileRequest 2 (url: https:/2/2/2.png)

Clearly, the URL is malformed. Clearly, there is something wrong with the template string from which the URL is being formed.

At this point I tried using the 'Getting Started' instructions from the manual. Once I had downloaded the sample data, I was able, following instructions, to get raster data to show on the map pane. Vector data, however, for example from the 'lakes.gml' file in the sample data, still did not render at all.

This made me suspicious of the error seen earlier in the console,

Warning: QCss::Parser - Failed to load file "/style.qss"

If the default style is white on white, then perhaps QGIS has been rendering a map, but rendering it invisibly. I find that there are indeed two files with this name in my file system:

simon@mason:~/qgis$ locate style.qss
/home/simon/.qgis2/themes/Night Mapping/style.qss
/home/simon/simon/.qgis2/themes/Night Mapping/style.qss
/usr/share/qgis/resources/themes/Night Mapping/style.qss

However, I can't find any way of selecting a stylesheet in any of the menus (there's a 'Style Manager' dialogue, available from the 'Project Properties' dialogue and from the 'Settings' menu, but it does not mention stylesheets and does not appear to allow you to set one. There's no reference to 'style.qss' in any file in my .qgis2 directory; nor is there any reference to it, or to a stylesheet at all, in a saved project file.

I experimentally copied one of these style.qss files into the root directory of my filesystem, and restarted QGIS. This time, the file was found, but its only effect was to render many dialogues unreadable; it did not change the blankness of the default map panel. Further browsing showed that a QSS stylesheet is a stylesheet used by the Qt tookit (which QGIS is built on), not used by QGIS itself, and, as the default styles render QGIS perfectly acceptably, this file is not needed and is not the problem.

At this point I noticed what looked like specks of dirt on the screen. I zoomed in and found a group of vector shapes which could well be lakes - but they didn't AT ALL align with the sample raster data. I checked the coordinate systems used and found that they were different. I changed the coordinate system for the lakes data to that used for the raster data, and they overlaid precisely. Progress!

The breakthrough

So I went back to trying to find why the Open Street Map data was not loading. I right clicked on 'Tile Server (XYZ)' in the 'Browser Panel' and got a dialogue asking for a URL. I entered 'https://c.tile.openstreetmap.org/{z}/{x}/{y}.png', chosen from an existing leaflet project, and was shown another dialogue asking for a name for the layer. I entered 'TestOSM'.

A 'TestOSM' entry appeared in the 'Browser Panel', and when I dragged this to the map pane, suddenly I had a map.

Epilogue

 
My takeaway from this catalogue of problems is that the QGIS package offered by Ubuntu is 
  1. Misconfigured, and
  2. Obsolete
I did get it working, and I've documented what I needed to do above; but it's clearly some way behind the current 'stable release', which is 3.10.4.

So I've spent a whole morning trying to install a more up-to-date version of QGIS. There are many repositories for more recent versions of QGIS out there on the Web, and many 'howto' articles explaining how to set them up and use them. I've tried many this morning, and my conclusion is that they're all, without exception, broken in one way or another. Some people do seem to have succeeded in getting a working install, but even their notes don't work. 
Furthermore, after doing that, it took an awful lot of work to sort out the mess and get back to a working 2.18.7. In summary, I believe it can be done, but it's not for the faint hearted.