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.
- 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
Result of test 2: closed 3d polyline
leads in both cases to a 3d polyline, as shown in the image above.
I also tried to force ogr to create polygonz, using
which didn't improve the result, that should be a 3d polygon. Any idea how to achive this?