Developer’s Corner: DXF output format promoted to official extension for GeoServer

Dear all,
as you may already know, GeoServer supports a wide variety of formats as an output of the WFS OGC service, to represent vector feature data. Such formats include the OGC standard GML XML based format (in its various versions), but also more “user friendly” ones such as the shapefile format, GeoJSON, CSV and so on.

Some formats that are not supported by default, but that are used by some people working in the GIS field, are CAD formats. Among them, the most used in absolute (thinking of open formats) is DXF, the standard AutoCad file interchange format.

Many GIS tools, for example GDAL and QGIS already support this format and a weak support has existed in GeoServer for some time, mostly unknown.

In the Geotools/GeoServer land this is the current DXF support status:

  • GeoTools includes an unsupported module for DXF file reading and a DXF DataStore
  • GeoServer included for a long time a not much supported community module for dxf writing and a WFS output format using it
In a short time this is going to evolve, because the DXF community module has come to a new life, through a review and some improvements that have recently landed on master and the 2.4.x branch.
First of all, the module has been promoted to an official extension, so soon it would be easier for people to download and use it.
Then a PPIO for the WPS protocol has been added, so that DXF can be used as an output also for WPS processes whose output is a Feature.
If you want to give it a try, it is already available as an extension of the 2.5 beta release, available here.
It is also available in the latest 2.4.x nightly here.
If you instead want to wait for a stable version, look for the 2.4.5 release in a month or so.
To install it just unzip the extension content in the WEB-IN/lib folder of GeoServer, paying attention to remove the dxf-wps jar if you don’t have the WPS extension installed, and restart GeoServer.
To check its usage, this is an example WFS call outputting the usual topp:states GeoServer demo layer to a dxf:
http://localhost:8080/geoserver/wfs?request=GetFeature&typeName=topp:states&
outputFormat=dxf

You can also save bandwidth asking for a zipped dxf file, using the following url:

http://localhost:8080/geoserver/wfs?request=GetFeature&typeName=topp:states&
outputFormat=dxf-zip

Some format options are supported to customize the final dxf details:

  • version: (number) creates a DXF in the specified version format (only 14 is currently supported); to support other versions developers can implement the DXFWriter interface or extend AbstractDXFWriter
  • asblock: (true/false) if true, all geometries are written as blocks and then inserted as entities. If false, simple geometries are directly written as entities.
  • colors: (comma delimited list of numbers): colors to be used for the DXF layers, in sequence. If layers are more than the specified colors, they will be reused many times. A set of default colors is used if the option is not used. Colors are AutoCad color numbers (7=white, etc.).
  • ltypes: (comma delimited list of line type descriptors): line types to be used for the DXF layers, in sequence. 
    • If layers are more than the specified line types, they will be reused many times.
    • If not specified, all layers will be given a solid, continuous line type. 
    • A descriptor has the following format: ![!], where
      • is the name assigned to the line type
      • (optional) is a real number that tells how long is each part of the line pattern (defaults to 0.125)
      • is a visual description of the repeatable part of the line pattern, as a sequence of – (solid line),* (dot) and _ (empty space). For example a dash-dot pattern would be expressed as –_*_.
  • layers: (comma delimited list of strings) names to be assigned to the DXF layers. If specified, must contain a name for each requested layer. By default a standard name will be assigned to layers.
  • withattributes: (true/false) enables writing an extra layer with attributes from each feature, the layer has a punctual geometry, with a point in the centroid of the original feature

If you also want to check the WPS PPIO, just use the GeoServer WPS Request builder you can find in the Demos section of the GeoServer Web Admin UI, choose a process that has a feature as an output (for example the gs:Centroid process) and choose application/dxf as the result format.

We are going to continue improving the DXF support in Geoserver if needed, so stay in touch with us!

If you are interested in learning about how we can help you achieving your goals with our Open Source products and professional services, do not hesitate to contact us!

The GeoSolutions team,