Difference between revisions of "Beanshell:Create linestring from points with id attribute"
Jump to navigation
Jump to search
(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...") |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | BeanTools with user interface to create a LineString from points with an attribute | |
| + | containing the order of points | ||
| − | |||
| − | + | { | |
| − | // | + | |
| − | dialog = new MultiInputDialog(wc.workbench.frame, "Input box", true); | + | import com.vividsolutions.jump.workbench.ui.*; |
| − | dialog.addLayerComboBox("LAYER", wc.createPlugInContext().getCandidateLayer(0), "", wc.layerManager); | + | |
| − | dialog.addAttributeComboBox("SEQUENCE", "LAYER", AttributeTypeFilter.NUMSTRING_FILTER, "Select the attribute containing the sequence"); | + | // User interface |
| − | GUIUtil.centreOnWindow(dialog); | + | dialog = new MultiInputDialog(wc.workbench.frame, "Input box", true); |
| − | dialog.setVisible(true); | + | dialog.addLayerComboBox("LAYER", wc.createPlugInContext().getCandidateLayer(0), "", wc.layerManager); |
| − | if (!dialog.wasOKPressed()) {return;} | + | dialog.addAttributeComboBox("SEQUENCE", "LAYER", AttributeTypeFilter.NUMSTRING_FILTER, "Select the attribute containing the sequence"); |
| − | + | GUIUtil.centreOnWindow(dialog); | |
| − | // get | + | dialog.setVisible(true); |
| − | lyr = dialog.getLayer("LAYER"); | + | if (!dialog.wasOKPressed()) {return;} |
| − | att = dialog.getComboBox("SEQUENCE").selectedItem; | + | |
| − | + | // get parameters | |
| − | // Create | + | lyr = dialog.getLayer("LAYER"); |
| − | schema = new FeatureSchema(); | + | att = dialog.getComboBox("SEQUENCE").selectedItem; |
| − | schema.addAttribute("GEOMETRY",AttributeType.GEOMETRY); | + | |
| − | dataset = new FeatureDataset(schema | + | // Create new dataset |
| − | + | schema = new FeatureSchema(); | |
| − | + | schema.addAttribute("GEOMETRY",AttributeType.GEOMETRY); | |
| − | + | dataset = new FeatureDataset(schema); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | } | + | // Processing 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); | ||
| + | |||
| + | } | ||
Latest revision as of 07:20, 14 September 2016
BeanTools with user interface to create a LineString from points with an attribute containing the order of points
{
import com.vividsolutions.jump.workbench.ui.*;
// User interface
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 parameters
lyr = dialog.getLayer("LAYER");
att = dialog.getComboBox("SEQUENCE").selectedItem;
// Create new dataset
schema = new FeatureSchema();
schema.addAttribute("GEOMETRY",AttributeType.GEOMETRY);
dataset = new FeatureDataset(schema);
// Processing 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);
}