當前位置: 首頁>>代碼示例>>Java>>正文


Java DbaseFileHeader類代碼示例

本文整理匯總了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();
        }
    }
}
 
開發者ID:opf-labs,項目名稱:jhove2,代碼行數:30,代碼來源:ShapefileFeatureExtractor.java

示例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;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:63,代碼來源:ShapefileDataStore.java


注:本文中的org.geotools.data.shapefile.dbf.DbaseFileHeader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。