Search in sources :

Example 1 with RecordGraph

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);
    }
}
Also used : RecordGraph(com.revolsys.geometry.graph.RecordGraph)

Example 2 with RecordGraph

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;
}
Also used : RecordGraph(com.revolsys.geometry.graph.RecordGraph) Record(com.revolsys.record.Record)

Example 3 with RecordGraph

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);
    }
}
Also used : RecordGraph(com.revolsys.geometry.graph.RecordGraph) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ArrayRecord(com.revolsys.record.ArrayRecord) Node(com.revolsys.geometry.graph.Node) LineString(com.revolsys.geometry.model.LineString) Geometry(com.revolsys.geometry.model.Geometry) LineString(com.revolsys.geometry.model.LineString) DataType(com.revolsys.datatype.DataType) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) List(java.util.List) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) Edge(com.revolsys.geometry.graph.Edge)

Aggregations

RecordGraph (com.revolsys.geometry.graph.RecordGraph)3 Record (com.revolsys.record.Record)2 DataType (com.revolsys.datatype.DataType)1 Edge (com.revolsys.geometry.graph.Edge)1 Node (com.revolsys.geometry.graph.Node)1 Geometry (com.revolsys.geometry.model.Geometry)1 LineString (com.revolsys.geometry.model.LineString)1 ArrayRecord (com.revolsys.record.ArrayRecord)1 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Set (java.util.Set)1