DxfConverter

Reads a DXF drawing of a CAD, as a technical survey or a project, into three vectors: its points, its lines and its polygons, with the layer and the other properties of each entity.

Details

The entities read are POINT and TEXT, as points, LINE and the open POLYLINE and LWPOLYLINE, as lines, and the closed POLYLINE and LWPOLYLINE, as polygons. The other entities, as CIRCLE, ARC, SPLINE, HATCH, MTEXT and the INSERT of the blocks, are ignored. The entities inside the definitions of the blocks are read where they are defined, in the coordinates of the block, not where the blocks are inserted in the drawing.

The features have the fields of the DXF entity: LAYER, LTYPE (the line type), ELEVATION, THICKNESS, COLOR (the AutoCAD color index), and for the texts TEXT, TEXT_HEIGHT and TEXT_STYLE. A filter on LAYER, with VectorFilter, separates the layers of the drawing.

The DXF has no crs: it is taken from a prj file with the same name next to the DXF or, without it, from the given code. Only the ASCII DXF is read, not the binary one.

Parameters

Reads the points, lines and polygons of an ASCII DXF file of a CAD into three vectors.

Toolbox folder: Vector Processing
Status: Certified
Keywords: IO, DXF, CAD, Feature, Vector, Reading
Authors: Andrea Antonello
Class: org.hortonmachine.modules.DxfConverter

Inputs

Parameter

Type

Unit

Default

Description

file

file

The dxf file.

pCode

CRS code

The code defining the coordinate reference system, composed by authority and code number (ex. EPSG:3003). Applied if there is no prj file next to the dxf.

Outputs

Parameter

Type

Unit

Description

pointsVector

output file

The output point vector.

lineVector

output file

The output lines vector.

polygonVector

output file

The output polygons vector.

Example

The example reads flanginec.dxf, in docs/manual/modules/maps/data: a drawing with the outline of the basin of the sub-basins of BasinShape, as a closed polyline in the layer basin, and its river network, as polylines in the layer network:

import org.hortonmachine.modules.DxfConverter

// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"

var dxf = new DxfConverter()
// a drawing with the outline of the basin and the river network, in the layers basin and network
dxf.file = folder + "flanginec.dxf"
// the dxf has no prj file next to it: its crs
dxf.pCode = "EPSG:3003"
dxf.pointsVector = folder + "dxf_points.shp"
dxf.lineVector = folder + "dxf_lines.shp"
dxf.polygonVector = folder + "dxf_polygons.shp"
dxf.process()

The 99 polylines of the network go to the lines, in red, and the closed outline of the basin to the polygons, in blue. The drawing has no points, so no points vector is written:

The river network and the outline of the basin read from the DXF drawing