The JViews Maps package
provides all the necessary classes to read data provided in the
MapInfo Interchange File (MIF) 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 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:
- The IlvAttributeInfoProperty, which defines the name and the classes of the attributes that can be found in the associated MID file.
- The default feature renderer suitable to render the geometries contained in this file.
- The character encoding used in this file.
- The coordinate system in which the geometries of the file are expressed.
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();