Search in sources :

Example 11 with ArrayRecord

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);
    });
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) PathResource(com.revolsys.spring.resource.PathResource) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) RecordWriterFactory(com.revolsys.record.io.RecordWriterFactory) File(java.io.File)

Example 12 with ArrayRecord

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);
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) ArrayRecord(com.revolsys.record.ArrayRecord) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 13 with ArrayRecord

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;
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) ArrayList(java.util.ArrayList) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord)

Example 14 with ArrayRecord

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);
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) ArrayRecord(com.revolsys.record.ArrayRecord) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) DirectionalFields(com.revolsys.record.property.DirectionalFields)

Example 15 with ArrayRecord

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);
    }
}
Also used : ListRecordReader(com.revolsys.record.io.ListRecordReader) RecordReaderTransferable(com.revolsys.swing.dnd.transferable.RecordReaderTransferable) ArrayRecord(com.revolsys.record.ArrayRecord) RecordReader(com.revolsys.record.io.RecordReader) ListRecordReader(com.revolsys.record.io.ListRecordReader) ArrayList(java.util.ArrayList) ArrayRecord(com.revolsys.record.ArrayRecord) Record(com.revolsys.record.Record) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

ArrayRecord (com.revolsys.record.ArrayRecord)19 Record (com.revolsys.record.Record)15 Geometry (com.revolsys.geometry.model.Geometry)5 FieldDefinition (com.revolsys.record.schema.FieldDefinition)5 RecordDefinition (com.revolsys.record.schema.RecordDefinition)5 DataType (com.revolsys.datatype.DataType)4 LineString (com.revolsys.geometry.model.LineString)2 RecordReader (com.revolsys.record.io.RecordReader)2 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)2 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 NoSuchElementException (java.util.NoSuchElementException)2 Bindings (javax.script.Bindings)2 MapEx (com.revolsys.collection.map.MapEx)1 Edge (com.revolsys.geometry.graph.Edge)1 Node (com.revolsys.geometry.graph.Node)1 RecordGraph (com.revolsys.geometry.graph.RecordGraph)1 ClockDirection (com.revolsys.geometry.model.ClockDirection)1 Point (com.revolsys.geometry.model.Point)1