Search in sources :

Example 61 with LayerRecord

use of com.revolsys.swing.map.layer.record.LayerRecord 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)

Example 62 with LayerRecord

use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.

the class MergeRecordsDialog method finish.

public void finish() {
    final MultipleUndo multipleUndo = new MultipleUndo();
    for (final Record mergedRecord : this.mergedRecords.keySet()) {
        final CreateRecordUndo createRecordUndo = new CreateRecordUndo(this.layer, mergedRecord);
        multipleUndo.addEdit(createRecordUndo);
    }
    for (final LayerRecord record : this.replacedOriginalRecords) {
        final DeleteLayerRecordUndo deleteRecordUndo = new DeleteLayerRecordUndo(record);
        multipleUndo.addEdit(deleteRecordUndo);
    }
    if (this.undoManager == null) {
        multipleUndo.redo();
    } else {
        this.undoManager.addEdit(multipleUndo);
    }
    setVisible(false);
}
Also used : CreateRecordUndo(com.revolsys.swing.undo.CreateRecordUndo) DeleteLayerRecordUndo(com.revolsys.swing.undo.DeleteLayerRecordUndo) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) MultipleUndo(com.revolsys.swing.undo.MultipleUndo)

Example 63 with LayerRecord

use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.

the class ModeAbstractCached method forEachRecord.

@Override
public void forEachRecord(final Query query, final Consumer<? super LayerRecord> action) {
    final Condition filter = query.getWhereCondition();
    final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
    final AbstractRecordLayer layer = getLayer();
    final Iterable<LayerRecord> records = new ListByIndexIterator<>(this.records);
    layer.forEachRecord(records, filter, orderBy, action);
}
Also used : Condition(com.revolsys.record.query.Condition) ListByIndexIterator(com.revolsys.collection.list.ListByIndexIterator) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord)

Example 64 with LayerRecord

use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.

the class ModeAllPaged method getRecordDo.

@Override
protected LayerRecord getRecordDo(final int row) {
    final int recordCountChanges = super.getRecordCount();
    if (row >= 0) {
        if (row < recordCountChanges) {
            return super.getRecordDo(row);
        } else {
            final int persistedRow = row - recordCountChanges;
            final int recordCount = getRecordCount();
            if (row < recordCount) {
                final int pageNumber = persistedRow / this.pageSize;
                final int recordNumber = persistedRow % this.pageSize;
                final LayerRecord record = getRecordPagePersisted(pageNumber, recordNumber);
                return record;
            }
        }
    }
    return null;
}
Also used : LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord)

Example 65 with LayerRecord

use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.

the class EditRecordGeometryOverlay method addRecords.

private void addRecords(final List<LayerRecord> results, final LayerGroup group, final Geometry boundingBox) {
    final double scale = getViewportScale();
    final List<Layer> layers = group.getLayers();
    Collections.reverse(layers);
    for (final Layer layer : layers) {
        if (layer instanceof LayerGroup) {
            final LayerGroup childGroup = (LayerGroup) layer;
            addRecords(results, childGroup, boundingBox);
        } else if (layer instanceof AbstractRecordLayer) {
            final AbstractRecordLayer recordLayer = (AbstractRecordLayer) layer;
            if (recordLayer.isSelectable(scale)) {
                final List<LayerRecord> selectedRecords = recordLayer.getSelectedRecords();
                for (final LayerRecord selectedRecord : selectedRecords) {
                    final Geometry geometry = selectedRecord.getGeometry();
                    if (boundingBox.intersects(geometry)) {
                        results.add(selectedRecord);
                    }
                }
            }
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) List(java.util.List) ArrayList(java.util.ArrayList) LayerGroup(com.revolsys.swing.map.layer.LayerGroup) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) ElevationModelLayer(com.revolsys.swing.map.layer.elevation.ElevationModelLayer) Layer(com.revolsys.swing.map.layer.Layer) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) AbstractLayer(com.revolsys.swing.map.layer.AbstractLayer)

Aggregations

LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)79 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)34 Geometry (com.revolsys.geometry.model.Geometry)15 IdentifierProxyLayerRecord (com.revolsys.swing.map.layer.record.IdentifierProxyLayerRecord)15 NewProxyLayerRecord (com.revolsys.swing.map.layer.record.NewProxyLayerRecord)15 BoundingBox (com.revolsys.geometry.model.BoundingBox)11 Record (com.revolsys.record.Record)11 ArrayList (java.util.ArrayList)11 List (java.util.List)10 Test (org.junit.Test)10 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)7 Point (com.revolsys.geometry.model.Point)6 Condition (com.revolsys.record.query.Condition)4 LayerRecordMenu (com.revolsys.swing.map.layer.record.LayerRecordMenu)4 CloseLocation (com.revolsys.swing.map.overlay.CloseLocation)4 RecordRowTable (com.revolsys.swing.table.record.RecordRowTable)4 LineString (com.revolsys.geometry.model.LineString)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 AbstractLayer (com.revolsys.swing.map.layer.AbstractLayer)3 Layer (com.revolsys.swing.map.layer.Layer)3