Last active
December 18, 2015 21:38
-
-
Save tjmgis/5848433 to your computer and use it in GitHub Desktop.
OS VectorMap Local QGIS Text Recipe - guide to how to post process OS VectorMap Local so that you can use QGIS data driven styling to create cartographic text styling.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The following is a guide for post processing OS VectorMap Local so that it can be rendered within QGIS. | |
We need X Y coordinates so we can use the anchor position | |
ALTER TABLE vml.text ADD COLUMN x_coordinate NUMERIC; | |
COMMIT; | |
update vml.text set x_coordinate = ST_X(wkb_geometry); | |
COMMIT; | |
ALTER TABLE vml.text ADD COLUMN y_coordinate NUMERIC; | |
COMMIT; | |
update vml.text set y_coordinate = ST_Y(wkb_geometry); | |
COMMIT; | |
Firstly, we need to create a new anchor column which tells QGIS which position to locate the text. | |
ALTER TABLE vml.text ADD COLUMN vertical VARCHAR; | |
COMMIT; | |
ALTER TABLE vml.text ADD COLUMN horizontal VARCHAR; | |
COMMIT; | |
update vml.text set vertical = 'Bottom' where anchorposition = 0; | |
update vml.text set horizontal = 'Left' where anchorposition = 0; | |
update vml.text set vertical = 'Half' where anchorposition = 1; | |
update vml.text set horizontal = 'Left' where anchorposition = 1; | |
update vml.text set vertical = 'Top' where anchorposition = 2; | |
update vml.text set horizontal = 'Left' where anchorposition = 2; | |
update vml.text set vertical = 'Bottom' where anchorposition = 3; | |
update vml.text set horizontal = 'Center' where anchorposition = 3; | |
update vml.text set vertical = 'Half' where anchorposition = 4; | |
update vml.text set horizontal = 'Center' where anchorposition = 4; | |
update vml.text set vertical = 'Top' where anchorposition = 5; | |
update vml.text set horizontal = 'Center' where anchorposition = 5; | |
update vml.text set vertical = 'Bottom' where anchorposition = 6; | |
update vml.text set horizontal = 'Right' where anchorposition = 6; | |
update vml.text set vertical = 'Half' where anchorposition = 7; | |
update vml.text set horizontal = 'Right' where anchorposition = 7; | |
update vml.text set vertical = 'Top' where anchorposition = 8; | |
update vml.text 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 vml_text ADD COLUMN fontcolour VARCHAR; | |
COMMIT; | |
update vml_text set fontcolour = '#646464'; | |
COMMIT; | |
update vml_text set fontcolour = '#9E8F7C' where featurecode = 15404; | |
update vml_text set fontcolour = '#9E8F7C' where featurecode = 15407; | |
update vml_text set fontcolour = '#C47206' where featurecode = 15403; | |
update vml_text set fontcolour = '#C47206' where featurecode = 15402; | |
update vml_text set fontcolour = '#71B6D1' where featurecode = 15603; | |
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 vml_text ADD COLUMN fontname VARCHAR; | |
COMMIT; | |
update vml_text set fontname = 'Times New Roman' where font = 0; | |
update vml_text set fontname = 'Arial' where font = 1; | |
update vml_text set fontname = 'Arial' where font = 2; | |
update vml_text set fontname = 'Arial' where font = 3; | |
update vml_text set fontname = 'Arial' where font = 4; | |
COMMIT; | |
Next we add a new column for the text we actually want to render for only a specific number of features. The reason for this is we do not want to render the road text as this will be rendered from the roadclines. | |
ALTER TABLE vml_text ADD COLUMN rendertext VARCHAR; | |
COMMIT; | |
update vml_text set rendertext = textstring where featurecode = '15017'; | |
update vml_text set rendertext = textstring where featurecode = '15015'; | |
update vml_text set rendertext = textstring where featurecode = '15112'; | |
update vml_text set rendertext = textstring where featurecode = '15121'; | |
update vml_text set rendertext = textstring where featurecode = '15122'; | |
update vml_text set rendertext = textstring where featurecode = '15210'; | |
update vml_text set rendertext = textstring where featurecode = '15122'; | |
update vml_text set rendertext = textstring where featurecode = '15403'; | |
update vml_text set rendertext = textstring where featurecode = '15404'; | |
update vml_text set rendertext = textstring where featurecode = '15407'; | |
update vml_text set rendertext = textstring where featurecode = '15603'; | |
COMMIT; | |
Next we create a new column roadinfo on the roadcline table which is a concatenated attributed based on the road number and road name. The code will concentenate the attributes and also deal with NULL values. | |
ALTER TABLE vml_roadcline ADD COLUMN roadinfo VARCHAR; | |
COMMIT; | |
update vml_roadcline set roadinfo = ARRAY_TO_STRING(ARRAY[roadnumber, roadname], ' '); | |
COMMIT; | |
After post processing the data can now be rendered in QGIS using the data drive styling functions. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment