Programming with JViews Maps > Introducing the Main Classes > Readers and Writers > The MID/MIF Reader

The class relationship for the mid/mif reader is shown in Figure 1.6.

map_midmif.png

Figure 1.6 MID/MIF Reader UML Diagram

This section describes the ilog.views.maps.format.mid/mif package, which allows you to read files provided in the MapInfo Interchange File (MIF) format.

A MapInfo Interchange Format consists of a MIF file containing the geometries and rendering attributes, and a MID file containing the attributes attached to each geometry.

The MIF file is an ASCII text file that describes the geometry data associated with rendering attributes such as pen and brush styles, font, and color that should be used to transform geometries into graphic objects. The reader classes provided with the JViews Maps package allow you to use either the information contained in the MIF file or your own rendering attributes.

The MID file contains attributes, which are nongraphical additional information associated with the geometries contained in the MIF file.

The MID/MIF Reader contains the following classes:

The MIDMIF Datasource

The IlvMIDMIFDataSource class is a specialized data source that reads MIDMIF files. It wraps all MIDMIF file rendering processes.

IlvMIDMIFDataSource source = new IlvMIDMIFDataSource(filename);
source.setManager(manager);
source.start();

The IlvMIFDMIFDataSource produces a IlvMapLayer for objects having the same geometries and similar graphic attributes. If, however, a MIDMIF file contains lines whose color attributes are different, for example, red and blue, two layers are created, one for the blue lines and one for the red lines.

Classes for Reading the MapInfo Interchange File Format

The JViews Maps package provides all the necessary classes to read data provided in the MapInfo Interchange File format. In addition to these classes, the JViews Maps package also provides the IlvGraphic classes needed to render specific MIF objects.

The classes used to read MapInfo Interchange files are the following:

The IlvMIDMIFReader Class

This class reads both MIF file and MID file by providing a MIF file name and a MID file name. If the MID file name is set to null, no attribute is loaded. If the MID file name corresponds to a valid MID file, the attributes are read from the file and attached to the IlvMapFeature returned by the reader.

IlvMIDMIFReader reader = new IlvMIDMIFReader("example.mif", "example.mid");
IlvMapFeature feature = reader.getNextFeature(); 
while(feature != null)
     feature = reader.getNextFeature();

The IlvMIFReader Class

This is the class that reads a single MIF file, providing a MIF file name or a reader to the constructor. You can then iterate to obtain the IlvMapFeatures of the file, but you can also obtain information about the MIF file you are reading, such as:

Note that the coordinate system returned by the reader can be null even if the MapInfo specifications consider the geometries to be in the Geographic coordinate system if none is specified in the MIF file.

IlvMIFReader reader = 
    new IlvMIFReader("example.mif");
IlvAttributeInfoProperty info = reader.getAttributeInfo();
if(info != null) {
    System.out.println("Attributes info : ");
    for(int i = 0; i < info.getAttributesCount(); i++) {
        System.out.println("Name " + info.getAttributeName(i));
        System.out.println("Class " + info.getAttributeClass(i));
    }
}
IlvCoordinateSystem cs = reader.getCoordinateSystem();
if(cs != null) 
    System.out.println("The coordinate system is " + cs.getName());
else
    System.out.println("Assuming a geographic coordinate system");
String encoding = reader.getCharset();
System.out.println("Char set is " + encoding);

The IlvMIDReader Class

This class reads a MID file. You must have previously opened the corresponding MIF file, in order to build the second argument of the MID reader (IlvAttributeInfoProperty) that is provided in the MIF file.

IlvMIFReader reader = 
    new IlvMIFReader("example.mif");
IlvAttributeInfoProperty info = reader.getAttributeInfo();
IlvMIDReader mid = new IlvMIDReader("example.mid", info);
IlvFeatureAttributeProperty prop = mid.getNextRecord();
while(prop != null)
    prop = mid.getNextRecord();

Classes for Rendering the MapInfo Interchange File Format

Since the MIF file can contain rendering information, the JViews Maps package provides classes to directly use this rendering information. This includes a ready-to-use IlvFeatureRenderer suitable to render geometries found in the MIF file and a factory to create IlvMapLineRenderingStyle.

In addition to these rendering classes, the JViews Maps package also provides a set of specific IlvGraphic objects to display the MID/MIF geometries. These IlvGraphic objects are needed by the MID/MIF specifications but can also be used outside a MID/MIF context.

The IlvMIFFeatureRenderer Class

This class is a subclass of the IlvDefaultFeatureRenderer that dispatches on the appropriate renderer with the rendering styles found in the MIF file. This is the IlvFeatureRenderer returned by the getDefaultFeatureRenderer() method of the IlvMIFReader class. The rendering styles found in the MIF file are attached to the IlvMapFeature as properties by the reader and interpreted in the renderer.

The IlvMIFPenFactory Class

This class is a factory to create an IlvMapLineRenderingStyle by specifying a MID/MIF pattern identifier.

The IlvMIFCoordinateSystemFactory Class

This class is a factory to translate a MID/MIF coordinate system into a Maps coordinate system.

Specialized Graphics

The IlvGraphic objects needed to render MID/MIF geometries include the following classes:

Coordinate System Support

Along with objects and attribute information, MIF files also contain information on the coordinate system used to store the graphic objects of a defined file.

The possible coordinate systems in MID/MIF are the following:

The JViews Maps package fully supports projected coordinates defined in a MID/MIF file. The supported projections are listed in Table 1.1:

Table 1.1 List of Supported MID/MIF Projections
MID/MIF Projection Number 
Name 
Corresponding Projection 
Albers Equal-Area Conic 
IlvAlbersEqualAreaProjection
Azimuthal Equidistant 
IlvAzimuthalEquidistantProjection
Cylindrical Equal Area 
IlvCylindricalEqualAreaProjection
14 
Eckert IV 
IlvEckert4Projection
15 
Eckert VI 
IlvEckert6Projection
17 
Gall 
IlvMercatorProjection
Hotine Oblique Mercator 
IlvObliqueMercatorProjection
Lambert Azimuthal Equal Area 
IlvLambertAzimuthalEqualAreaProjection
Lambert Conformal Conic 
IlvLambertConformalConicProjection
19 
Lambert Conformal Conic 
(modified for Belgium 1972) 
IlvLambertConformalConicProjection
Longitude/Latitude 
Not a projection. An IlvGeographicCoordinateSystem is used. 
10 
Mercator 
IlvMercatorProjection
11 
Miller Cylindrical 
IlvMillerCylindrical Projection
13 
Mollweide 
IlvMollweideProjection
27 
Polyconic 
IlvPolyconicProjection
12 
Robinson 
IlvRobinsonProjection
16 
Sinusoidal 
IlvSinusoidalProjection
20 
Stereographic 
IlvStereographicProjection
Transverse Mercator 
IlvTransverseMercatorProjection

JViews Maps supports all ellipsoids and nearly all datums from MapInfo (see the MID/MIF file format specification for the full list of ellipsoids and datums).

Note
The MIF format specification allows user datum definition, with either 3 or 7 parameters. As the JViews Maps package does not support 7-parameter datum yet, definitions of 7- parameter datum is decoded as 3-parameter datum, skipping the rotations and scale part of datum definitions.