GIS to CAD using ogr2ogr – Part 3 – Point Annotation to Text in CAD

GIS to CAD using ogr2ogr – Part 1 – Shp to DXF with Contour Data
GIS to CAD using ogr2ogr – Part 2 – GML to DXF with OS MasterMap

MasterMap Topo Sample Data:

https://www.ordnancesurvey.co.uk/business-and-government/licensing/sample-data/discover-data.html

OS MasterMap has an annotation layer, which is simple to symbolise in a GIS program. But becomes more difficult in CAD software.

With ogr2org, when writing a DXF file, if you have an input point geometry, which has an OGR_STYLE attribute, it will be written as a text geometry when opened in CAD.

So for our MasterMap data we have one layer we want to convert to text:
CartographicText

ogrinfo os-mastermap-topography-layer-sample-data.gml CartographicText
OGRFeature(CartographicText):855
fid (String) = osgb1000000729425681
featureCode (Integer) = 10026
version (Integer) = 1
versionDate (String) = 2001-11-11
theme (StringList) = (1:Buildings)
changeDate (StringList) = (1:1999-09-08)
reasonForChange (StringList) = (1:Modified)
descriptiveGroup (StringList) = (1:Buildings Or Structure)
physicalLevel (Integer) = 50
anchorPosition (Integer) = 0
font (Integer) = 2
height (Real) = 1.5
orientation (Integer) = 2890
textString (String) = 5
descriptiveTerm (String) = (null)
make (String) = Manmade
POINT (290875.38 92635.81)

So for this we are primarily interested in “textString” and potentially “orientation”.

Lets see the layer as points first as a baseline:

ogr2ogr -f DXF CartographicText.dxf os-mastermap-topography-layer-sample-data.gml CartographicText

Screenshot[10]

Zoomed in:

Screenshot[11]

But lets try that as text. We will keep this simple and only take into account orientation and to a small extent height. Lets look at orientation:

Orientation – The orientation of text or symbol features for cartographic placement. This is measured in tenths of a degree anticlockwise from due east (0–3599).

So conversion to degree will be simple. Orientation/10

We can also take into consideration height as a multiplier.

And “textString” stores the text itself.

The command:

ogr2ogr.exe -f DXF CartographicText2.dxf os-mastermap-topography-layer-sample-data.gml CartographicText -sql "SELECT 'LABEL(f:""Arial"",s:""'||(height*800)||'"",t:""'||textString||'"",a:""'||(orientation/10)||'"",p:5)' AS OGR_STYLE, * FROM CartographicText" -dialect SQLITE

Full extent:

Screenshot[12]

Zoomed in:

Screenshot[13]

Explained:

Since this is run in windows, through the regular console, the escape character for quotes is two quotes “”‘. So a combination on ‘ ” and “”‘ we can accommodate all the required quotes.

f:””Arial””,s:””‘||(height*800)||'””,t:””‘||textString||'””,a:””‘||(orientation/10)||'””,p:5

f:””Arial””
Font: Arial

s:””‘||(height*800)||'””
Size: Multiplier of the height field, I am not sure what the units are, comments appreciated.

t:””‘||textString||'””
Text: textString column

a:””‘||(orientation/10)||'””
Align: In degrees

p:5
Position: the OS position and the ogr2ogr style position are slightly different, so better placement could be achieved with some pre-processing

GIS to CAD using ogr2ogr – Part 1 – Shp to DXF with Contour Data
GIS to CAD using ogr2ogr – Part 2 – GML to DXF with OS MasterMap