Beanshell:Create linestring from points with id attribute

From OpenJUMP Wiki
Revision as of 08:12, 14 September 2016 by Michaudm (talk | contribs) (Created page with "{ import com.vividsolutions.jump.workbench.ui.*; // Create a dialog box to get the layer to be processed // and the attribute containing the sequence dialog = new MultiInput...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

{

import com.vividsolutions.jump.workbench.ui.*;

// Create a dialog box to get the layer to be processed // and the attribute containing the sequence dialog = new MultiInputDialog(wc.workbench.frame, "Input box", true); dialog.addLayerComboBox("LAYER", wc.createPlugInContext().getCandidateLayer(0), "", wc.layerManager); dialog.addAttributeComboBox("SEQUENCE", "LAYER", AttributeTypeFilter.NUMSTRING_FILTER, "Select the attribute containing the sequence"); GUIUtil.centreOnWindow(dialog); dialog.setVisible(true); if (!dialog.wasOKPressed()) {return;}

// get the user choice lyr = dialog.getLayer("LAYER"); att = dialog.getComboBox("SEQUENCE").selectedItem;

// Create a new layer schema = new FeatureSchema(); schema.addAttribute("GEOMETRY",AttributeType.GEOMETRY); dataset = new FeatureDataset(schema);

// Process input data map = new TreeMap(); int i = 0; for (feature : lyr.featureCollectionWrapper.features) {

   if (feature.schema.hasAttribute(att)) {
        map.put(feature.getAttribute(att), feature.geometry.coordinate);
   }
   else map.put(i++, feature.geometry.coordinate);

} geometry = new GeometryFactory().createLineString(map.values().toArray(new Coordinate[map.size()])); f = new BasicFeature(schema); f.setGeometry(geometry); dataset.add(f); wc.layerManager.addLayer("Result",lyr.name+"-line",dataset);

}