3

I have two tables in a pg database. One with annotations/points and one with linestrings. I would like to export both of them to the same dxf file with ogr2ogr. Is it possible at all somehow? I have managed to export the lines based on this article. And the points as well based on this. I also checked the official gdal documentation but there are no examples for my problem.

The ogr2ogr commands:

ogr2ogr -f "DXF" dir\line_layer.dxf "PG:host=*** user=*** dbname=***" -sql "select the_geom from shcema.line_table"
ogr2ogr -f "DXF" dir\annot_layer.dxf "PG:host=*** user=*** dbname=***" -sql "select the_geom, ogr_style from shcema.annot_table"

The ogr_style column contains data like this: "LABEL(f:""Times New Roman"",s:12pt,t:Sz 5)"

So my question is: Is it somehow possible to export from these two different sources to the same dxf file? (I am using GDAL 3.0.4.)

3
  • 2
    Points and lines can be written into same DXF but they must come from one OGR datasource as documented Only one OGR layer can be used to create the output file (but many DXF layers can be created). You could combine lines and points into one layer in PostGIS but then you must add dummy OGR_STYLE field also for your line features.
    – user30184
    Commented May 18, 2021 at 8:53
  • I combined them and now on the dxf I can see the lines and the insertion points of the texts, but not the texts themselves. I added PEN(c:black) to the ogr_stlye column for the lines. In the sql query i tried selecting everything/ only the geom/ the geom and the ogr_style/ the geom and the text but none of them worked as I hoped. Do you have any idea what am I missing?
    – 588chm
    Commented May 18, 2021 at 9:36
  • I apologize but you have now more experience than I have about DXF and GDAL.
    – user30184
    Commented May 18, 2021 at 9:41

1 Answer 1

2

I managed to find a solution and now I am answering my own question. The geometry column must be geometry type, so it can store lines and points as well. You can specify the display style in a column called ogr_style, based on the parameters shown here. Also if you add a column called layer you can specify a layer for the given record.

Note that you will get an error message, but the output will be just fine:

ERROR 1: DXF layer does not support arbitrary field creation, field 'ogr_style' not created. 

Here is a sample of my postgresql table:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.