Thursday, 28 December 2017

export - Exporting PostGIS Geometry POINT as Label text to DXF or DGN


I need to export, by the ogr2ogr command or similar, text information related to a geometry position from my PostgreSQL(with PostGIS) database to an AutoCAD DXF layer file or to a Microstation DGN layer file, so I can later show that information in the AutoCAD/Microstation GIS.


I have been looking through internet for so many days but all I can get is a layer with geometry points, I always lose the text label information. I know there is the "Text" element type in DGN and the "MTEXT/TEXT" element type in DXF, so I need to generate that kind of features.



In Shapefiles I know that I can export new attribute fields with that information but it have to be obtained in DXF/DGN format.


I need to made it automatic with some kind of server command like GDAL ogr2ogr, but I have tried with the "-select" (getting the text SQL SELECT attribute) or "-lco" or "-dsco" options without any result...


Those are my commands:


ogr2ogr -select "Text" -f DXF text_layer.dxf "PG:host=192.168.1.* user=**** password=**** dbname=****" -sql "SELECT position AS the_geom, name as Text FROM the_geometry_table"

ogr2ogr -select "Text" -f DGN text_layer.dgn "PG:host=192.168.1.* user=**** password=**** dbname=****" -sql "SELECT position AS the_geom, name as Text FROM the_geometry_table"

Any help?



Answer



From the OGR DXF Driver document, dxf driver



Point features with LABEL styling are written as MTEXT entities based on the styling information.


The OGR Feature Style is available here, OGR Style guide ,look for - Label Tool Parameters.


To define the Label style:


You can add a field named OGR_STYLE to your Postgresql table and populate with something like this, "LABEL(f:"Times New Roman",s:12pt,t:{text_string})"
text_string is the field you want to display as text in the DXF.


When you run ogr2ogr to convert your Point geometry to DXF, ogr should automatically detect OGR_STYLE and output MText in the dxf.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...