本文整理汇总了Java中org.geotools.data.shapefile.dbf.DbaseFileHeader类的典型用法代码示例。如果您正苦于以下问题:Java DbaseFileHeader类的具体用法?Java DbaseFileHeader怎么用?Java DbaseFileHeader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbaseFileHeader类属于org.geotools.data.shapefile.dbf包,在下文中一共展示了DbaseFileHeader类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractDbfHeader
import org.geotools.data.shapefile.dbf.DbaseFileHeader; //导入依赖的package包/类
/**
* Extract information from the DBF file header.
*
* @param reportables
* the class used to hold the features values found
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private void extractDbfHeader(ShapefileFeatures features)
throws IOException
{
DbaseFileReader dbfReader = null;
try {
dbfReader = shapefileDS.openDbfReader();
DbaseFileHeader dbfHeader = dbfReader.getHeader();
DbfHeader dbfh = features.dbfHeader;
dbfh.recordCount = dbfHeader.getNumRecords();
dbfh.recordLength = dbfHeader.getRecordLength();
dbfh.fieldCount = dbfHeader.getNumFields();
for (int i = 0; i < dbfHeader.getNumFields(); i++) {
dbfh.fieldNames.add(dbfHeader.getFieldName(i));
}
}
finally {
if (dbfReader != null) {
dbfReader.close();
}
}
}
示例2: createDbaseHeader
import org.geotools.data.shapefile.dbf.DbaseFileHeader; //导入依赖的package包/类
/**
* Attempt to create a DbaseFileHeader for the FeatureType. Note, we cannot set the number of
* records until the write has completed.
*
* @param featureType DOCUMENT ME!
*
* @return DOCUMENT ME!
*
* @throws IOException DOCUMENT ME!
* @throws DbaseFileException DOCUMENT ME!
*/
protected static DbaseFileHeader createDbaseHeader(SimpleFeatureType featureType)
throws IOException, DbaseFileException {
DbaseFileHeader header = new DbaseFileHeader();
for (int i = 0, ii = featureType.getAttributeCount(); i < ii; i++) {
AttributeDescriptor type = featureType.getDescriptor(i);
Class<?> colType = type.getType().getBinding();
String colName = type.getLocalName();
int fieldLen = FeatureTypes.getFieldLength(type);
if (fieldLen == FeatureTypes.ANY_LENGTH)
fieldLen = 255;
if ((colType == Integer.class) || (colType == Short.class) || (colType == Byte.class)) {
header.addColumn(colName, 'N', Math.min(fieldLen, 9), 0);
} else if (colType == Long.class) {
header.addColumn(colName, 'N', Math.min(fieldLen, 19), 0);
} else if (colType == BigInteger.class) {
header.addColumn(colName, 'N', Math.min(fieldLen, 33), 0);
} else if (Number.class.isAssignableFrom(colType)) {
int l = Math.min(fieldLen, 33);
int d = Math.max(l - 2, 0);
header.addColumn(colName, 'N', l, d);
// This check has to come before the Date one or it is never reached
// also, this field is only activated with the following system property:
// org.geotools.shapefile.datetime=true
} else if (java.util.Date.class.isAssignableFrom(colType)
&& Boolean.getBoolean("org.geotools.shapefile.datetime")) {
header.addColumn(colName, '@', fieldLen, 0);
} else if (java.util.Date.class.isAssignableFrom(colType)
|| Calendar.class.isAssignableFrom(colType)) {
header.addColumn(colName, 'D', fieldLen, 0);
} else if (colType == Boolean.class) {
header.addColumn(colName, 'L', 1, 0);
} else if (CharSequence.class.isAssignableFrom(colType) || colType == java.util.UUID.class) {
// Possible fix for GEOT-42 : ArcExplorer doesn't like 0 length
// ensure that maxLength is at least 1
header.addColumn(colName, 'C', Math.min(254, fieldLen), 0);
} else if (Geometry.class.isAssignableFrom(colType)) {
continue;
//skip binary data types
} else if (colType == byte[].class) {
continue;
} else {
throw new IOException("Unable to write column " +colName + " : " + colType.getName());
}
}
return header;
}