Search in sources :

Example 31 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class XbaseRecordReader method loadRecord.

protected Record loadRecord() throws IOException {
    final Record record = this.recordFactory.newRecord(this.recordDefinition);
    for (int i = 0; i < this.recordDefinition.getFieldCount(); i++) {
        int length = this.recordDefinition.getFieldLength(i);
        final DataType type = this.recordDefinition.getFieldType(i);
        Object value = null;
        if (type == DataTypes.STRING) {
            if (length < 255) {
                value = getString(length);
            } else {
                value = getMemo(length);
                length = 10;
            }
        } else if (type == DataTypes.DECIMAL || type == DataTypes.FLOAT) {
            value = getNumber(length);
        } else if (type == DataTypes.BOOLEAN) {
            value = getBoolean();
        } else if (type == DataTypes.DATE_TIME) {
            value = getDate(length);
        }
        record.setValue(i, value);
    }
    return record;
}
Also used : DataType(com.revolsys.datatype.DataType) Record(com.revolsys.record.Record)

Example 32 with DataType

use of com.revolsys.datatype.DataType 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 33 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class XmlRecordWriter method write.

@Override
public void write(final Record record) {
    if (!this.opened) {
        writeHeader();
    }
    QName qualifiedName = this.recordDefinition.getProperty(RecordProperties.QUALIFIED_NAME);
    if (qualifiedName == null) {
        qualifiedName = new QName(this.recordDefinition.getName());
    }
    this.out.startTag(qualifiedName);
    for (final FieldDefinition field : this.recordDefinition.getFields()) {
        final int fieldIndex = field.getIndex();
        final Object value;
        if (isWriteCodeValues()) {
            value = record.getCodeValue(fieldIndex);
        } else {
            value = record.getValue(fieldIndex);
        }
        if (isValueWritable(value)) {
            final String name = field.getName();
            final QName tagName = new QName(name);
            if (value instanceof Map) {
                @SuppressWarnings("unchecked") final Map<String, ?> map = (Map<String, ?>) value;
                this.out.startTag(tagName);
                map(map);
                this.out.endTag();
            } else if (value instanceof List) {
                final List<?> list = (List<?>) value;
                this.out.startTag(tagName);
                list(list);
                this.out.endTag();
            } else {
                final DataType dataType = field.getDataType();
                final String string = dataType.toString(value);
                this.out.nillableElement(tagName, string);
            }
        }
    }
    this.out.endTag();
}
Also used : QName(javax.xml.namespace.QName) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) List(java.util.List) Map(java.util.Map)

Example 34 with DataType

use of com.revolsys.datatype.DataType 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 35 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class OgrVrtWriter method write.

public static void write(final File file, final RecordDefinition recordDefinition, final String dataSource) throws IOException {
    try (XmlWriter writer = new XmlWriter(new FileWriter(file))) {
        writer.setIndent(true);
        writer.startDocument("UTF-8", "1.0");
        writer.startTag("OGRVRTDataSource");
        writer.startTag("OGRVRTLayer");
        final String typeName = recordDefinition.getName();
        writer.attribute("name", typeName);
        writer.startTag("SrcDataSource");
        writer.attribute("relativeToVRT", "1");
        writer.text(dataSource);
        writer.endTag("SrcDataSource");
        writer.element(new QName("SrcLayer"), typeName);
        for (final FieldDefinition attribute : recordDefinition.getFields()) {
            final String fieldName = attribute.getName();
            final DataType fieldType = attribute.getDataType();
            final Class<?> typeClass = attribute.getTypeClass();
            if (Geometry.class.isAssignableFrom(typeClass)) {
                final GeometryFactory geometryFactory = recordDefinition.getGeometryFactory();
                writer.element("GeometryType", "wkb" + fieldType);
                if (geometryFactory != null) {
                    writer.element("LayerSRS", "EPSG:" + geometryFactory.getCoordinateSystemId());
                }
                writer.startTag("GeometryField");
                writer.attribute("encoding", "WKT");
                writer.attribute("field", fieldName);
                writer.attribute("name", fieldName);
                writer.attribute("reportSrcColumn", "FALSE");
                writer.element("GeometryType", "wkb" + fieldType);
                if (geometryFactory != null) {
                    writer.element("SRS", "EPSG:" + geometryFactory.getCoordinateSystemId());
                }
                writer.endTag("GeometryField");
            } else {
                writer.startTag("Field");
                writer.attribute("name", fieldName);
                String type = "String";
                if (Arrays.asList(DataTypes.BYTE, DataTypes.SHORT, DataTypes.INT, DataTypes.LONG, DataTypes.BIG_INTEGER).contains(fieldType)) {
                    type = "Integer";
                } else if (Arrays.asList(DataTypes.FLOAT, DataTypes.DOUBLE, DataTypes.DECIMAL).contains(fieldType)) {
                    type = "Real";
                } else if (DataTypes.DATE.equals(type)) {
                    type = "Date";
                } else if (DataTypes.DATE_TIME.equals(type)) {
                    type = "DateTime";
                } else {
                    type = "String";
                }
                writer.attribute("type", type);
                final int length = attribute.getLength();
                if (length > 0) {
                    writer.attribute("width", length);
                }
                final int scale = attribute.getScale();
                if (scale > 0) {
                    writer.attribute("scale", scale);
                }
                writer.attribute("src", fieldName);
                writer.endTag("Field");
            }
        }
        writer.endTag("OGRVRTLayer");
        writer.endTag("OGRVRTDataSource");
        writer.endDocument();
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) QName(javax.xml.namespace.QName) FileWriter(java.io.FileWriter) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) XmlWriter(com.revolsys.record.io.format.xml.XmlWriter)

Aggregations

DataType (com.revolsys.datatype.DataType)85 FieldDefinition (com.revolsys.record.schema.FieldDefinition)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 PathName (com.revolsys.io.PathName)13 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 Geometry (com.revolsys.geometry.model.Geometry)10 Record (com.revolsys.record.Record)10 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)10 ArrayList (java.util.ArrayList)8 ArrayRecord (com.revolsys.record.ArrayRecord)6 PrintWriter (java.io.PrintWriter)6 EsriGeodatabaseXmlFieldType (com.revolsys.record.io.format.esri.gdb.xml.type.EsriGeodatabaseXmlFieldType)5 MapEx (com.revolsys.collection.map.MapEx)4 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 Point (com.revolsys.geometry.model.Point)4 IOException (java.io.IOException)4 Map (java.util.Map)4 CollectionDataType (com.revolsys.datatype.CollectionDataType)3 EnumerationDataType (com.revolsys.datatype.EnumerationDataType)3 CodeTable (com.revolsys.record.code.CodeTable)3