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:

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:

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

Lets see the layer as points first as a baseline:


Zoomed in:


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:

Full extent:


Zoomed in:



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.


Font: Arial

Size: Multiplier of the height field, I am not sure what the units are, comments appreciated.

Text: textString column

Align: In degrees

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

9 thoughts on “GIS to CAD using ogr2ogr – Part 3 – Point Annotation to Text in CAD

  1. Pingback: GIS to CAD using ogr2ogr – Part 3 – Point Annotation to Text in CAD |

  2. Pingback: GIS to CAD using ogr2ogr – Part 2 – GML to DXF with OS MasterMap | GIS for Thought

  3. BoKai


    i followed your description of getting Annotation/Labeling from some file to DXF. At the time beeing i am trying to run the command as recommended:
    ogr2ogr.exe -f DXF Hausnummern.dxf Lage_mit_Hausnummer_clip.shp Lage_mit_Hausnummer_clip -sql “SELECT ‘LABEL(f:””Arial””,s:””‘||(TXTHOH*1)||'””,t:””‘||TXT||'””,a:””‘||(DWI_MATH*1)||'””,p:5)’ AS OGR_STYLE, * FROM Lage_mit_Hausnummer_clip” -dialect SQLITE
    But i get an Error because of quotes problem and about || sign.

    I didn’t wanted to change anything of your code thats why i also used the brackets with math operations as multiplication with 1. The orientation of my Text lables is ok and need no transformation.

    The only big difference is that i used a shp as input file

    Do you have any hints or solutions for the problem?

    Thank you in advance!



  4. Angela Blanco-Vogt


    I am trying to convert annotation to dxf-file.
    I have saved the Postgis layer to gml. But I am getting this message:

    C:\Temp\Alkis2018_DNG>ogrinfo Nummer_beschriftung.gml CartographicText
    Had to open data source read-only.
    INFO: Open of Nummer_beschriftung.gml'
    using driver
    GML’ successful.
    FAILURE: Couldn’t fetch requested layer CartographicText!

    Best regards

    1. Heikki Vesanto Post author

      CartographicText is the name of the layer inside the Ordnance Survey MasterMap GML file. You need to specify the name of you layer.

      So try ogrinfo Nummer_beschriftung.gml and see what layers it has. Likely it has a layer called Nummer_beschriftung.

      If I was you I wouldn’t convert to GML at all, and just use the PostgreSQL layer directly.

  5. Nick

    This is a wonderful tutorial, thanks for taking the time to pull it together.

    I would like to add multiple column features as mtext labels – do you have any ideas how this could be done?

    1. Heikki Vesanto Post author

      You can concatenate multiple columns into one. For example if the column names were text1 and text2:

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

  6. Andy Hird

    Anyone any pointers for doing this with MapInfo and creating a Text Object and not a point object

    Thanks in advance


Leave a Reply

Your email address will not be published. Required fields are marked *