org.geotools.data.mif
Class MIFFile

java.lang.Object
  extended byorg.geotools.data.mif.MIFFile

public class MIFFile
extends java.lang.Object

MIFFile class allows sequential reading and writing of Features in MapInfo MIF/MID text file format with a FeatureReader and FeatureWriter.

This class has been developed starting from MapInfoDataSource.

Open issues:

Version:
$Id: MIFFile.java 17700 2006-01-22 23:30:39Z desruisseaux $
Author:
Luca S. Percich, AMA-MI, Paolo Rizzi, AMA-MI

Field Summary
static int MAX_STRING_LEN
           
 
Constructor Summary
MIFFile(java.lang.String path, FeatureType featureType, java.util.HashMap params)
           This constructor creates a a new MIF/MID file given schema and path.
MIFFile(java.lang.String path, java.util.Map params)
           This constructor opens an existing MIF/MID file, and creates the corresponding schema from the file header Allowed parameters in params Map: "namespace" = URI of the namespace prefix for FeatureTypes PARAM_GEOMFACTORY = GeometryFactory object to be used for creating geometries; alternatively, use PARAM_SRID; PARAM_SRID = SRID to be used for creating geometries; PARAM_FIELDCASE = field names tranformation: "upper" to uppercase | "lower" to lowercase | "" none; PARAM_GEOMNAME = <String>, name of the geometry field (defaults to "the_geom"); PARAM_GEOMTYPE = geometry type handling: "untyped" uses Geometry class | "typed" force geometry to the type of the first valid geometry found in file | "multi" like typed, but forces LineString to MultilineString and Polygon to MultiPolygon; | "Point" | "LineString" | "MultiLineString" | "Polygon" | "MultiPolygon" | "Text" forces Geometry to Point and creates a MIF_TEXT String field in the schema Header clauses values can also be set in the params Map, but they might be overridden by values read from MIF header.
 
Method Summary
protected static void copyFileAndDelete(java.io.File in, java.io.File out, boolean deleteIn)
          Utility function for copying or moving files
 FeatureReader getFeatureReader()
           Opens the MIF file for input and returns a FeatureReader for accessing the features.
 FeatureWriter getFeatureWriter()
          Returns a FeatureWriter for writing features to the MIF/MID file.
protected static java.io.File getFileHandler(java.io.File path, java.lang.String fileName, java.lang.String ext, boolean mustExist)
          Utility function for initFiles - returns a File given a parent path, the file name without extension and the extension Tests different extension case for case-sensitive filesystems
 java.lang.String getHeaderClause(java.lang.String clause)
          Gets the value for an header clause
protected static java.lang.String getMifName(java.lang.String fName)
          Returns the name of a .mif file without extension
 FeatureType getSchema()
          Returns the MIF schema
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_STRING_LEN

public static final int MAX_STRING_LEN
See Also:
Constant Field Values
Constructor Detail

MIFFile

public MIFFile(java.lang.String path,
               java.util.Map params)
        throws java.io.IOException

This constructor opens an existing MIF/MID file, and creates the corresponding schema from the file header

Allowed parameters in params Map:

Header clauses values can also be set in the params Map, but they might be overridden by values read from MIF header.

Basic usage:


   HashMap params = new HashMap();
   // params.put(MIFFile.PARAM_GEOMFACTORY, new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING_SINGLE), SRID));
   params.put(MIFFile.PARAM_SRID, new Integer(SRID));
   params.put(MIFFile.PARAM_FIELDCASE, "upper");
   params.put(MIFFile.PARAM_GEOMNAME, "GEOM");
   params.put(MIFFile.PARAM_GEOMTYPE, "typed");
   MIFFile mf = new MIFFile("c:/some_path/file.mif",params);
   FeatureType ft = mf.getSchema();
   FeatureReader fr = mf.getFeatureReader();	
   while (fr.hasNext()) {
   	Feature in = fr.next();
   	doSomethingWithFeature(in);
   }
   fr.close(); // closes file resources
 

Parameters:
path - Full pathName of the mif file, can be specified without the .mif extension
params - Parameters map
Throws:
java.io.IOException - If the specified mif file could not be opened

MIFFile

public MIFFile(java.lang.String path,
               FeatureType featureType,
               java.util.HashMap params)
        throws java.io.IOException,
               SchemaException

This constructor creates a a new MIF/MID file given schema and path. If a .mif/.mid file pair already exists, it will be overwritten.

Basic usage:


   HashMap params = new HashMap();
   params.put(MIFFile.MIFDataStore.HCLAUSE_COORDSYS, "Nonearth \"m\"");
 
   MIFFile mf = new MIFFile("c:/some_path/", ft, params);
 
 
   FeatureWriter fw = mf.getFeatureWriter();
 
   while(...) {
 	    Feature f = fw.next();
 			f.setAttribute(...,...);
 			fw.write();
 	 }
 
   fw.close();
 

Parameters:
path - Full path & file name of the MIF file to create, can be specified without the .mif extension
featureType -
params - Parameter map
Throws:
java.io.IOException - Couldn't open the specified mif file for writing header
SchemaException - Error setting the given FeatureType as the MIF schema
Method Detail

getHeaderClause

public java.lang.String getHeaderClause(java.lang.String clause)
Gets the value for an header clause

Parameters:
clause -
Returns:

getFeatureReader

public FeatureReader getFeatureReader()
                               throws java.io.IOException

Opens the MIF file for input and returns a FeatureReader for accessing the features.

TODO Concurrent file access is still not handled. MUST LOCK FILE and return an error if another FeatureReader is open - Handle concurrent access with synchronized(mif) / or Filesystem locking is enough?

Returns:
A FeatureReader for reading features from MIF/MID file
Throws:
java.io.IOException

getFeatureWriter

public FeatureWriter getFeatureWriter()
                               throws java.io.IOException
Returns a FeatureWriter for writing features to the MIF/MID file.

Returns:
A featureWriter for this file
Throws:
java.io.IOException

getMifName

protected static java.lang.String getMifName(java.lang.String fName)
                                      throws java.io.FileNotFoundException
Returns the name of a .mif file without extension

Parameters:
fName - The file name, possibly with .mif extension
Returns:
The name with no extension
Throws:
java.io.FileNotFoundException - if extension was other than "mif"

getFileHandler

protected static java.io.File getFileHandler(java.io.File path,
                                             java.lang.String fileName,
                                             java.lang.String ext,
                                             boolean mustExist)
                                      throws java.io.FileNotFoundException
Utility function for initFiles - returns a File given a parent path, the file name without extension and the extension Tests different extension case for case-sensitive filesystems

Parameters:
path - Directory containing the file
fileName - Name of the file with no extension
ext - extension with trailing "."
mustExist - If true, raises an excaption if the file does not exist
Returns:
The File object
Throws:
java.io.FileNotFoundException

getSchema

public FeatureType getSchema()
Returns the MIF schema

Returns:
the current FeatureType associated with the MIF file

copyFileAndDelete

protected static void copyFileAndDelete(java.io.File in,
                                        java.io.File out,
                                        boolean deleteIn)
                                 throws java.io.IOException
Utility function for copying or moving files

Parameters:
in - Source file
out - Destination file
deleteIn - If true, source will be deleted upon successfull copy
Throws:
java.io.IOException


Copyright © GeoTools. All Rights Reserved.