I'm trying to export PostGIS points as blocks to DXF format. I have a simple table in PostGIS with columns:

CREATE TABLE pod_com_azimuth
  ogc_fid integer,
  rotation double precision,
  pointtype text,
  geom geometry(Point)

I'm converting it to DXF with an ogr2ogr utility:

ogr2ogr -f DXF angle_test.dxf 
PG:"dbname='coms' host='localhost' port='5432' user='mofo' password='mofo' schemas=public"
-sql "select ogc_fid, rotation as blockangle, pointtype as blockname, 'rblk' as layer, geom 
from pod_com_azimuth"

But when I open the resulting file in AutoCAD I get a layer with POINT objects. But I need them to be blocks with a blockname and blockangle values taken from PostgreSQL fields. How do I export them as blocks (inserts)?

1 Answer 1


You should firstly provide a reference DXF file(e.g. my.dxf) in the folder from where you want to execute the ogr2ogr command. It should contain the DXF block you want to use in your exported DXF. For example, it could contain a block with the name "pnt".

Then, you should execute an ogr2ogr command that could look like this:

ogr2ogr -f DXF angle_test.dxf -dsco HEADER=my.dxf PG:"dbname='coms' host='localhost' port='5432' user='mofo' password='mofo'" -sql "select rotation as BlockAngle, 'pnt' as BlockName, 'rblk' as Layer, geom from pod_com_azimuth"

dsco comes from "Dataset creation option (format specific)", based on the GDAL documentation (gdal-2.4.3/apps/ogrdissolve.cpp, line 498)

I learned to do this ogr2ogr command from this mailing list: https://lists.osgeo.org/pipermail/gdal-dev/2011-August/029796.html

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.