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

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

Lets see the layer as points first as a baseline:

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:

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

6 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 | GeoNe.ws

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

  3. BoKai

    Hallo,

    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!

    Best,

    Bo

    Reply
  4. Angela Blanco-Vogt

    Hallo,

    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
    Angela

    Reply
    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.

      Reply

Leave a Reply

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