| java.lang.Object org.geotools.data.mif.MIFFile
MIFFile | public class MIFFile (Code) | |
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:
-
CoordSys clause parsing is still not supported
author: Luca S. Percich, AMA-MI author: Paolo Rizzi, AMA-MI version: $Id: MIFFile.java 27862 2007-11-12 19:51:19Z desruisseaux $ |
Constructor Summary | |
public | MIFFile(String path, 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. | public | MIFFile(String path, FeatureType featureType, HashMap params)
This constructor creates a a new MIF/MID file given schema and path. |
MAX_STRING_LEN | final public static int MAX_STRING_LEN(Code) | | |
MIFFile | public MIFFile(String path, Map params) throws IOException(Code) | |
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.
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 Parameters: params - Parameters map throws: IOException - If the specified mif file could not be opened |
MIFFile | public MIFFile(String path, FeatureType featureType, HashMap params) throws IOException, SchemaException(Code) | |
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 bespecified without the .mif extension Parameters: featureType - Parameters: params - Parameter map throws: IOException - Couldn't open the specified mif file for writingheader throws: SchemaException - Error setting the given FeatureType as the MIFschema |
copyFileAndDelete | protected static void copyFileAndDelete(File in, File out, boolean deleteIn) throws IOException(Code) | | Utility function for copying or moving files
Parameters: in - Source file Parameters: out - Destination file Parameters: deleteIn - If true, source will be deleted upon successfull copy throws: IOException - |
getFeatureReader | public FeatureReader getFeatureReader() throws IOException(Code) | |
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?
A FeatureReader for reading features from MIF/MID file throws: IOException - |
getFileHandler | protected static File getFileHandler(File path, String fileName, String ext, boolean mustExist) throws FileNotFoundException(Code) | | 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 Parameters: fileName - Name of the file with no extension Parameters: ext - extension with trailing "." Parameters: mustExist - If true, raises an excaption if the file does not exist The File object throws: FileNotFoundException - |
getHeaderClause | public String getHeaderClause(String clause)(Code) | | Gets the value for an header clause
Parameters: clause - |
getSchema | public FeatureType getSchema()(Code) | | Returns the MIF schema
the current FeatureType associated with the MIF file |
|
|