use of com.revolsys.record.ArrayRecord in project com.revolsys.open by revolsys.
the class RecordIoTestSuite method addWriteReadTest.
public static void addWriteReadTest(final TestSuite suite, final String prefix, final String fileExtension) {
addGeometryTestSuites(suite, prefix, (geometryFactory, geometry, geometryDataType) -> {
final String geometryTypeString = geometryDataType.toString();
final File directory = new File("/tmp/revolsystest/io/" + fileExtension);
final File file = new File(directory, geometryTypeString + "_" + geometryFactory.getAxisCount() + "_" + geometry.getVertexCount() + "." + fileExtension);
file.delete();
file.getParentFile().mkdirs();
final PathResource resource = new PathResource(file);
final RecordWriterFactory recordWriterFactory = IoFactory.factory(RecordWriterFactory.class, resource);
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(PathName.newPathName(geometryTypeString));
if (recordWriterFactory.isCustomFieldsSupported()) {
recordDefinition.addField("BOOLEAN", DataTypes.BOOLEAN, true);
recordDefinition.addField("BYTE", DataTypes.BYTE, true);
recordDefinition.addField("SHORT", DataTypes.SHORT, true);
recordDefinition.addField("INT", DataTypes.INT, true);
recordDefinition.addField("LONG", DataTypes.LONG, true);
recordDefinition.addField("FLOAT", DataTypes.FLOAT, 4, 3, true);
recordDefinition.addField("DOUBLE", DataTypes.DOUBLE, 10, 9, true);
recordDefinition.addField("STRING", DataTypes.STRING, true);
}
if (recordWriterFactory.isGeometrySupported()) {
recordDefinition.addField("GEOMETRY", geometryDataType, true);
}
recordDefinition.setGeometryFactory(geometryFactory);
final ArrayRecord record = new ArrayRecord(recordDefinition);
record.setValue("BOOLEAN", true);
record.setValue("BYTE", Byte.MAX_VALUE);
record.setValue("SHORT", Short.MAX_VALUE);
record.setValue("INT", Integer.MAX_VALUE);
record.setValue("LONG", 999999999999999999L);
record.setValue("FLOAT", 6.789);
record.setValue("DOUBLE", 1.234567890);
record.setValue("STRING", "test");
record.setGeometryValue(geometry);
doRecordWriteTest(resource, record);
doRecordReadTest(resource, record);
doGeometryReadTest(resource, record);
});
}
use of com.revolsys.record.ArrayRecord in project com.revolsys.open by revolsys.
the class CreateObjectsWithinDistanceOfGeometry method process.
@Override
protected void process(final Channel<Record> in, final Channel<Record> out, final Record object) {
if (this.writeOriginal) {
out.write(object);
}
final RecordDefinition recordDefinition = object.getRecordDefinition();
final Geometry geometryValue = object.getGeometry();
final Map<RecordDefinition, Geometry> recordDefinitionGeometries = getRecordDefinitionGeometries(recordDefinition);
for (final Entry<RecordDefinition, Geometry> recordDefinitionGeometry : recordDefinitionGeometries.entrySet()) {
final RecordDefinition newRecordDefinition = recordDefinitionGeometry.getKey();
final Geometry intersectsGeometry = recordDefinitionGeometry.getValue();
if (intersectsGeometry.intersects(geometryValue)) {
final Record newRecord = new ArrayRecord(newRecordDefinition, object);
out.write(newRecord);
}
}
}
use of com.revolsys.record.ArrayRecord in project com.revolsys.open by revolsys.
the class EsriXmlRecordDefinitionUtil method getValues.
public static List<Record> getValues(final RecordDefinition recordDefinition, final Domain domain) {
final List<Record> values = new ArrayList<>();
for (final CodedValue codedValue : domain.getCodedValues()) {
final Record value = new ArrayRecord(recordDefinition);
value.setIdentifier(Identifier.newIdentifier(codedValue.getCode()));
value.setValue("DESCRIPTION", codedValue.getName());
values.add(value);
}
return values;
}
use of com.revolsys.record.ArrayRecord in project com.revolsys.open by revolsys.
the class AbstractRecordLayer method getMergedRecord.
/**
* Get a record containing the values of the two records if they can be
* merged. The new record is not a layer data object so would need to be
* added, likewise the old records are not removed so they would need to be
* deleted.
*
* @param point
* @param record1
* @param record2
* @return
*/
public Record getMergedRecord(final Point point, final Record record1, final Record record2) {
if (record1 == record2) {
return record1;
} else {
final String sourceIdFieldName = getIdFieldName();
final Object id1 = record1.getValue(sourceIdFieldName);
final Object id2 = record2.getValue(sourceIdFieldName);
int compare = 0;
if (id1 == null) {
if (id2 != null) {
compare = 1;
}
} else if (id2 == null) {
compare = -1;
} else {
compare = CompareUtil.compare(id1, id2);
}
if (compare == 0) {
final Geometry geometry1 = record1.getGeometry();
final Geometry geometry2 = record2.getGeometry();
final double length1 = geometry1.getLength();
final double length2 = geometry2.getLength();
if (length1 == length2) {
compare = Integer.compare(System.identityHashCode(record1), System.identityHashCode(record2));
} else if (length1 > length2) {
compare = -1;
} else {
compare = 1;
}
}
if (compare > 0) {
return getMergedRecord(point, record2, record1);
} else {
final DirectionalFields property = DirectionalFields.getProperty(getRecordDefinition());
final Map<String, Object> newValues = property.getMergedMap(point, record1, record2);
newValues.remove(getIdFieldName());
return new ArrayRecord(getRecordDefinition(), newValues);
}
}
}
use of com.revolsys.record.ArrayRecord in project com.revolsys.open by revolsys.
the class AbstractRecordLayer method copyRecordsToClipboard.
public void copyRecordsToClipboard(final List<LayerRecord> records) {
if (!records.isEmpty()) {
final RecordDefinition recordDefinition = getRecordDefinition();
final List<Record> copies = new ArrayList<>();
for (final LayerRecord record : records) {
final ArrayRecord recordCopy = new ArrayRecord(recordDefinition, record);
copies.add(recordCopy);
}
final RecordReader reader = new ListRecordReader(recordDefinition, copies);
final RecordReaderTransferable transferable = new RecordReaderTransferable(reader);
ClipboardUtil.setContents(transferable);
}
}
Aggregations