0

In an answer to a question asked by @Canningmister, @tjmgis posted an excellent answer Styling OS Vectormap Local in QGIS? about making OS SLD files work in QGIS.
As an amateur user who uses QGIS to produce maps for my Parish Council I have struggled with styles for OS data in QGIS.
I can see how to edit the sld files using a text editor such as TextPad which I assume will work with Mastermap area and line layers but I am confused with making the text layer SLD work and have several questions:

  1. Are the layers imported into QGIS from ESRI shapefiles or directly from gml?
  2. How do you post process the text layer data to add extra columns without having the data in a database and if so which one?

I am familiar with executing SQL scripts in a database. Am I missing something - I can't get my head round this.

user23808
  • 25
  • 7
  • I tried editing the Topo Area SLD which QGIS now reads and displays 21 rules. Nothing displays even if I change the scale so I assume there is a mismatch with the rules which seem to use os_cat which is not in the attribute table and should not the rules be based on the featureCode? I'm stuck. – user23808 Nov 09 '13 at 14:57

2 Answers2

3

Styling OS MasterMap can be done in a number of different ways.

Option 1 - use the current feature code column which only has hundred or so style rules.

Option 2 - or style based on four key attributes - descriptive group, descriptive term, physical presence and make there are almost 4000 permutations.

It is also dependent on what translator or loader you have used to translate your data. Some create their own style column.

So for our web services we wrote some code that creates a new style column, os_cat, that is populated based on the Option 2. But have just one attribute to style off which is significantly easier to create a style sheet for and it's more performant.

When you download the SLD zip there should be a couple of text files that contain the SQL code to create that new os_cat column? internally we use the Astun Technology loader so the code matches what the data is after it has been loaded into a PostGIS database.

I see you saw my answer regarding the OS VectorMap Local SLD use - Styling OS Vectormap Local in QGIS?

So you have a few choices

1) Load OS MasterMap into a database, then use the SQL files to create the new style column and then use amended SLD files where you have removed the featuretypestyle

You can find the SQL I use here

https://gist.github.com/tjmgis/6184358

There are lots of different databases that you could use and a number of loaders for both open source and proprietary setups.

(On my iPad so struggling to copy and paste all of the content from the gist to here so maybe a mod could edit)

2) Translate the OS MasterMap GML files to ESRI Shapefiles, manually create a new os_cat column and populate it using the field calculator which seems to support writing CASE statements - Elseif Conditional Statement in QGIS Field Calculator

Again there are open source options and proprietary.

Hope this helps

Tim

The following is a guide for post processing OSMM Cartographic Text so that it can be rendered within QGIS.

Firstly, we need to create a new anchor column which tells QGIS which position to locate the text.

ALTER TABLE osmm.cartographictext ADD COLUMN anchor VARCHAR;
COMMIT;

update osmm.cartographictext set anchor = 'Below Left' where anchorposition = 0;
update osmm.cartographictext set anchor = 'Left' where anchorposition = 1;
update osmm.cartographictext set anchor = 'Above Left' where anchorposition = 2;
update osmm.cartographictext set anchor = 'Below' where anchorposition = 3;
update osmm.cartographictext set anchor = 'Over' where anchorposition = 4;
update osmm.cartographictext set anchor = 'Above' where anchorposition = 5;
update osmm.cartographictext set anchor = 'Below Right' where anchorposition = 6;
update osmm.cartographictext set anchor = 'Right' where anchorposition = 7;
update osmm.cartographictext set anchor = 'Above Right' where anchorposition = 8;
COMMIT;

ALTER TABLE osmm.cartographictext ADD COLUMN vertical VARCHAR;
COMMIT;
ALTER TABLE osmm.cartographictext ADD COLUMN horizontal VARCHAR;
COMMIT;

update osmm.cartographictext set vertical = 'Bottom' where anchorposition = 0;
update osmm.cartographictext set horizontal = 'Left' where anchorposition = 0;

update osmm.cartographictext set vertical = 'Half' where anchorposition = 1;
update osmm.cartographictext set horizontal = 'Left' where anchorposition = 1;

update osmm.cartographictext set vertical = 'Top' where anchorposition = 2;
update osmm.cartographictext set horizontal = 'Left' where anchorposition = 2;

update osmm.cartographictext set vertical = 'Bottom' where anchorposition = 3;
update osmm.cartographictext set horizontal = 'Center' where anchorposition = 3;

update osmm.cartographictext set vertical = 'Half' where anchorposition = 4;
update osmm.cartographictext set horizontal = 'Center' where anchorposition = 4;

update osmm.cartographictext set vertical = 'Top' where anchorposition = 5;
update osmm.cartographictext set horizontal = 'Center' where anchorposition = 5;

update osmm.cartographictext set vertical = 'Bottom' where anchorposition = 6;
update osmm.cartographictext set horizontal = 'Right' where anchorposition = 6;

update osmm.cartographictext set vertical = 'Half' where anchorposition = 7;
update osmm.cartographictext set horizontal = 'Right' where anchorposition = 7;

update osmm.cartographictext set vertical = 'Top' where anchorposition = 8;
update osmm.cartographictext set horizontal = 'Right' where anchorposition = 8;
COMMIT;

Next we need to add a new column to tell QGIS what colour the text should be.

ALTER TABLE osmm.cartographictext ADD COLUMN fontcolour VARCHAR;
COMMIT;

update osmm.cartographictext set fontcolour = '#000000';
COMMIT;
update osmm.cartographictext set fontcolour = '#0099FF' where descriptivegroup = '{"Inland Water"}';
update osmm.cartographictext set fontcolour = '#0099FF' where descriptivegroup = '{"Tidal Water"}';
update osmm.cartographictext set fontcolour = '#FF00FF' where descriptivegroup = '{"Political Or Administrative"}';
COMMIT;

Next we add a new column for the font family name, this is based on the attribute 'font' already within the data.

ALTER TABLE osmm.cartographictext ADD COLUMN fontname VARCHAR;
COMMIT;

update osmm.cartographictext set fontname = 'Times New Roman' where font = 0;
update osmm.cartographictext set fontname = 'Arial' where font = 1;
update osmm.cartographictext set fontname = 'Arial' where font = 2;
COMMIT;

ALTER TABLE osmm.cartographictext ADD COLUMN orientationdegrees VARCHAR;
COMMIT;

update osmm.cartographictext set orientationdegrees = (orientation/10);
COMMIT;

Also need X Y coordinates so we can use the anchor position

ALTER TABLE osmm.cartographictext ADD COLUMN x_coordinate NUMERIC;
COMMIT;
update osmm.cartographictext set x_coordinate = ST_X(wkb_geometry);
COMMIT;

ALTER TABLE osmm.cartographictext ADD COLUMN y_coordinate NUMERIC;
COMMIT;
update osmm.cartographictext set y_coordinate = ST_Y(wkb_geometry);
COMMIT;

After post processing the data can now be rendered in QGIS using the data drive styling functions.

tjmgis
  • 3,330
  • 1
  • 23
  • 37
  • Any views on the the best open source database and loader which will run under Windows to transfer OS Mastermap data to QGIS. I did try MS SQL server sometime ago and gave up because of difficulties. I would like to try a find an easy solution to this to make it easier for other Parish Councils to be able to make maps by producing a simple 'How To' guide – user23808 Nov 10 '13 at 16:01
  • Having searched the net I am going to try PostgreSQL with PostGIS and then the Astun Technology loader – user23808 Nov 11 '13 at 07:50
  • @user23808 we use PostGIS and the Astun Loader internally as do lots of Councils so that is a good place to start. If any of the answers were useful remember to accpect one of them – tjmgis Nov 11 '13 at 10:41
  • I have installed PostgreSQL with PostGIS and OSGeo4W following the instructions on the Astun Loader site. However when I try to install lxml I am getting errors. Any suggestions? – user23808 Nov 11 '13 at 15:04
  • Sorry previous comment timed out I am executing easy_install lxml==2.3 under the OSGeo4W shell ERROR: b"'xslt-config' is not recognised as an internal or external command make sure the development packages of libxm12 and libxslt are installed

    error: Unable to find vcvarsall.bat

    – user23808 Nov 11 '13 at 15:16
  • Pardon my ignorance but what is accpect and how do you do it. – user23808 Nov 11 '13 at 15:20
  • Doh - just realised this is accept and I can see what to do – user23808 Nov 11 '13 at 16:36
  • Having got completely stuck trying to execute easy install before installing the astun technology loader I am going to ask a new question on this topic – user23808 Nov 12 '13 at 14:28
  • I have added an answer to your other question which I hope helps – tjmgis Nov 12 '13 at 20:49
  • Having succeeded in using PostGis http://gis.stackexchange.com/questions/77221/problems-installing-the-astun-technology-loader-in-windows-7. I have now loaded 6 PostGis layers into QGIS and loaded the modified SLDs. Topographicline, boundaryline and topographicarea display fine but topographicpoint and cartographicsymbol do not. They use svg files but how do they fit into QGIS. The cartographic text is not displaying what do I need to do in QGIS. – user23808 Nov 15 '13 at 21:49
  • Sorted out svg files by adding OS svg files to QGIS svg directory. Still working on text – user23808 Nov 15 '13 at 23:06
  • you might be intersted in looking here for styles - https://github.com/QGIS-UK/Styles. – tjmgis Nov 16 '13 at 08:59
  • Thanks Tim - I think everything is present in QGIS. There are 27000 lines in the cartographic text layer. The style is rule based with 21 scale dependant rules. os_cat and the other associated attributes are populated. I have set the label to textstring and display field to os_cat. No text appears at any scale. What am I missing? – user23808 Nov 16 '13 at 12:18
  • I tried the other styles you suggested which work except for text and some missing svg files in Topographical_Point such as pump and electricity poles - Chris – user23808 Nov 17 '13 at 23:13
  • I have included some screen shots of QGIS using data imported from PostGIS (PostgreSQL) modified to set os_cat using OS SLD files. The screen display looks a bit washed out but I can't get the text layer to display https://www.dropbox.com/sh/11r9dro2xboop0r/iHyoosCxkM – user23808 Nov 18 '13 at 10:37
  • Hi Chris - I often start small and build up. For example, for cartographic text drop the OSMM style and see if the points show on the map. Then use the label and use the textstring, does the label show? Then use the data derived options and shift the position of text and the orientation using the new columns you have added. see what I mean? Here is a link to one I have used successfully - https://www.dropbox.com/s/udon2b1dv40l4vy/OS%20MasterMap%20Topography%20%28backdrop%20style%29%20-%20Cartographic%20Text.qml – tjmgis Nov 18 '13 at 15:40
  • Hi Tim - Your text style works perfectly in both my test projects. I am obviously missing something as I can't find any trace of your text style in QGIS. If I look in the layer properties and I am unable to find any way into your style settings. Which tab should I be on and how do I get into the data derived options? - Chris – user23808 Nov 18 '13 at 20:08
  • The penny has finally dropped and I have now located the data derived options in the label tab under text and placement. I still can't make the OS rule based text SLD work though. I am using 5 of the OS SLDs and your qml style file for the text for which I am grateful - thanks Chris – user23808 Nov 19 '13 at 14:56
2

I'd use Astun Loader to transfer the GML into Shp or PostGis.

https://github.com/AstunTechnology/Loader

It would be worth using the latest ogr 1.10 with loader as I've seen some problems with TopographicLine with ogr.

I'd then use the styling available from Lutra Consulting to to style MasterMap. If you've got the data in PostGis you'll have to edit the 'featurecod' rule in the style file to read 'featurecode'

http://www.lutraconsulting.co.uk/resources/ostranslator

You can add additional columns to data in either shp (using qgis) or PostGIS (using sql through pgAdmin)

AndyB
  • 73
  • 8