|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.geotools.data.mif.MIFFile
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:
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 |
public static final int MAX_STRING_LEN
Constructor Detail |
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
path
- Full pathName of the mif file, can be specified without the
.mif extensionparams
- Parameters map
java.io.IOException
- If the specified mif file could not be openedpublic 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();
path
- Full path & file name of the MIF file to create, can be
specified without the .mif extensionfeatureType
- params
- Parameter map
java.io.IOException
- Couldn't open the specified mif file for writing
header
SchemaException
- Error setting the given FeatureType as the MIF
schemaMethod Detail |
public java.lang.String getHeaderClause(java.lang.String clause)
clause
-
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?
java.io.IOException
public FeatureWriter getFeatureWriter() throws java.io.IOException
java.io.IOException
protected static java.lang.String getMifName(java.lang.String fName) throws java.io.FileNotFoundException
fName
- The file name, possibly with .mif extension
java.io.FileNotFoundException
- if extension was other than "mif"protected static java.io.File getFileHandler(java.io.File path, java.lang.String fileName, java.lang.String ext, boolean mustExist) throws java.io.FileNotFoundException
path
- Directory containing the filefileName
- Name of the file with no extensionext
- extension with trailing "."mustExist
- If true, raises an excaption if the file does not exist
java.io.FileNotFoundException
public FeatureType getSchema()
protected static void copyFileAndDelete(java.io.File in, java.io.File out, boolean deleteIn) throws java.io.IOException
in
- Source fileout
- Destination filedeleteIn
- If true, source will be deleted upon successfull copy
java.io.IOException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |