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 | Class and Description |
---|---|
private class |
BC_MIFFile.Reader
Private FeatureReader inner class for reading Features from the MIF file
|
private class |
BC_MIFFile.Writer
MIF FeatureWriter
|
Modifier and Type | Field and Description |
---|---|
private char |
chDelimiter |
private static String |
CLAUSE_ANGLE |
private static String |
CLAUSE_BRUSH |
private static String |
CLAUSE_CENTER |
private static String |
CLAUSE_COLUMNS |
private static String |
CLAUSE_FONT |
private static String |
CLAUSE_JUSTIFY |
private static String |
CLAUSE_LABEL |
private static String |
CLAUSE_PEN |
private static String |
CLAUSE_RIGHT |
private static String |
CLAUSE_SMOOTH |
private static String |
CLAUSE_SPACING |
private static String |
CLAUSE_SYMBOL |
private static String |
DEFAULT_BRUSH |
private static String |
DEFAULT_PEN |
private static String |
DEFAULT_SYMBOL |
private Object[] |
featureDefaults |
private org.geotools.feature.FeatureType |
featureType |
private String |
fieldNameCase |
private String |
geometryClass |
private String |
geometryName |
private com.vividsolutions.jts.geom.GeometryFactory |
geomFactory |
private int |
geomFieldIndex |
private HashMap |
header |
private static Logger |
LOGGER |
static int |
MAX_STRING_LEN |
private File |
midFile |
private File |
midFileOut |
private File |
mifFile |
private File |
mifFileOut |
private float |
multX |
private float |
multY |
private URI |
namespace |
private int |
numAttribs |
private Integer |
SRID |
private float |
sumX |
private float |
sumY |
private boolean |
toGeometryCollection |
private static String |
TYPE_ARC |
private static String |
TYPE_COLLECTION |
private static String |
TYPE_ELLIPSE |
private static String |
TYPE_LINE |
private static String |
TYPE_MULTIPOINT |
private static String |
TYPE_NONE |
private static String |
TYPE_PLINE |
private static String |
TYPE_POINT |
private static String |
TYPE_RECT |
private static String |
TYPE_REGION |
private static String |
TYPE_ROUNDRECT |
private static String |
TYPE_TEXT |
private boolean |
useTransform |
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
|
private String |
exportClause(String clause,
boolean required,
boolean quote) |
private String |
exportHeader()
Creates the MIF file header
|
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.
|
private org.geotools.data.FeatureWriter |
getFeatureWriter(boolean append)
Private FeatureWriter in append mode, could be called by
DataStore.getFeatureWriterAppend(); not implemented yet
|
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.
|
private String |
getMapInfoAttrType(org.geotools.feature.AttributeType at)
Maps an AttributeType to a MapInfo field type
|
protected static String |
getMifName(String fName)
Returns the name of a .mif file without extension
|
private Object |
getParam(String name,
Object defa,
boolean required,
Map params)
Returns a parameter value from the parameters map
|
org.geotools.feature.FeatureType |
getSchema()
Returns the MIF schema
|
private BC_MIFValueSetter[] |
getValueSetters()
Gets the ValueSetters
|
private void |
initFiles(String path,
boolean mustExist)
Sets the path name of the MIF and MID files
|
private void |
parseParams(Map params)
Parses the parameters map into fields:
|
private void |
readMifHeader(boolean skipRead,
BC_MIFFileTokenizer mif)
Reads the header from the given MIF file stream tokenizer
|
private void |
setHeaderClause(String clause,
String value)
Sets the value for a Header Clause.
|
private void |
setSchema(org.geotools.feature.FeatureType ft)
Sets the schema (FeatureType) and creates value setters and IO object
buffer
|
private static final String TYPE_NONE
private static final String TYPE_POINT
private static final String TYPE_LINE
private static final String TYPE_PLINE
private static final String TYPE_REGION
private static final String TYPE_TEXT
private static final String TYPE_ARC
private static final String TYPE_RECT
private static final String TYPE_ROUNDRECT
private static final String TYPE_ELLIPSE
private static final String TYPE_MULTIPOINT
private static final String TYPE_COLLECTION
private static final String CLAUSE_SYMBOL
private static final String CLAUSE_PEN
private static final String CLAUSE_SMOOTH
private static final String CLAUSE_CENTER
private static final String CLAUSE_BRUSH
private static final String CLAUSE_FONT
private static final String CLAUSE_ANGLE
private static final String CLAUSE_JUSTIFY
private static final String CLAUSE_SPACING
private static final String CLAUSE_RIGHT
private static final String CLAUSE_LABEL
private static final String CLAUSE_COLUMNS
public static final int MAX_STRING_LEN
private static final String DEFAULT_PEN
private static final String DEFAULT_BRUSH
private static final String DEFAULT_SYMBOL
private static Logger LOGGER
private final HashMap header
private File mifFile
private File midFile
private File mifFileOut
private File midFileOut
private Object[] featureDefaults
private char chDelimiter
private org.geotools.feature.FeatureType featureType
private int numAttribs
private int geomFieldIndex
private URI namespace
private boolean useTransform
private float multX
private float multY
private float sumX
private float sumY
private com.vividsolutions.jts.geom.GeometryFactory geomFactory
private Integer SRID
private String fieldNameCase
private String geometryName
private String geometryClass
private boolean toGeometryCollection
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 schemaprivate void parseParams(Map params) throws IOException
params
- IOException
- Error getting parameters from the specified mapprivate Object getParam(String name, Object defa, boolean required, Map params) throws IOException
name
- defa
- required
- params
- IOException
- if required parameter is missingprivate void setHeaderClause(String clause, String value) throws IOException
Sets the value for a Header Clause. Possible values are:
clause
- Name of the Header Clausevalue
- Value for the Header ClauseIOException
- Bad delimiter was specifiedpublic 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 Writersprivate org.geotools.data.FeatureWriter getFeatureWriter(boolean append) throws IOException
Private FeatureWriter in append mode, could be called by DataStore.getFeatureWriterAppend(); not implemented yet
append
- IOException
private String exportHeader() throws org.geotools.feature.SchemaException
org.geotools.feature.SchemaException
- A required header clause is missing.private String exportClause(String clause, boolean required, boolean quote) throws org.geotools.feature.SchemaException
org.geotools.feature.SchemaException
private String getMapInfoAttrType(org.geotools.feature.AttributeType at)
at
- Attribute Typeprivate void initFiles(String path, boolean mustExist) throws FileNotFoundException
path
- The full path of the .mif file, with or without extensionmustExist
- True if opening file for readingFileNotFoundException
protected 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
private void readMifHeader(boolean skipRead, BC_MIFFileTokenizer mif) throws IOException, org.geotools.feature.SchemaException
skipRead
- Skip the header, just to get to the data sectionmif
- IOException
org.geotools.feature.SchemaException
- Error reading header informationpublic org.geotools.feature.FeatureType getSchema()
private void setSchema(org.geotools.feature.FeatureType ft) throws org.geotools.feature.SchemaException
ft
- org.geotools.feature.SchemaException
- The given FeatureType is not compatible with MapInfo formatprivate BC_MIFValueSetter[] getValueSetters() throws org.geotools.feature.SchemaException
org.geotools.feature.SchemaException
- An attribute of an unsupported type was found.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.