Search in sources :

Example 56 with Record

use of com.revolsys.record.Record in project com.revolsys.open by revolsys.

the class Json method toString.

public static String toString(final RecordDefinition recordDefinition, final Map<String, ? extends Object> parameters) {
    final Record object = new ArrayRecord(recordDefinition);
    object.setValues(parameters);
    return toString(object);
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord)

Example 57 with Record

use of com.revolsys.record.Record in project com.revolsys.open by revolsys.

the class GpxIterator method parseRoute.

private Record parseRoute() throws XMLStreamException {
    this.index++;
    final Record record = this.recordFactory.newRecord(GpxConstants.GPX_TYPE);
    record.setValue("dataset_name", this.baseName);
    record.setValue("index", this.index);
    record.setValue("feature_type", "rte");
    final List<Record> pointObjects = new ArrayList<>();
    int axisCount = 2;
    while (this.in.nextTag() == XMLStreamConstants.START_ELEMENT) {
        if (this.in.getName().equals(GpxConstants.EXTENSION_ELEMENT)) {
            this.in.skipSubTree();
        } else if (this.in.getName().equals(GpxConstants.ROUTE_POINT_ELEMENT)) {
            final double pointIndex = this.index + (pointObjects.size() + 1.0) / 10000;
            final Record pointObject = parseRoutPoint(pointIndex);
            pointObjects.add(pointObject);
            final Point point = pointObject.getGeometry();
            axisCount = Math.max(axisCount, point.getAxisCount());
        } else {
            parseAttribute(record);
        }
    }
    final int vertexCount = pointObjects.size();
    final double[] coordinates = new double[vertexCount * axisCount];
    for (int i = 0; i < vertexCount; i++) {
        final Record pointObject = pointObjects.get(i);
        final Point point = pointObject.getGeometry();
        CoordinatesListUtil.setCoordinates(coordinates, axisCount, i, point);
    }
    final LineString line;
    if (vertexCount > 1) {
        line = this.geometryFactory.lineString(axisCount, coordinates);
    } else {
        line = this.geometryFactory.lineString();
    }
    record.setGeometryValue(line);
    this.objects.addAll(pointObjects);
    return record;
}
Also used : LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) Record(com.revolsys.record.Record) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 58 with Record

use of com.revolsys.record.Record in project com.revolsys.open by revolsys.

the class DirectionalFields method getMergedRecord.

/**
 * Get a new record that is the result of merging the two records. The
 * attributes will be taken from the record with the longest length. If one
 * line needs to be reversed then the second record will be reversed.
 *
 * @param record1
 * @param record2
 * @return
 */
public Record getMergedRecord(final Point point, final Record record1, Record record2) {
    final LineString line1 = record1.getGeometry();
    LineString line2 = record2.getGeometry();
    Record fromRecord;
    Record toRecord;
    final boolean line1Longer = line1.getLength() > line2.getLength();
    LineString newLine;
    final int lastPoint1 = line1.getVertexCount() - 1;
    final int lastPoint2 = line2.getVertexCount() - 1;
    if (line1.equalsVertex(2, 0, line2, 0) && line1.equalsVertex(2, 0, point)) {
        record2 = getReverse(record2);
        line2 = record2.getGeometry();
        fromRecord = record2;
        toRecord = record1;
        newLine = line1.merge(point, line2);
    } else if (line1.equalsVertex(2, lastPoint1, line2, lastPoint2) && line1.equalsVertex(2, lastPoint1, point)) {
        record2 = getReverse(record2);
        line2 = record2.getGeometry();
        fromRecord = record1;
        toRecord = record2;
        newLine = line1.merge(point, line2);
    } else if (line1.equalsVertex(2, lastPoint1, line2, 0) && line1.equalsVertex(2, lastPoint1, point)) {
        fromRecord = record1;
        toRecord = record2;
        newLine = line1.merge(point, line2);
    } else if (line1.equalsVertex(2, 0, line2, lastPoint2) && line1.equalsVertex(2, 0, point)) {
        fromRecord = record2;
        toRecord = record1;
        newLine = line2.merge(point, line1);
    } else {
        throw new IllegalArgumentException("Lines for records don't touch");
    }
    Record newRecord;
    if (line1Longer) {
        newRecord = Records.copy(record1, newLine);
    } else {
        newRecord = Records.copy(record2, newLine);
    }
    setFromFieldValues(fromRecord, toRecord, newRecord);
    setToFieldValues(toRecord, fromRecord, newRecord);
    LengthFieldName.setRecordLength(newRecord);
    return newRecord;
}
Also used : LineString(com.revolsys.geometry.model.LineString) Record(com.revolsys.record.Record) Point(com.revolsys.geometry.model.Point)

Example 59 with Record

use of com.revolsys.record.Record in project com.revolsys.open by revolsys.

the class DirectionalFields method getMergedMap.

public Map<String, Object> getMergedMap(final Point point, final Record record1, Record record2) {
    final LineString line1 = record1.getGeometry();
    LineString line2 = record2.getGeometry();
    Record fromRecord;
    Record toRecord;
    LineString newLine;
    final Vertex line1From = line1.getVertex(0);
    final Vertex line2From = line2.getVertex(0);
    if (line1From.equals(2, line2From) && line1From.equals(2, point)) {
        record2 = getReverse(record2);
        line2 = record2.getGeometry();
        fromRecord = record2;
        toRecord = record1;
        newLine = line1.merge(point, line2);
    } else {
        final Vertex line1To = line1.getToVertex(0);
        final Vertex line2To = line2.getToVertex(0);
        if (line1To.equals(2, line2To) && line1To.equals(2, point)) {
            record2 = getReverse(record2);
            line2 = record2.getGeometry();
            fromRecord = record1;
            toRecord = record2;
            newLine = line1.merge(point, line2);
        } else if (line1To.equals(2, line2From) && line1To.equals(2, point)) {
            fromRecord = record1;
            toRecord = record2;
            newLine = line1.merge(point, line2);
        } else if (line1From.equals(2, line2To) && line1From.equals(2, point)) {
            fromRecord = record2;
            toRecord = record1;
            newLine = line2.merge(point, line1);
        } else {
            throw new IllegalArgumentException("Lines for records don't touch");
        }
    }
    final Map<String, Object> newValues = new LinkedHashMap<>(record1);
    setFromFieldValues(fromRecord, toRecord, newValues);
    setToFieldValues(toRecord, fromRecord, newValues);
    final RecordDefinition recordDefinition = record1.getRecordDefinition();
    final String geometryFieldName = recordDefinition.getGeometryFieldName();
    newValues.put(geometryFieldName, newLine);
    return newValues;
}
Also used : Vertex(com.revolsys.geometry.model.vertex.Vertex) LineString(com.revolsys.geometry.model.LineString) Record(com.revolsys.record.Record) LineString(com.revolsys.geometry.model.LineString) LinkedHashMap(java.util.LinkedHashMap) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 60 with Record

use of com.revolsys.record.Record in project com.revolsys.open by revolsys.

the class DirectionalFields method getMergedRecord.

/**
 * Get a new record that is the result of merging the two records. The
 * attributes will be taken from the record with the longest length. If one
 * line needs to be reversed then the second record will be reversed.
 *
 * @param record1
 * @param record2
 * @return
 */
public Record getMergedRecord(final Record record1, Record record2) {
    final LineString line1 = record1.getGeometry();
    final int vertexCount1 = line1.getVertexCount();
    LineString line2 = record2.getGeometry();
    final int vertexCount2 = line2.getVertexCount();
    Record fromRecord;
    Record toRecord;
    final boolean line1Longer = line1.getLength() > line2.getLength();
    LineString newLine;
    if (line1.equalsVertex(2, 0, line2, 0)) {
        record2 = getReverse(record2);
        line2 = record2.getGeometry();
        fromRecord = record2;
        toRecord = record1;
        newLine = line1.merge(line2);
    } else if (line1.equalsVertex(2, vertexCount1 - 1, line2, vertexCount2 - 1)) {
        record2 = getReverse(record2);
        line2 = record2.getGeometry();
        fromRecord = record1;
        toRecord = record2;
        newLine = line1.merge(line2);
    } else if (line1.equalsVertex(2, vertexCount1 - 1, line2, 0)) {
        fromRecord = record1;
        toRecord = record2;
        newLine = line1.merge(line2);
    } else if (line1.equalsVertex(2, 0, line2, vertexCount2 - 1)) {
        fromRecord = record2;
        toRecord = record1;
        newLine = line2.merge(line1);
    } else {
        throw new IllegalArgumentException("Lines for records don't touch");
    }
    Record newRecord;
    if (line1Longer) {
        newRecord = Records.copy(record1, newLine);
    } else {
        newRecord = Records.copy(record2, newLine);
    }
    setFromFieldValues(fromRecord, toRecord, newRecord);
    setToFieldValues(toRecord, fromRecord, newRecord);
    LengthFieldName.setRecordLength(newRecord);
    return newRecord;
}
Also used : LineString(com.revolsys.geometry.model.LineString) Record(com.revolsys.record.Record) Point(com.revolsys.geometry.model.Point)

Aggregations

Record (com.revolsys.record.Record)198 ArrayRecord (com.revolsys.record.ArrayRecord)43 RecordReader (com.revolsys.record.io.RecordReader)34 RecordDefinition (com.revolsys.record.schema.RecordDefinition)34 Geometry (com.revolsys.geometry.model.Geometry)29 LineString (com.revolsys.geometry.model.LineString)21 Point (com.revolsys.geometry.model.Point)20 ChannelWriter (com.revolsys.io.channels.ChannelWriter)19 Identifier (com.revolsys.identifier.Identifier)17 ArrayList (java.util.ArrayList)16 FieldDefinition (com.revolsys.record.schema.FieldDefinition)15 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)14 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)13 NoSuchElementException (java.util.NoSuchElementException)13 DataType (com.revolsys.datatype.DataType)10 Query (com.revolsys.record.query.Query)9 HashMap (java.util.HashMap)9 List (java.util.List)8 LinkedHashMap (java.util.LinkedHashMap)7 Edge (com.revolsys.geometry.graph.Edge)6