Changeset 4095 in osm for applications
- Timestamp:
- 2007-08-13T12:55:42+02:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/lakewalker
- Files:
-
- 5 added
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/lakewalker/README
r4071 r4095 1 1 A JOSM plugin to interface to Darryl Shpak's Lakewalker module 2 2 3 - On-screen feedback to Lakewalker progress 3 - On-screen feedback to Lakewalker progress with cancel 4 4 - Tag ways appropriately 5 5 - limit ways to length 6 6 - Access all lakewalker options via preferences and via ctrl-click pop-up dialog 7 7 - Manage Landsat image cache from Prefs screen 8 - Read data in thread 8 9 - ... -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerAction.java
r4071 r4095 12 12 import java.io.File; 13 13 import java.io.InputStreamReader; 14 import java.nio.channels.ClosedByInterruptException; 14 15 import java.util.ArrayList; 15 16 import java.util.Collection; … … 18 19 19 20 import javax.swing.JOptionPane; 21 import javax.swing.ProgressMonitor; 20 22 21 23 import org.openstreetmap.josm.Main; … … 29 31 import org.openstreetmap.josm.data.osm.Segment; 30 32 import org.openstreetmap.josm.data.osm.Way; 33 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 31 34 import org.openstreetmap.josm.tools.ImageProvider; 35 import org.xml.sax.SAXException; 32 36 33 37 /** … … 42 46 protected Cursor oldCursor; 43 47 protected List<Node> selectedNodes; 44 48 45 49 public LakewalkerAction(String name) { 46 50 super(name, "lakewalker-sml", tr("Lake Walker."), KeyEvent.VK_L, KeyEvent.CTRL_MASK … … 48 52 this.name = name; 49 53 setEnabled(true); 54 50 55 } 51 56 … … 53 58 54 59 Main.map.mapView.setCursor(oldCursor); 55 60 56 61 if (Main.map == null) { 57 62 JOptionPane.showMessageDialog(Main.parent, tr("No data loaded.")); 58 63 return; 59 64 } 60 65 61 66 selectedNodes = new ArrayList<Node>(); 62 67 for (OsmPrimitive osm : Main.ds.getSelected()) { … … 76 81 } 77 82 } 78 83 79 84 protected void lakewalk(Point clickPoint) { 80 LatLon pos = Main.map.mapView.getLatLon(clickPoint.x, clickPoint.y); 81 String line; 82 83 File working_dir = new File (Main.pref.getPreferencesDir(), "plugins"); 84 working_dir = new File(working_dir, "Lakewalker"); 85 String target = Main.pref.get(LakewalkerPlugin.PREF_PYTHON) + " lakewalker.py"; 86 LatLon topLeft = Main.map.mapView.getLatLon(0, 0); 87 LatLon botRight = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), Main.map.mapView.getHeight()); 88 89 target += " --lat=" + pos.lat(); 90 target += " --lon=" + pos.lon(); 91 target += " --left=" + topLeft.lon(); 92 target += " --right=" + botRight.lon(); 93 target += " --top=" + topLeft.lat(); 94 target += " --bottom=" + botRight.lat(); 95 target += " --josm"; 96 97 Collection<Command> commands = new LinkedList<Command>(); 98 Way way = new Way(); 99 Node lastNode = null; 100 Node firstNode = null; 101 102 try 103 { 104 Runtime rt = Runtime.getRuntime(); 105 System.out.println("dir: "+working_dir+", target: "+target); 106 Process p = rt.exec(target, null, working_dir); 107 System.out.println("Just Run"); 108 BufferedReader input = 109 110 new BufferedReader 111 112 (new InputStreamReader(p.getInputStream())); 113 BufferedReader err = new BufferedReader(new InputStreamReader (p.getErrorStream())) ; 85 LatLon pos = Main.map.mapView.getLatLon(clickPoint.x, clickPoint.y); 86 87 /* 88 * Collect options 89 */ 90 File working_dir = new File(Main.pref.getPreferencesDir(), "plugins"); 91 working_dir = new File(working_dir, "Lakewalker"); 92 String target = Main.pref.get(LakewalkerPreferences.PREF_PYTHON) + " lakewalker.py"; 93 LatLon topLeft = Main.map.mapView.getLatLon(0, 0); 94 LatLon botRight = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), Main.map.mapView 95 .getHeight()); 96 97 /* 98 * Build command line 99 */ 100 target += " --lat=" + pos.lat(); 101 target += " --lon=" + pos.lon(); 102 target += " --left=" + topLeft.lon(); 103 target += " --right=" + botRight.lon(); 104 target += " --top=" + topLeft.lat(); 105 target += " --bottom=" + botRight.lat(); 106 target += " --maxnodes=" + Main.pref.get(LakewalkerPreferences.PREF_MAX_NODES, "50000"); 107 target += " --threshold=" + Main.pref.get(LakewalkerPreferences.PREF_THRESHOLD, "35"); 108 target += " --josm"; 109 110 114 111 115 /* 116 * Lakewalker will output data it stdout. Each line has a code 117 * in character 1 indicating the type of data on the line: 118 * 119 * m text - Status message 120 * l name [size] - Access landsat image name. size is returned if it needs to be downloaded. 121 * e text - Error message 122 * s nnn - Start node data stream, nnn seperate tracings to follow 123 * t nnn - Start tracing, nnn nodes to follow 124 * x [o] - End of Tracing. o indicates do not connect last node to first 125 * n lat lon [o] - Node. o indicates it is an open node (not connected to the previous node) 126 * z - End of data stream 127 */ 128 while ((line = input.readLine()) != null) { 129 System.out.println(line); 130 char option = line.charAt(0); 131 switch(option) { 132 case 'n': 133 String[] tokens = line.split(" "); 134 try { 135 LatLon ll = new LatLon(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2])); 136 Node n = new Node(ll); 137 commands.add(new AddCommand(n)); 138 if (lastNode != null) { 139 Segment s = new Segment(lastNode, n); 140 commands.add(new AddCommand(s)); 141 way.segments.add(s); 142 } 143 else { 144 firstNode = n; 145 } 146 lastNode = n; 147 } 148 catch (Exception ex) { 112 113 114 try { 115 /* 116 * Start the Lakewalker 117 */ 118 Runtime rt = Runtime.getRuntime(); 119 System.out.println("dir: " + working_dir + ", target: " + target); 120 Process p = rt.exec(target, null, working_dir); 121 final BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); 122 123 /* 124 * Start a thread to read the output 125 */ 126 final LakewalkerReader reader = new LakewalkerReader(); 127 128 PleaseWaitRunnable lakewalkerTask = new PleaseWaitRunnable(tr("Tracing")){ 129 @Override protected void realRun() throws SAXException { 130 reader.read(input); 131 } 132 @Override protected void finish() { 149 133 150 } 151 break; 134 } 135 @Override protected void cancel() { 136 reader.cancel(); 152 137 153 case 'x': 154 Segment s = new Segment(lastNode, firstNode); 155 commands.add(new AddCommand(s)); 156 way.segments.add(s); 157 commands.add(new AddCommand(way)); 158 break; 159 } 160 161 } 162 163 while ((line = err.readLine()) != null) { 164 System.out.println(line); 165 } 166 167 input.close(); 168 p.destroy(); 169 170 } 171 catch (Exception ex) { 172 System.out.println("Exception caught: "+ex.getMessage()); 173 } 174 175 if (!commands.isEmpty()) { 176 Main.main.undoRedo.add(new SequenceCommand(tr("Lakewalker trace"), commands)); 177 Main.ds.setSelected(way); 178 } 179 } 180 138 } 139 }; 140 Main.worker.execute(lakewalkerTask); 141 } 142 catch (Exception ex) { 143 System.out.println("Exception caught: " + ex.getMessage()); 144 } 145 146 147 } 148 181 149 protected void lakewalk(List nodes) { 182 150 183 151 } 184 152 … … 189 157 } 190 158 191 public void mouseEntered(MouseEvent e) { 192 } 193 194 public void mouseExited(MouseEvent e) { 159 public void mouseEntered(MouseEvent e) { 160 } 161 162 public void mouseExited(MouseEvent e) { 195 163 } 196 164 … … 200 168 public void mouseReleased(MouseEvent e) { 201 169 } 202 203 // class DuplicateDialog extends JDialog { 204 // private static final long serialVersionUID = 1L; 205 // protected Box mainPanel; 206 // protected IntConfigurer offset; 207 // protected boolean cancelled; 208 // protected String right; 209 // protected String left; 210 // protected JComboBox moveCombo; 211 // 212 // public DuplicateDialog(String title) { 213 // super(); 214 // this.setTitle(title); 215 // this.setModal(true); 216 // initComponents(); 217 // } 218 // 219 // protected void initComponents() { 220 // mainPanel = Box.createVerticalBox(); 221 // offset = new IntConfigurer("", tr("Offset (metres): "), new Integer(15)); 222 // mainPanel.add(offset.getControls()); 223 // getContentPane().add(mainPanel); 224 // 225 // right = tr("right/down"); 226 // left = tr("left/up"); 227 // Box movePanel = Box.createHorizontalBox(); 228 // movePanel.add(new JLabel(tr("Create new segments to the "))); 229 // moveCombo = new JComboBox(new String[] {right, left}); 230 // movePanel.add(moveCombo); 231 // movePanel.add(new JLabel(tr(" of existing segments."))); 232 // mainPanel.add(movePanel); 233 // 234 // Box buttonPanel = Box.createHorizontalBox(); 235 // JButton okButton = new JButton(tr("Ok")); 236 // okButton.addActionListener(new ActionListener() { 237 // public void actionPerformed(ActionEvent e) { 238 // cancelled = false; 239 // setVisible(false); 240 // 241 // } 242 // }); 243 // JButton canButton = new JButton(tr("Cancel")); 244 // canButton.addActionListener(new ActionListener() { 245 // public void actionPerformed(ActionEvent e) { 246 // cancelled = true; 247 // setVisible(false); 248 // } 249 // }); 250 // buttonPanel.add(okButton); 251 // buttonPanel.add(canButton); 252 // mainPanel.add(buttonPanel); 253 // 254 // pack(); 255 // } 256 // 257 // protected int getOffset() { 258 // int off = offset.getIntValue(15); 259 // return right.equals(moveCombo.getSelectedItem()) ? off : -off; 260 // } 261 // 262 // protected boolean isCancelled() { 263 // return cancelled; 264 // } 265 // 266 // } 170 171 172 // class DuplicateDialog extends JDialog { 173 // private static final long serialVersionUID = 1L; 174 // protected Box mainPanel; 175 // protected IntConfigurer offset; 176 // protected boolean cancelled; 177 // protected String right; 178 // protected String left; 179 // protected JComboBox moveCombo; 180 // 181 // public DuplicateDialog(String title) { 182 // super(); 183 // this.setTitle(title); 184 // this.setModal(true); 185 // initComponents(); 186 // } 187 // 188 // protected void initComponents() { 189 // mainPanel = Box.createVerticalBox(); 190 // offset = new IntConfigurer("", tr("Offset (metres): "), new Integer(15)); 191 // mainPanel.add(offset.getControls()); 192 // getContentPane().add(mainPanel); 193 // 194 // right = tr("right/down"); 195 // left = tr("left/up"); 196 // Box movePanel = Box.createHorizontalBox(); 197 // movePanel.add(new JLabel(tr("Create new segments to the "))); 198 // moveCombo = new JComboBox(new String[] {right, left}); 199 // movePanel.add(moveCombo); 200 // movePanel.add(new JLabel(tr(" of existing segments."))); 201 // mainPanel.add(movePanel); 202 // 203 // Box buttonPanel = Box.createHorizontalBox(); 204 // JButton okButton = new JButton(tr("Ok")); 205 // okButton.addActionListener(new ActionListener() { 206 // public void actionPerformed(ActionEvent e) { 207 // cancelled = false; 208 // setVisible(false); 209 // 210 // } 211 // }); 212 // JButton canButton = new JButton(tr("Cancel")); 213 // canButton.addActionListener(new ActionListener() { 214 // public void actionPerformed(ActionEvent e) { 215 // cancelled = true; 216 // setVisible(false); 217 // } 218 // }); 219 // buttonPanel.add(okButton); 220 // buttonPanel.add(canButton); 221 // mainPanel.add(buttonPanel); 222 // 223 // pack(); 224 // } 225 // 226 // protected int getOffset() { 227 // int off = offset.getIntValue(15); 228 // return right.equals(moveCombo.getSelectedItem()) ? off : -off; 229 // } 230 // 231 // protected boolean isCancelled() { 232 // return cancelled; 233 // } 234 // 235 // } 267 236 } -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPlugin.java
r4071 r4095 17 17 public class LakewalkerPlugin extends Plugin { 18 18 19 public static final String VERSION = "0.2"; 20 public static final String PREF_PYTHON = "lakewalker.python"; 19 public static final String VERSION = "0.3"; 21 20 22 21 protected String name; … … 47 46 public PreferenceSetting getPreferenceSetting() 48 47 { 49 return new LakewalkerPreference Setting();48 return new LakewalkerPreferences(); 50 49 } 51 50 -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPreferences.java
r4061 r4095 12 12 import org.openstreetmap.josm.tools.GBC; 13 13 import org.openstreetmap.josm.tools.I18n; 14 public class LakewalkerPreference Settingimplements PreferenceSetting {14 public class LakewalkerPreferences implements PreferenceSetting { 15 15 16 public static final String PREF_PYTHON = "lakewalker.python"; 17 public static final String PREF_MAX_SEG = "lakewalker.max_segs_in_way"; 18 public static final String PREF_MAX_NODES = "lakewalker.max_nodes"; 19 public static final String PREF_THRESHOLD = "lakewalker.threshold"; 20 16 21 protected JTextField python = new JTextField(10); 22 protected IntConfigurer maxSegs = new IntConfigurer(); 23 protected IntConfigurer maxNodes = new IntConfigurer(); 24 protected IntConfigurer threshold = new IntConfigurer(); 17 25 18 26 public void addGui(PreferenceDialog gui) { 19 python.setToolTipText(tr("<html>Path to python executable.</html>")); 27 python.setToolTipText(tr("Path to python executable.")); 28 maxSegs.setToolTipText(tr("Maximum number of segments per way.")); 29 maxNodes.setToolTipText(tr("Maximum number of nodes to trace.")); 30 maxNodes.setToolTipText(tr("Gray threshold.")); 20 31 String description = tr("An interlude to the Lakewalker Python module to trace water bodies on Landsat imagery.<br><br>Version: {0}", LakewalkerPlugin.VERSION); 32 21 33 JPanel prefPanel = gui.createPreferenceTab("lakewalker.png", I18n.tr("Lakewalker Plugin Preferences"), description); 22 34 prefPanel.add(new JLabel(tr("Python executable")), GBC.std().insets(10,5,5,0)); 23 35 prefPanel.add(python, GBC.eol().insets(0,5,0,0).fill(GBC.HORIZONTAL)); 24 36 prefPanel.add(new JLabel(tr("Maximum number of segments per way")), GBC.std().insets(10,5,5,0)); 37 prefPanel.add(maxSegs.getControls(), GBC.eol().insets(0,5,0,0).fill(GBC.HORIZONTAL)); 38 prefPanel.add(new JLabel(tr("Maximum number of nodes to trace")), GBC.std().insets(10,5,5,0)); 39 prefPanel.add(maxNodes.getControls(), GBC.eol().insets(0,5,0,0).fill(GBC.HORIZONTAL)); 40 prefPanel.add(new JLabel(tr("Maximum gray value to count as water")), GBC.std().insets(10,5,5,0)); 41 prefPanel.add(threshold.getControls(), GBC.eol().insets(0,5,0,0).fill(GBC.HORIZONTAL)); 42 43 python.setText(Main.pref.get(PREF_PYTHON, "python.exe")); 44 maxSegs.setValue(Main.pref.get(PREF_MAX_SEG, "250")); 45 maxNodes.setValue(Main.pref.get(PREF_MAX_NODES, "50000")); 46 threshold.setValue(Main.pref.get(PREF_THRESHOLD, "35")); 25 47 } 26 48 27 49 public void ok() { 28 Main.pref.put(LakewalkerPlugin.PREF_PYTHON, python.getText()); 29 50 Main.pref.put(PREF_PYTHON, python.getText()); 51 Main.pref.put(PREF_MAX_SEG, maxSegs.getValueString()); 52 Main.pref.put(PREF_MAX_NODES, maxNodes.getValueString()); 53 Main.pref.put(PREF_THRESHOLD, threshold.getValueString()); 30 54 } 31 55
Note:
See TracChangeset
for help on using the changeset viewer.