Search in sources :

Example 56 with DataType

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

the class RecordIoTestSuite method doRecordWriteTest.

private static void doRecordWriteTest(final PathResource resource, final Record record) {
    final RecordDefinition recordDefinition = record.getRecordDefinition();
    final GeometryFactory geometryFactory = recordDefinition.getGeometryFactory();
    try (Writer<Record> writer = RecordWriter.newRecordWriter(record, resource)) {
        writer.setProperty(IoConstants.GEOMETRY_FACTORY, geometryFactory);
        final FieldDefinition geometryField = recordDefinition.getGeometryField();
        if (geometryField != null) {
            final DataType geometryDataType = geometryField.getDataType();
            writer.setProperty(IoConstants.GEOMETRY_TYPE, geometryDataType);
        }
        writer.write(record);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 57 with DataType

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

the class RecordIoTestSuite method addGeometryTestSuites.

public static void addGeometryTestSuites(final TestSuite suite, final String namePrefix, final GeometryTestFunction<GeometryFactory, Geometry, DataType> testFunction) {
    final List<DataType> geometryDataTypes = Arrays.asList(DataTypes.POINT, DataTypes.LINE_STRING, DataTypes.POLYGON, DataTypes.MULTI_POINT, DataTypes.MULTI_LINE_STRING, DataTypes.MULTI_POLYGON);
    for (final DataType dataType : geometryDataTypes) {
        final TestSuite dataTypeSuite = new TestSuite(namePrefix + " " + dataType.toString());
        suite.addTest(dataTypeSuite);
        for (int axisCount = 2; axisCount < 5; axisCount++) {
            int maxGeometryCount = 1;
            if (dataType.toString().startsWith("Multi")) {
                maxGeometryCount = 3;
            }
            for (int geometryCount = 0; geometryCount <= maxGeometryCount; geometryCount++) {
                int maxVertexCount = 2;
                if (dataType.toString().contains("Line")) {
                    maxVertexCount = 4;
                }
                for (int vertexCount = 2; vertexCount <= maxVertexCount; vertexCount++) {
                    int maxRingCount = 0;
                    if (dataType.toString().contains("Polygon")) {
                        maxRingCount = 3;
                    }
                    if (geometryCount == 0) {
                        maxRingCount = 0;
                    }
                    for (int ringCount = 0; ringCount <= maxRingCount; ringCount++) {
                        final GeometryFactory geometryFactory = GeometryFactory.floating(4326, axisCount);
                        double delta = 1.0;
                        if (geometryFactory.isProjected()) {
                            delta = 1000.0;
                        }
                        final Geometry geometry = GeometryTestUtil.geometry(geometryFactory, dataType, geometryCount, ringCount, vertexCount, delta);
                        String name = namePrefix + " " + dataType + " A=" + axisCount + " G=" + geometryCount;
                        if (maxVertexCount > 2) {
                            name += " V=" + vertexCount;
                        }
                        if (maxRingCount > 2) {
                            name += " R=" + ringCount;
                        }
                        final TestCase testCase = new RunnableTestCase(name, () -> testFunction.apply(geometryFactory, geometry, dataType));
                        dataTypeSuite.addTest(testCase);
                    }
                }
            }
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) TestSuite(junit.framework.TestSuite) RunnableTestCase(com.revolsys.junit.RunnableTestCase) TestCase(junit.framework.TestCase) RunnableTestCase(com.revolsys.junit.RunnableTestCase) DataType(com.revolsys.datatype.DataType)

Example 58 with DataType

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

the class ShapefileGeometryUtil method getShapeType.

public int getShapeType(final Geometry geometry) {
    if (geometry != null) {
        final GeometryFactory geometryFactory = geometry.getGeometryFactory();
        final DataType dataType = geometry.getDataType();
        return getShapeType(geometryFactory, dataType);
    }
    return ShapefileConstants.NULL_SHAPE;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) DataType(com.revolsys.datatype.DataType)

Example 59 with DataType

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

the class XbaseRecordWriter method writeHeader.

@SuppressWarnings("deprecation")
private void writeHeader() throws IOException {
    if (this.out != null) {
        final ByteBuffer headerBuffer = ByteBuffer.allocateDirect(32);
        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);
        int recordLength = 1;
        this.fields.clear();
        int fieldCount = 0;
        for (final String name : this.recordDefinition.getFieldNames()) {
            final int index = this.recordDefinition.getFieldIndex(name);
            final int length = this.recordDefinition.getFieldLength(index);
            final int scale = this.recordDefinition.getFieldScale(index);
            final DataType fieldType = this.recordDefinition.getFieldType(index);
            final Class<?> typeJavaClass = fieldType.getJavaClass();
            final int fieldLength = addDbaseField(name, fieldType, typeJavaClass, length, scale);
            if (fieldLength > 0) {
                recordLength += fieldLength;
                fieldCount++;
            }
        }
        this.recordBuffer = ByteBuffer.allocateDirect(recordLength);
        headerBuffer.put((byte) 0x03);
        final Date now = new Date();
        headerBuffer.put((byte) now.getYear());
        headerBuffer.put((byte) (now.getMonth() + 1));
        headerBuffer.put((byte) now.getDate());
        // Write 0 as the number of records, come back and update this when closed
        headerBuffer.putInt(0);
        final short headerLength = (short) (33 + fieldCount * 32);
        headerBuffer.putShort(headerLength);
        headerBuffer.putShort((short) recordLength);
        headerBuffer.putShort((short) 0);
        headerBuffer.put((byte) 0);
        headerBuffer.put((byte) 0);
        headerBuffer.putInt(0);
        headerBuffer.putInt(0);
        headerBuffer.putInt(0);
        headerBuffer.put((byte) 0);
        headerBuffer.put((byte) 1);
        headerBuffer.putShort((short) 0);
        Buffers.writeAll(this.out, headerBuffer);
        for (final XBaseFieldDefinition field : this.fields) {
            if (field.getDataType() != DataTypes.OBJECT) {
                final String name = field.getName();
                final byte[] nameBytes = name.getBytes();
                final int length = field.getLength();
                int decimalPlaces = field.getDecimalPlaces();
                if (decimalPlaces < 0) {
                    decimalPlaces = 0;
                } else if (decimalPlaces > 15) {
                    decimalPlaces = Math.min(length, 15);
                } else if (decimalPlaces > length) {
                    decimalPlaces = Math.min(length, 15);
                }
                headerBuffer.put(nameBytes, 0, Math.min(10, nameBytes.length));
                final int numPad = 11 - nameBytes.length;
                for (int i = 0; i < numPad; i++) {
                    headerBuffer.put((byte) 0);
                }
                headerBuffer.put((byte) field.getType());
                headerBuffer.putInt(0);
                headerBuffer.put((byte) length);
                headerBuffer.put((byte) decimalPlaces);
                headerBuffer.putShort((short) 0);
                headerBuffer.put((byte) 0);
                headerBuffer.putShort((short) 0);
                headerBuffer.put((byte) 0);
                headerBuffer.put((byte) 0);
                headerBuffer.put((byte) 0);
                headerBuffer.put((byte) 0);
                headerBuffer.put((byte) 0);
                headerBuffer.put((byte) 0);
                headerBuffer.put((byte) 0);
                headerBuffer.put((byte) 0);
                headerBuffer.put((byte) 0);
                Buffers.writeAll(this.out, headerBuffer);
            }
        }
        headerBuffer.put((byte) 0x0d);
        Buffers.writeAll(this.out, headerBuffer);
    }
}
Also used : DataType(com.revolsys.datatype.DataType) ByteBuffer(java.nio.ByteBuffer) Date(java.util.Date)

Example 60 with DataType

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

the class OsnSerializer method serializeAttributes.

public void serializeAttributes(final Record object) throws IOException {
    final RecordDefinition type = object.getRecordDefinition();
    final int attributeCount = type.getFieldCount();
    for (int i = 0; i < attributeCount; i++) {
        final Object value = object.getValue(i);
        if (value != null) {
            final String name = type.getFieldName(i);
            final DataType dataType = type.getFieldType(i);
            if (dataType instanceof EnumerationDataType) {
                fieldName(name);
                write(value.toString());
                endAttribute();
            } else {
                serializeAttribute(name, value);
            }
            if (this.indentEnabled) {
                endLine();
            }
            if (!this.endElement) {
                if (i < attributeCount - 1) {
                    endLine();
                } else if (type.getName().equals("/Coord3D")) {
                    for (final Object parent : this.scope) {
                        if (parent instanceof Record) {
                            final Record parentObject = (Record) parent;
                            if (parentObject.getRecordDefinition().getName().equals(SaifConstants.TEXT_ON_CURVE)) {
                                endLine();
                            }
                        }
                    }
                } else {
                    endLine();
                }
            }
        }
    }
}
Also used : EnumerationDataType(com.revolsys.datatype.EnumerationDataType) EnumerationDataType(com.revolsys.datatype.EnumerationDataType) DataType(com.revolsys.datatype.DataType) Record(com.revolsys.record.Record) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

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