Search in sources :

Example 11 with RecordDefinitionImpl

use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.

the class XbaseSchemaReader method getRecordDefinition.

protected RecordDefinition getRecordDefinition() throws IOException {
    if (this.recordDefinition == null) {
        this.recordDefinition = new RecordDefinitionImpl(this.typePath);
        int b = this.in.read();
        while (b != 0x0D) {
            final StringBuilder fieldName = new StringBuilder();
            boolean endOfName = false;
            for (int i = 0; i < 11; i++) {
                if (!endOfName && b != 0) {
                    fieldName.append((char) b);
                } else {
                    endOfName = true;
                }
                if (i != 10) {
                    b = this.in.read();
                }
            }
            final char fieldType = (char) this.in.read();
            this.in.skipBytes(4);
            final int length = this.in.read();
            this.in.skipBytes(15);
            b = this.in.read();
            final XBaseFieldDefinition field = new XBaseFieldDefinition(fieldName.toString(), fieldName.toString(), fieldType, length);
            if (this.fieldDefinitions != null) {
                this.fieldDefinitions.add(field);
            }
            this.recordDefinition.addField(fieldName.toString(), field.getDataType(), length, true);
        }
    }
    return this.recordDefinition;
}
Also used : RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl)

Example 12 with RecordDefinitionImpl

use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.

the class XbaseIterator method readRecordDefinition.

private void readRecordDefinition() throws IOException {
    this.recordDefinition = new RecordDefinitionImpl(this.typeName);
    int b = this.in.read();
    while (b != 0x0D) {
        final StringBuilder fieldName = new StringBuilder();
        boolean endOfName = false;
        for (int i = 0; i < 11; i++) {
            if (!endOfName && b != 0) {
                fieldName.append((char) b);
            } else {
                endOfName = true;
            }
            if (i != 10) {
                b = this.in.read();
            }
        }
        final char fieldType = (char) this.in.read();
        this.in.skipBytes(4);
        int length = this.in.read();
        final int decimalCount = this.in.read();
        this.in.skipBytes(14);
        b = this.in.read();
        final DataType dataType = DATA_TYPES.get(fieldType);
        if (fieldType == MEMO_TYPE) {
            length = Integer.MAX_VALUE;
        }
        this.recordDefinition.addField(fieldName.toString(), dataType, length, decimalCount, false);
    }
    if (this.mappedFile) {
        final EndianMappedByteBuffer file = (EndianMappedByteBuffer) this.in;
        this.firstIndex = file.getFilePointer();
    }
}
Also used : EndianMappedByteBuffer(com.revolsys.io.endian.EndianMappedByteBuffer) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DataType(com.revolsys.datatype.DataType)

Example 13 with RecordDefinitionImpl

use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.

the class XbaseRecordReader method readRecordDefinition.

private void readRecordDefinition() throws IOException {
    this.recordDefinition = new RecordDefinitionImpl(this.typeName);
    if (this.exists) {
        int readCount = Buffers.readAll(this.in, this.buffer1);
        if (readCount == -1) {
            throw new RuntimeException("Unexpected end of file: " + this.resource);
        }
        final ByteBuffer fieldHeaderBuffer = ByteBuffer.allocate(31);
        int b = this.buffer1.get();
        while (b != 0x0D) {
            this.buffer1.clear();
            readCount = Buffers.readAll(this.in, fieldHeaderBuffer);
            if (readCount != 31) {
                throw new RuntimeException("Unexpected end of file: " + this.resource);
            }
            final StringBuilder fieldName = new StringBuilder();
            boolean endOfName = false;
            for (int i = 0; i < 11; i++) {
                if (!endOfName && b != 0) {
                    fieldName.append((char) b);
                } else {
                    endOfName = true;
                }
                if (i != 10) {
                    b = fieldHeaderBuffer.get();
                }
            }
            final char fieldType = (char) fieldHeaderBuffer.get();
            fieldHeaderBuffer.getInt();
            int length = fieldHeaderBuffer.get() & 0xFF;
            final int decimalCount = fieldHeaderBuffer.get();
            fieldHeaderBuffer.clear();
            readCount = Buffers.readAll(this.in, this.buffer1);
            if (readCount == -1) {
                throw new RuntimeException("Unexpected end of file: " + this.resource);
            }
            b = this.buffer1.get();
            final DataType dataType = DATA_TYPES.get(fieldType);
            if (fieldType == MEMO_TYPE) {
                length = Integer.MAX_VALUE;
            }
            this.recordDefinition.addField(fieldName.toString(), dataType, length, decimalCount, false);
        }
    }
}
Also used : RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DataType(com.revolsys.datatype.DataType) ByteBuffer(java.nio.ByteBuffer)

Example 14 with RecordDefinitionImpl

use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.

the class ShapefileRecordReader method updateRecordDefinition.

private void updateRecordDefinition() {
    assert this.recordDefinition == null : "Cannot override recordDefinition when set";
    if (this.xbaseRecordReader != null) {
        final RecordDefinitionImpl recordDefinition = this.xbaseRecordReader.getRecordDefinition();
        recordDefinition.setPolygonRingDirection(ClockDirection.CLOCKWISE);
        this.recordDefinition = recordDefinition;
        if (recordDefinition.getGeometryFieldIndex() == -1) {
            DataType geometryType = DataTypes.GEOMETRY;
            switch(this.shapeType) {
                case ShapefileConstants.POINT_SHAPE:
                case ShapefileConstants.POINT_Z_SHAPE:
                case ShapefileConstants.POINT_M_SHAPE:
                case ShapefileConstants.POINT_ZM_SHAPE:
                    geometryType = DataTypes.POINT;
                    break;
                case ShapefileConstants.POLYLINE_SHAPE:
                case ShapefileConstants.POLYLINE_Z_SHAPE:
                case ShapefileConstants.POLYLINE_M_SHAPE:
                case ShapefileConstants.POLYLINE_ZM_SHAPE:
                    geometryType = DataTypes.MULTI_LINE_STRING;
                    break;
                case ShapefileConstants.POLYGON_SHAPE:
                case ShapefileConstants.POLYGON_Z_SHAPE:
                case ShapefileConstants.POLYGON_M_SHAPE:
                case ShapefileConstants.POLYGON_ZM_SHAPE:
                    geometryType = DataTypes.MULTI_POLYGON;
                    break;
                case ShapefileConstants.MULTI_POINT_SHAPE:
                case ShapefileConstants.MULTI_POINT_Z_SHAPE:
                case ShapefileConstants.MULTI_POINT_M_SHAPE:
                case ShapefileConstants.MULTI_POINT_ZM_SHAPE:
                    geometryType = DataTypes.MULTI_POINT;
                    break;
                default:
                    break;
            }
            recordDefinition.addField("geometry", geometryType, true);
        }
    }
}
Also used : RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DataType(com.revolsys.datatype.DataType)

Example 15 with RecordDefinitionImpl

use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method newTableRecordDefinition.

private RecordDefinitionImpl newTableRecordDefinition(final DETable deTable) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase == null) {
                return null;
            } else {
                try {
                    String schemaCatalogPath = deTable.getParentCatalogPath();
                    SpatialReference spatialReference;
                    if (deTable instanceof DEFeatureClass) {
                        final DEFeatureClass featureClass = (DEFeatureClass) deTable;
                        spatialReference = featureClass.getSpatialReference();
                    } else {
                        spatialReference = null;
                    }
                    PathName schemaPath = toPath(schemaCatalogPath);
                    final RecordStoreSchema schema = newSchema(schemaPath, spatialReference);
                    if (schemaPath.equals(this.defaultSchemaPath)) {
                        if (!(deTable instanceof DEFeatureClass)) {
                            schemaCatalogPath = "\\";
                            deTable.setCatalogPath("\\" + deTable.getName());
                        }
                    } else if (schemaPath.equals("")) {
                        schemaPath = this.defaultSchemaPath;
                    }
                    for (final Field field : deTable.getFields()) {
                        final String fieldName = field.getName();
                        final CodeTable codeTable = getCodeTableByFieldName(fieldName);
                        if (codeTable instanceof FileGdbDomainCodeTable) {
                            final FileGdbDomainCodeTable domainCodeTable = (FileGdbDomainCodeTable) codeTable;
                            field.setDomain(domainCodeTable.getDomain());
                        }
                    }
                    final String tableDefinition = EsriGdbXmlSerializer.toString(deTable);
                    try {
                        final Table table = geodatabase.createTable(tableDefinition, schemaCatalogPath);
                        geodatabase.closeTable(table);
                        table.delete();
                        final RecordDefinitionImpl recordDefinition = getRecordDefinition(PathName.newPathName(schemaPath), schemaCatalogPath, tableDefinition);
                        initRecordDefinition(recordDefinition);
                        schema.addElement(recordDefinition);
                        return recordDefinition;
                    } catch (final Throwable t) {
                        throw new RuntimeException("Unable to create table " + deTable.getCatalogPath(), t);
                    }
                } finally {
                    releaseGeodatabase();
                }
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) CodeTable(com.revolsys.record.code.CodeTable) DETable(com.revolsys.record.io.format.esri.gdb.xml.model.DETable) Table(com.revolsys.gis.esri.gdb.file.capi.swig.Table) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) DEFeatureClass(com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) Field(com.revolsys.record.io.format.esri.gdb.xml.model.Field) SpatialReference(com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference) PathName(com.revolsys.io.PathName)

Aggregations

RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)30 PathName (com.revolsys.io.PathName)14 DataType (com.revolsys.datatype.DataType)10 FieldDefinition (com.revolsys.record.schema.FieldDefinition)7 RecordDefinition (com.revolsys.record.schema.RecordDefinition)6 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Geometry (com.revolsys.geometry.model.Geometry)3 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 Record (com.revolsys.record.Record)3 DETable (com.revolsys.record.io.format.esri.gdb.xml.model.DETable)3 MapEx (com.revolsys.collection.map.MapEx)2 FileGdbRecordStore (com.revolsys.gis.esri.gdb.file.FileGdbRecordStore)2 FileGdbDomainCodeTable (com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable)2 CodeTable (com.revolsys.record.code.CodeTable)2 DEFeatureClass (com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass)2 Field (com.revolsys.record.io.format.esri.gdb.xml.model.Field)2