The
IlvDBFWriter and
IlvDBFAttributeInfo classes manage the writing of DBase III+ files (
.dbf
files).
These files contain records corresponding to attributes of geometries
contained within a Shapefile.
As .dbf
files need records
with fixed-size fields, it is important to choose a field size that
is large enough to contain all data of a field, as well as a size
small enough not to waste data.
The goal of the class
IlvDBFAttributeInfo
is
to complement
IlvAttributeInfoProperty for
the definition of record fields.
The following example shows how to write the contents
of an iterator to a set of .shp
, .shx
and .dbf
files:
try {
// Create the SHP writer.
IlvSHPWriter shpwriter = new IlvSHPWriter("foo.shp", "foo.shx");
// Read the first feature.
IlvMapFeature feature = iterator.getNextFeature();
// Create the DBF Writer.
IlvDBFAttributeInfo info =
new IlvDBFAttributeInfo(feature.getAttributeInfo());
IlvDBFWriter dbfwriter = new IlvDBFWriter(info,
"foo.dbf");
// Loop on features.
while (feature != null) {
shpwriter.writeFeature(feature);
dbfwriter.writeAttributes(feature.getAttributes());
feature = iterator.getNextFeature();
}
shpwriter.close();
dbfwriter.close();
} catch (IOException e) {
// Error processing.
e.printStackTrace();
}
Once again, the writers must be closed to write the headers
correctly.