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