public class BC_MIFFile extends 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:
Modifier and Type | Field and Description |
---|---|
static int |
MAX_STRING_LEN |
Constructor and Description |
---|
BC_MIFFile(String path,
org.geotools.feature.FeatureType featureType,
HashMap params)
This constructor creates a a new MIF/MID file given schema and path.
|
BC_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.
|
Modifier and Type | Method and Description |
---|---|
protected static void |
copyFileAndDelete(File in,
File out,
boolean deleteIn)
Utility function for copying or moving files
|
org.geotools.data.FeatureReader |
getFeatureReader()
Opens the MIF file for input and returns a FeatureReader for accessing
the features.
|
org.geotools.data.FeatureWriter |
getFeatureWriter()
Returns a FeatureWriter for writing features to the MIF/MID file.
|
protected static File |
getFileHandler(File path,
String fileName,
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
|
String |
getHeaderClause(String clause)
Gets the value for an header clause.
|
protected static String |
getMifName(String fName)
Returns the name of a .mif file without extension
|
org.geotools.feature.FeatureType |
getSchema()
Returns the MIF schema
|
public static final int MAX_STRING_LEN
public BC_MIFFile(String path, Map params) throws 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 mapIOException
- If the specified mif file could not be openedpublic BC_MIFFile(String path, org.geotools.feature.FeatureType featureType, HashMap params) throws IOException, org.geotools.feature.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
- der Typ des Featuresparams
- Parameter mapIOException
- Couldn't open the specified mif file for writing headerorg.geotools.feature.SchemaException
- Error setting the given FeatureType as the MIF schemapublic String getHeaderClause(String clause)
clause
- der Name der Clausepublic org.geotools.data.FeatureReader getFeatureReader() throws 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?
IOException
- IO-Fehler beim Öffnen des Readerspublic org.geotools.data.FeatureWriter getFeatureWriter() throws IOException
IOException
- IO-Fehler beim Öffnen des Writersprotected static String getMifName(String fName) throws FileNotFoundException
fName
- The file name, possibly with .mif extensionFileNotFoundException
- if extension was other than "mif"protected static File getFileHandler(File path, String fileName, String ext, boolean mustExist) throws 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 existFileNotFoundException
public org.geotools.feature.FeatureType getSchema()
protected static void copyFileAndDelete(File in, File out, boolean deleteIn) throws IOException
in
- Source fileout
- Destination filedeleteIn
- If true, source will be deleted upon successfull copyIOException
Copyright © 2017 BitCtrl Systems GmbH. All rights reserved.