3

Today I tried to export a 3-dimensional geometry out of postgis into a dxf file. After some tests it came out, that I was able to export

  • a 3d-linestring which represents the geometry or
  • a 2d-polygon which is basically the 3d geometry wih dropped z-values.

but not a closed 3d-polygon.

My environment

  • PostgreSQL 9.6, Postgis 2.3.2
  • GDAL 2.0.2

Let's create a single polygon and two tables for the ogr-export:

--cleanup
DROP TABLE IF EXISTS polygon;
DROP TABLE IF EXISTS test1;
DROP TABLE IF EXISTS test2;

--create single polygonz
SELECT 
    ST_GeomFromText('POLYGON Z ((0.0 0.0 0.0  ,  10.0 0.0 10.0  ,  0.0 10.0 10.0  ,  0.0 0.0 0.0))') as geom
INTO
    polygon;

--create ogr table with polygon z
SELECT
    1 as gid,
    'Layer 1'::text AS layer,
    'BRUSH(fc:#ff0066,bc:#ff0066,id:"ogr-brush-0")'::text AS ogr_style,
    geom AS geom
INTO
    test1
FROM
    polygon;

--create ogr table with closed linestring z
SELECT
    1 as gid,
    'Layer 1'::text AS layer,
    'BRUSH(fc:#ff0066,bc:#ff0066,id:"ogr-brush-0")'::text AS ogr_style,
    ST_ExteriorRing((ST_Dump(geom)).geom) AS geom
INTO
    test2
FROM
    polygon;

And use the following script to export the geometry into DXF:

ogr2ogr -f "DXF" test1.dxf PG:"dbname=test3d host=127.0.0.1 port=5432 user=postgres password=postgres" -sql "SELECT * FROM test1"
ogr2ogr -f "DXF" test2.dxf PG:"dbname=test3d host=127.0.0.1 port=5432 user=postgres password=postgres" -sql "SELECT * FROM test2"

Result of test1: 2d hatch

test1.dxf

Result of test 2: closed 3d polyline

test2.dxf

Setting

 DXF_WRITE_HATCH=NO

leads in both cases to a 3d polyline, as shown in the image above.

I also tried to force ogr to create polygonz, using

-nlt POLYGONZ

which didn't improve the result, that should be a 3d polygon. Any idea how to achive this?

2

I don't think this is possible.

From reading the source code of the DXFWriter, one can see that any polygon with different heights values will be converted to an AcDb3dPolyline entity.

You can have elevation in your DXF if you specify -zField <column> in your command, with <column> being the column name in your postgis table containing elevation information, but that is not what you want to achieve : elevation is a single property for a polyline, perfect for contour lines but not much else.

The closest DXF entity to a 3D polygon would be 3DSOLID, but the DXFWriter has no support for this entity type as of now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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