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);
}
}
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);
}
}
}
}
}
}
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;
}
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);
}
}
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();
}
}
}
}
}
Aggregations