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.

  • 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 9 '13 at 14:57
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.

  • 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 7: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
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)

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.