1

I am using OS Translator to convert .gz OSMasterMap files to .SHP files for use in QGIS. I am now trying to add QGIS .QML files to add the styling within QGIS, I have followed the instructions in the Getting Started Guide (https://github.com/OrdnanceSurvey/OSMM-Topography-Layer-stylesheets/blob/master/Getting%20Started%20Guide%20-%20Styling%20OSMM%20Topography%20Layer.pdf) however when I add the layers using the .QML file the layer becomes greyed out and the features disappear (below).

enter image description here

I am using the Schema 9 stylesheets from https://github.com/OrdnanceSurvey/OSMM-Topography-Layer-stylesheets.

Does anyone know the reason for this issue or what I may have done wrong?

EDIT

enter image description here

  • 1
    zoom in and it will become visible (around 1:1200 I think) – Ian Turton Feb 12 '18 at 14:03
  • Hi Ian, thanks for the help, but it still doesn't show at 1:1200 - imgur.com/a/1mnX1 – sm29 Feb 12 '18 at 16:31
  • 1
    did you use schema 9 data files? check what the style is looking for and make sure it matches the attribute names (and case) of your data. – Ian Turton Feb 12 '18 at 16:33
  • I have tried both schema 7 and 9. I have been sent this data from somebody else - this is what it looks like prior to attempting to load the styles imgur.com/a/wvB77. Here is the attribute table of the TopographicArea file, it seems to match the styling, e.g it inclues Track, Coniferous Tree etc. imgur.com/a/8pqCi – sm29 Feb 13 '18 at 11:08
2

The QML files are based on an attribute called categorizedSymbol from the picture of the attributes you provide it seems you do not have this column. For some reason, OS do not apply the styling transform before shipping the data so you need to go back to your supplier and ask them to do it for you.

  • Thanks Ian I will ask my colleague to apply the styling. – sm29 Feb 13 '18 at 11:50
1

So I've had this problem with MasterMap for some time and have only just hit on a couple of solutions over the last few weeks. Apologies for the long-winded reply, but it is going to take a bit of time to explain the solution.

The QML stylesheets expect an attribute column called style_code, but the OS do not supply this column with their data, you have to add it and populate it yourself, presumably to enable you to apply different styles as you see fit. The OS do supply some code to speed things up, but it needs a bit of explaining.

NB my solution is based on using QGIS 2.8 32bit on a Windows 10 machine.

Taking the OS TopographicArea layer as our example, first check that all OS symbols and fonts have been installed in the correct folders, as per OS instructions. Then check that you have an attribute table with the following three columns in your table: descriptiveterm, descriptivegroup, and make. There should be no column called style-code.

If you downloaded the files as GML from an OS supplier then the long column names should be intact. If you were supplied them as shapefiles, then the column names may have been altered or truncated (.shp column headers are limited to 10 characters). You need to make a note of the new column names and establish which equals which. In my case descriptiveterm was truncated to descript_1 and descriptivegroup to descriptiv. The descriptiveterm column will have values like Multi Surface, while the descriptivegroup column will have values like Building, or General Surface.

If your file came as a shapefile, at this point you should make a backup.

Now for the coding. Locate the file topographicarea_createtable_string.sql which should be in the folder OSMM-Topography-Layer-stylesheets-master\Schema version 9\SQL\PostGIS\String. Open it with Word Pad (not Note Pad) and save as a new file. I have yet to find a way to run the whole SQL file in QGIS, but we can copy and paste the contents after a bit of editing.

If your MM file came as GML and your column names are intact you need do very little editing. If the column names have been truncated or altered use 'Find and Replace' to change all the affected column names in the code.

Since my attributes are presented in an unusual array formula, e.g. (1:General Surface), it is helpful to replace the = symbol with the ~ 'contains' symbol.

Back in QGIS, if the TopographicArea layer is a shapefile, open it for editing. Open the properties dialogue for the layer and navigate to the fields tab. Click the Field Calculator button, which brings up a new dialogue box. If your file is a shapefile enabled for editing check Create New Field. If it is GML, then you can only create a virtual field that may be lost at the end of the session :( , so remember to save as a new file at the end of the procedure. The output field name MUST be style_code, the type a whole number (integer) and the width at least 3.

Now copy and paste all the code from the section that starts: --Built Environment Descriptive Term Rules to the line ELSE 99, into the Expression box. Create a new line at the base of the code and type END. At this point there should be no errors in the code. If there are you need to go hunt them out before you can apply it. When sorted, hit OK. When it has run, save everything.

Now, check the attributes of the file. There should be a new column called style_code populated with the various style code numbers. If there are too many 99s in the column go back to the code and check where the breakdown may have occurred (did you leave an = instead of ~?), then re-run the code.

Apply the OS QML stylesheet and the fills should now be visible, if your viewing scale is between 1:4,000 and 1:1 (adjust viewing scale in the Layer Properties, General tab).

If your shapefile was in edit mode, save it, then save QGIS. If your file is GML, save it as a new file and make sure the calculated field has copied over as a new permanent field, before ending this QGIS session. Otherwise you risk loosing your new style_code column.

I said there were two ways. The second method is to apply the style to the layer first, then switch from categorised style to rule-based style. Then for each style find the appropriate line of code in the SQL file, then copy/edit the relevant portion into the expression builder, e.g. descriptiveterm ~ 'Multi Surface'. This is laborious. When complete, save the style as a new QML style than can be applied to other files, bearing in mind that column names may have been altered etc.

These methods seem to work for all except the CartogrpahicText layer, which I have yet to crack fully (I have my own workaround stylesheet for now).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.