Programming with JViews Maps > Introducing the Main Classes > Readers and Writers > The DXF Reader

There are two ways of reading DXF files:

This section contains the following topics:

The source code for the Map Builder demonstration, which contains all of the code described in this section, can be found at <installdir>/jviews-maps81/samples/mapbuilder/index.html

The IlvMapDXFReader Class

This class reads DXF features from a specified DXF file or catalog. It implements the IlvMapFeatureIterator interface to iterate over the read features.

Using the IlvMapDXFReader Class to Create Vector Data

To read the DXF features using the IlvMapDXFReader object:

  1. Create an IlvMapDXFReader instance from the path of the DXF file:
String DXFpath = " C:/maps/DXF/map.dxf";
IlvMapDXFReader reader = new IlvMapDXFReader(DXFpath);
  1. Set the transformation to use to render DXF, for example:
reader.setDestinationBounds(new Rectangle2D.Double
   (lonMinRad,latMinRad,lonMaxRad,latMaxRad));
  1. Get the default DXF renderer:
IlvFeatureRenderer renderer = reader. getDefaultFeatureRenderer ();
  1. Iterate over the features, render them, and assign them to a manager:
IlvMapFeature feature = reader.getNextFeature();
while(feature != null) {
  // Render map feature into graphic object
  IlvGraphic graphic = renderer.makeGraphic(feature,null);
  // Add this object on the first layer of the manager
  manager.addObject(graphic, 0, false);
  feature = reader.getNextFeature();
}

The IlvDXFDataSource Class

The IlvDXFDataSource class provides a convenient way of creating a set of layers containing DXF data in a manager. You can also georeference the geographic objects to create, as DXF datasets are usually non-georeferenced.

Using the IlvDXFDataSource Class to Create Vector Data

To read DXF features using the IlvDXFDataSource:

  1. Create an IlvDXFDataSource:
String DXFpath = " C:/maps/DXF_0606_ed8/DXFT";
IlvDXFDataSource source = new IlvDXFDataSource(DXFpath); 
  1. Connect this data source with the manager of the view:
source.setManager(manager);
  1. Set the transformation to use to render DXF into geo-referenced objects, for example:
source.setDestinationBounds(lonMinRad,latMinRad,lonMaxRad,latMaxRad);
Alternatively you can use a tailored transformation through the use of: IlvDXFDataSource.setInternalTransformation.
  1. Start the DXF data source:
source.start();