Changeset 6949 in osm for applications/editors/josm/plugins
- Timestamp:
- 2008-02-22T09:49:07+01:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/Lakewalker.java
r6923 r6949 223 223 public ArrayList<double[]> duplicateNodeRemove(ArrayList<double[]> nodes){ 224 224 225 if(nodes.size() <= 1){ 226 return nodes; 227 } 228 225 229 double lastnode[] = new double[] {nodes.get(0)[0], nodes.get(0)[1]}; 226 230 … … 251 255 252 256 // Check if node list is empty 253 if(nodes.size() ==0){257 if(nodes.size()<=1){ 254 258 return nodes; 255 259 } … … 286 290 } 287 291 292 public ArrayList<double[]> douglasPeuckerNR(ArrayList<double[]> nodes, double epsilon){ 293 /* 294 command_stack = [(0, len(nodes) - 1)] 295 296 Vector result_stack = new Vector(); 297 298 while(command_stack.size() > 0){ 299 cmd = command_stack.pop(); 300 if(type(cmd) == tuple){ 301 (start, end) = cmd 302 (node, dist) = dp_findpoint(nodes, start, end) 303 if(dist > epsilon){ 304 command_stack.append("+") 305 command_stack.append((start, node)) 306 command_stack.append((node, end)) 307 } else { 308 result_stack.append((start, end)) 309 } 310 } elseif(cmd == "+"){ 311 first = result_stack.pop() 312 second = result_stack.pop() 313 if(first[-1] == second[0]){ 314 result_stack.append(first + second[1:]) 315 //print "Added %s and %s; result is %s" % (first, second, result_stack[-1]) 316 }else { 317 error("ERROR: Cannot connect nodestrings!") 318 #print first 319 #print second 320 return; 321 } 322 } else { 323 error("ERROR: Can't understand command \"%s\"" % (cmd,)) 324 return 325 326 if(len(result_stack) == 1){ 327 return [nodes[x] for x in result_stack[0]]; 328 } else { 329 error("ERROR: Command stack is empty but result stack has %d nodes!" % len(result_stack)); 330 return; 331 } 332 333 farthest_node = None 334 farthest_dist = 0 335 first = nodes[0] 336 last = nodes[-1] 337 338 for(i in xrange(1, len(nodes) - 1){ 339 d = point_line_distance(nodes[i], first, last) 340 if(d > farthest_dist){ 341 farthest_dist = d 342 farthest_node = i 343 } 344 } 345 if(farthest_dist > epsilon){ 346 seg_a = douglas_peucker(nodes[0:farthest_node+1], epsilon) 347 seg_b = douglas_peucker(nodes[farthest_node:-1], epsilon) 348 //print "Minimized %d nodes to %d + %d nodes" % (len(nodes), len(seg_a), len(seg_b)) 349 nodes = seg_a[:-1] + seg_b 350 } else { 351 return [nodes[0], nodes[-1]]; 352 } 353 */ 354 return nodes; 355 } 356 288 357 public ArrayList<double[]> douglasPeucker(ArrayList<double[]> nodes, double epsilon){ 289 358 290 359 // Check if node list is empty 291 if(nodes.size() ==0){360 if(nodes.size()<=1){ 292 361 return nodes; 293 362 } -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerAction.java
r6923 r6949 106 106 final int waylen = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_MAX_SEG, "500")); 107 107 final int maxnode = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_MAX_NODES, "50000")); 108 final int threshold = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_THRESHOLD , "35"));108 final int threshold = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_THRESHOLD_VALUE, "90")); 109 109 final double epsilon = Double.parseDouble(Main.pref.get(LakewalkerPreferences.PREF_EPSILON, "0.0003")); 110 110 final int resolution = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_LANDSAT_RES, "4000")); -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerActionOld.java
r6910 r6949 40 40 41 41 public LakewalkerActionOld(String name) { 42 super(name, "lakewalker-sml", tr("Lake Walker ."), KeyEvent.VK_L,KeyEvent.CTRL_MASK43 | KeyEvent.SHIFT_MASK, true);42 super(name, "lakewalker-sml", tr("Lake Walker (Old)"), KeyEvent.VK_L, KeyEvent.ALT_MASK | KeyEvent.CTRL_MASK 43 | KeyEvent.SHIFT_MASK, false); 44 44 this.name = name; 45 45 setEnabled(true); -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPlugin.java
r6910 r6949 36 36 if (toolsMenu == null) { 37 37 toolsMenu = new JMenu(name); 38 toolsMenu.add(new JMenuItem(new LakewalkerActionOld(name2))); 38 39 toolsMenu.add(new JMenuItem(new LakewalkerAction(name))); 39 40 Main.main.menu.add(toolsMenu, 2); -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPreferences.java
r6874 r6949 21 21 public static final String PREF_MAX_NODES = "lakewalker.max_nodes"; 22 22 public static final String PREF_THRESHOLD = "lakewalker.threshold"; 23 public static final String PREF_THRESHOLD_VALUE = "lakewalker.thresholdvalue"; 23 24 public static final String PREF_EPSILON = "lakewalker.epsilon"; 24 25 public static final String PREF_LANDSAT_RES = "lakewalker.landsat_res"; … … 37 38 protected JLabel maxNodesLabel = new JLabel(tr("Maximum number of nodes in initial trace")); 38 39 protected IntConfigurer thresholdConfig = new IntConfigurer(); 39 protected JLabel thresholdLabel = new JLabel(tr("Maximum gray value to count as water (0-255)")); 40 protected JLabel thresholdLabel = new JLabel(tr("Maximum gray value to count as water (0-255) [For old script]")); 41 protected IntConfigurer thresholdConfigNew = new IntConfigurer(); 42 protected JLabel thresholdLabelNew = new JLabel(tr("Maximum gray value to count as water (0-255)")); 40 43 protected DoubleConfigurer epsilonConfig = new DoubleConfigurer(); 41 44 protected JLabel epsilonLabel = new JLabel(tr("Line simplification accuracy (degrees)")); … … 60 63 maxNodesConfig.setToolTipText(tr("Maximum number of nodes to generate before bailing out (before simplifying lines). Default 50000.")); 61 64 thresholdConfig.setToolTipText(tr("Maximum gray value to accept as water (based on Landsat IR-1 data). Can be in the range 0-255. Default 35.")); 65 thresholdConfigNew.setToolTipText(tr("Maximum gray value to accept as water (based on Landsat IR-1 data). Can be in the range 0-255. Default 90.")); 62 66 epsilonConfig.setToolTipText(tr("Accuracy of Douglas-Peucker line simplification, measured in degrees.<br>Lower values give more nodes, and more accurate lines. Default 0.0003.")); 63 67 landsatResConfig.setToolTipText(tr("Resolution of Landsat tiles, measured in pixels per degree. Default 4000.")); … … 77 81 maxNodesConfig.setValue(Main.pref.get(PREF_MAX_NODES, "50000")); 78 82 thresholdConfig.setValue(Main.pref.get(PREF_THRESHOLD, "35")); 83 thresholdConfigNew.setValue(Main.pref.get(PREF_THRESHOLD_VALUE, "90")); 79 84 epsilonConfig.setValue(Main.pref.get(PREF_EPSILON, "0.0003")); 80 85 landsatResConfig.setValue(Main.pref.get(PREF_LANDSAT_RES, "4000")); … … 99 104 prefPanel.add(thresholdLabel, labelConstraints); 100 105 prefPanel.add(thresholdConfig.getControls(), dataConstraints); 106 prefPanel.add(thresholdLabelNew, labelConstraints); 107 prefPanel.add(thresholdConfigNew.getControls(), dataConstraints); 101 108 prefPanel.add(epsilonLabel, labelConstraints); 102 109 prefPanel.add(epsilonConfig.getControls(), dataConstraints); … … 125 132 Main.pref.put(PREF_MAX_NODES, maxNodesConfig.getValueString()); 126 133 Main.pref.put(PREF_THRESHOLD, thresholdConfig.getValueString()); 134 Main.pref.put(PREF_THRESHOLD_VALUE, thresholdConfigNew.getValueString()); 127 135 Main.pref.put(PREF_EPSILON, epsilonConfig.getValueString()); 128 136 Main.pref.put(PREF_LANDSAT_RES, landsatResConfig.getValueString());
Note:
See TracChangeset
for help on using the changeset viewer.