Beanshell:Combine two selected layers

From OpenJUMP Wiki
Jump to: navigation, search

Combine two selected layers (untested)

{
firstLayer = wc.layerViewPanel.selectionManager.layersWithSelectedItems.iterator().next();
firstFeature = wc.layerViewPanel.selectionManager.getFeaturesWithSelectedItems(firstLayer).iterator().next();
for (feature : wc.layerViewPanel.selectionManager.featuresWithSelectedItems) {
 firstFeature.geometry = firstFeature.geometry.union(feature.geometry);
}
for (layer : wc.layerViewPanel.selectionManager.layersWithSelectedItems){
  layer.featureCollectionWrapper.removeAll(wc.layerViewPanel.selectionManager.getFeaturesWithSelectedItems(layer));
  }
firstLayer.featureCollectionWrapper.add(firstFeature);
wc.layerViewPanel.repaint();
}