When transferring data from a PostgreSQL/PostGIS database to a DXF file using ogr2ogr
I'm not able to figure out if it's possible to have both a PEN
and a LABEL
on line features.
This is what I currently run:
ogr2ogr -of "DXF" export.dxf PG:"host=localhost dbname=database port=5432 user='postgres' password='********'" -sql "WITH cte AS
(
SELECT
ST_INTERSECTION(a.geom, (
SELECT ST_SETSRID(geom, 2056)
FROM boundaries.state_boundary WHERE name LIKE 'Zuerich')
) AS geom,
surface_material
FROM av.roads AS a
WHERE ST_INTERSECTS(ST_SETSRID(a.geom, 2056), (SELECT ST_SETSRID(geom, 2056) FROM boundaries.state_boundary WHERE name LIKE 'Zuerich'))
)
SELECT
surface_material AS TEXT,
'PEN(c:#00D1E2FF,w:5px); LABEL(f:Arial,s:12pt,dp:5px,m:m,t:\"{surface_material}\")' AS OGR_STYLE,
'main road' AS LAYER,
geom
FROM cte"
Notice: the surface_material
attribute in the PG database contains text which can have spaces or single quotes in it.
A resulting feature looks like this when I explored the resulting export.dxf
file with ogrinfo -al
:
OGRFeature(entities):18181
Layer (String) = main road
SubClasses (String) = AcDbEntity:AcDbPolyline
EntityHandle (String) = 2471E
Style = PEN(c:#00bfff)
LINESTRING Z (2683912.8564 1247848.2197 0,2683924.3566 1247872.1497 0,2683015.0767 1247881.2798 0,2683016.7865 1247899.5998 0)
Some strange things that I can notice are that
- the
PEN
's color is not the one that I have actually specified (but it's visually "close to"), - the
PEN
width is not taken into account, - the
LABEL
is not appearing at all.
I don't know why. How to fix the Style value in order to embed all these values correctly?
The GDAL version I'm playing with is: GDAL 3.10.0dev-082d0e78c54dd544a14947ac216fdcca8080595c, released 2024/06/20
Relevant documentation
https://gdal.org/user/ogr_feature_style.html
https://gdal.org/drivers/vector/dxf.html
https://images.autodesk.com/adsk/files/autocad_2014_pdf_dxf_reference_enu.pdf