The DXF reader

There are two ways of reading DXF format files:
  • Using an IlvMapDXFReader instance directly. In this case, you must write all of the code required to render the DXF features into graphic objects, and then add them to the manager.
    The IlvMapDXFReader class reads DXF features from a specified DXF file or catalog. It implements the IlvMapFeatureIterator interface to iterate over the read features.
  • Using an IlvDXFDataSource. This is a convenient way of performing all the above operations at once and is more integrated with the data model of the map.
    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 data sets are usually nongeoreferenced.
The source code for the Map Builder demonstration, which contains all of the code described in this section, can be found at <installdir> /jviews-maps810/samples/mapbuilder/index.html.
To read the DXF features and create vector data using the DXF readerobject:
  1. Create an I lvMapDXFReader instance from the path of the DXF file:
    String DXFpath = " C:/maps/DXF/map.dxf";
    IlvMapDXFReader reader = new IlvMapDXFReader(DXFpath);
    
  2. Set the transformation to use to render DXF, for example:
    reader.setDestinationBounds(new Rectangle2D.Double
       (lonMinRad,latMinRad,lonMaxRad,latMaxRad));
    
  3. Get the default DXF renderer:
    IlvFeatureRenderer renderer = reader. getDefaultFeatureRenderer ();
    
  4. 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();
    }
    
To read DXF features and create vector data using the DXF data source:
  1. Create an IlvDXFDataSource :
    String DXFpath = " C:/maps/DXF_0606_ed8/DXFT";
    IlvDXFDataSource source = new IlvDXFDataSource(DXFpath); 
    
  2. Connect this data source with the manager of the view:
    source.setManager(manager);
    
  3. 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: setInternalTransformation.
  4. Start the DXF data source:
    source.start();