use of com.revolsys.geometry.graph.RecordGraph in project com.revolsys.open by revolsys.
the class GraphProcessor method init.
@Override
protected void init() {
super.init();
this.graph = new RecordGraph();
if (this.precisionModel != null) {
this.graph.setPrecisionModel(this.precisionModel);
}
}
use of com.revolsys.geometry.graph.RecordGraph in project com.revolsys.open by revolsys.
the class RecordPseudoNodeRemovalVisitor method mergeEdges.
protected Edge<Record> mergeEdges(final Node<Record> node, final Edge<Record> edge1, final Edge<Record> edge2) {
final Record object1 = edge1.getObject();
final Record object2 = edge2.getObject();
final Record newObject = mergeObjects(node, object1, object2);
// newObject.setIdValue(null);
final RecordGraph graph = (RecordGraph) edge1.getGraph();
final Edge<Record> newEdge = graph.addEdge(newObject);
graph.remove(edge1);
graph.remove(edge2);
return newEdge;
}
use of com.revolsys.geometry.graph.RecordGraph in project com.revolsys.open by revolsys.
the class MergeRecordsDialog method run.
public void run() {
try {
final List<LayerRecord> originalRecords = this.layer.getMergeableSelectedRecords();
String errorMessage = "";
final DataType geometryType = this.layer.getGeometryType();
this.mergedRecords = new HashMap<>();
if (originalRecords.size() < 2) {
errorMessage = " at least two records must be selected to merge.";
} else if (!DataTypes.LINE_STRING.equals(geometryType) && !DataTypes.MULTI_LINE_STRING.equals(geometryType)) {
errorMessage = "Merging " + geometryType + " not currently supported";
} else {
final RecordGraph graph = new RecordGraph();
for (final LayerRecord originalRecord : originalRecords) {
Geometry geometry = originalRecord.getGeometry();
if (geometry != null && !geometry.isEmpty()) {
geometry = this.layer.getGeometryFactory().geometry(LineString.class, geometry);
if (geometry instanceof LineString) {
final Record mergeableRecord = new ArrayRecord(originalRecord);
mergeableRecord.setGeometryValue(geometry);
this.mergeableToOiginalRecordMap.put(mergeableRecord, originalRecord);
graph.addEdge(mergeableRecord);
}
}
}
for (final Node<Record> node : graph.nodes()) {
if (node != null) {
final List<Edge<Record>> edges = node.getEdges();
if (edges.size() == 2) {
final Edge<Record> edge1 = edges.get(0);
final Record record1 = edge1.getObject();
final Edge<Record> edge2 = edges.get(1);
final Record record2 = edge2.getObject();
if (record1 != record2) {
final Record mergedRecord = this.layer.getMergedRecord(node, record1, record2);
graph.addEdge(mergedRecord);
edge1.remove();
edge2.remove();
final Set<LayerRecord> sourceRecords = new LinkedHashSet<>();
// TODO verify orientation to ensure they are in the correct
// order
// and see if they are reversed
CollectionUtil.addIfNotNull(sourceRecords, this.mergeableToOiginalRecordMap.get(record1));
CollectionUtil.addAllIfNotNull(sourceRecords, this.mergedRecords.remove(record1));
CollectionUtil.addIfNotNull(sourceRecords, this.mergeableToOiginalRecordMap.get(record2));
CollectionUtil.addAllIfNotNull(sourceRecords, this.mergedRecords.remove(record2));
this.mergedRecords.put(mergedRecord, sourceRecords);
replaceRecord(mergedRecord, record1);
replaceRecord(mergedRecord, record2);
}
}
}
}
}
final String message = errorMessage;
Invoke.later(() -> setMergedRecords(message, this.mergedRecords));
} catch (final Throwable e) {
Logs.error(this, "Error " + this, e);
}
}
Aggregations