Changeset 6910 in osm for applications/editors/josm/plugins/lakewalker
- Timestamp:
- 2008-02-18T09:06:14+01:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/lakewalker
- Files:
-
- 5 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/lakewalker/README
r4095 r6910 1 A JOSM plugin to interface to Darryl Shpak's Lakewalker module 1 README FOR Lakewalker 2 ======================= 2 3 4 The Lakewalker plugin can be used to generate traces of lakes, rivers or shoreline from 5 LANDSAT imagery (or theoretically any imagery that is provided on a WMS server). 6 7 Currently the plugin features 2 modes of operation: Native and Classic. The classic mode 8 requires the Python lakewalker.py script to be downloaded into the lakewalker directory 9 within the JOSM plugin directory. 10 11 Common Features: 3 12 - On-screen feedback to Lakewalker progress with cancel 4 13 - Tag ways appropriately 5 14 - limit ways to length 6 - Access all lakewalker options via preferences and via ctrl-click pop-up dialog7 15 - Manage Landsat image cache from Prefs screen 16 17 Native Features: 18 - Doesn't require Python 19 20 Classic Features: 21 - Access all lakewalker options via preferences 8 22 - Read data in thread 9 23 - ... -
applications/editors/josm/plugins/lakewalker/build.xml
r6789 r6910 49 49 <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.lakewalker.LakewalkerPlugin" /> 50 50 <attribute name="Plugin-Description" value="Interface to Lakewalker module" /> 51 <attribute name="Plugin-Version" value="0.1"/> 52 <attribute name="Author" value="Brent Easton <b.easton@uws.edu.au>"/> 51 <attribute name="Plugin-Version" value="0.2"/> 52 <attribute name="Author" value="Brent Easton <b.easton@uws.edu.au>, Jason Reid <jrreid@ucalgary.ca>"/> 53 <attribute name="Main-Class" value="org.openstreetmap.josm.plugins.lakewalker.LakewalkerApp"/> 53 54 </manifest> 54 55 </jar> -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerAction.java
r6874 r6910 13 13 import java.io.InputStreamReader; 14 14 import java.util.ArrayList; 15 import java.util.Collection; 16 import java.util.LinkedList; 15 17 import java.util.List; 18 import java.util.Vector; 16 19 17 20 import javax.swing.JOptionPane; … … 24 27 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 25 28 import org.openstreetmap.josm.tools.ImageProvider; 29 import org.openstreetmap.josm.data.coor.LatLon; 30 import org.openstreetmap.josm.data.osm.Node; 31 import org.openstreetmap.josm.data.osm.Way; 32 import org.openstreetmap.josm.command.AddCommand; 33 import org.openstreetmap.josm.command.Command; 34 import org.openstreetmap.josm.command.SequenceCommand; 35 26 36 import org.xml.sax.SAXException; 27 37 … … 38 48 protected List<Node> selectedNodes; 39 49 protected Thread executeThread; 50 protected boolean cancel; 51 52 protected Collection<Command> commands = new LinkedList<Command>(); 53 protected Collection<Way> ways = new ArrayList<Way>(); 40 54 41 55 public LakewalkerAction(String name) { … … 45 59 setEnabled(true); 46 60 } 47 61 48 62 public void actionPerformed(ActionEvent e) { 49 63 … … 73 87 } 74 88 75 protected void lakewalk(Point clickPoint) { 76 LatLon pos = Main.map.mapView.getLatLon(clickPoint.x, clickPoint.y); 77 78 /* 79 * Collect options 80 */ 81 File working_dir = new File(Main.pref.getPreferencesDir(), "plugins"); 82 working_dir = new File(working_dir, "Lakewalker"); 83 String target = Main.pref.get(LakewalkerPreferences.PREF_PYTHON) + " lakewalker.py"; 84 LatLon topLeft = Main.map.mapView.getLatLon(0, 0); 85 LatLon botRight = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), Main.map.mapView 86 .getHeight()); 87 88 /* 89 * Build command line 90 */ 91 target += " --lat=" + pos.lat(); 92 target += " --lon=" + pos.lon(); 93 target += " --left=" + topLeft.lon(); 94 target += " --right=" + botRight.lon(); 95 target += " --top=" + topLeft.lat(); 96 target += " --bottom=" + botRight.lat(); 97 target += " --waylength=" + Main.pref.get(LakewalkerPreferences.PREF_MAX_SEG, "500"); 98 target += " --maxnodes=" + Main.pref.get(LakewalkerPreferences.PREF_MAX_NODES, "50000"); 99 target += " --threshold=" + Main.pref.get(LakewalkerPreferences.PREF_THRESHOLD, "35"); 100 target += " --dp-epsilon=" + Main.pref.get(LakewalkerPreferences.PREF_EPSILON, "0.0003"); 101 target += " --landsat-res=" + Main.pref.get(LakewalkerPreferences.PREF_LANDSAT_RES, "4000"); 102 target += " --tilesize=" + Main.pref.get(LakewalkerPreferences.PREF_LANDSAT_SIZE, "2000"); 103 target += " --startdir=" + Main.pref.get(LakewalkerPreferences.PREF_START_DIR, "east"); 104 target += " --wms=" + Main.pref.get(LakewalkerPreferences.PREF_WMS, "IR1"); 105 target += " --josm"; 89 protected void lakewalk(Point clickPoint){ 90 /** 91 * Positional data 92 */ 93 final LatLon pos = Main.map.mapView.getLatLon(clickPoint.x, clickPoint.y); 94 final LatLon topLeft = Main.map.mapView.getLatLon(0, 0); 95 final LatLon botRight = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), Main.map.mapView 96 .getHeight()); 97 98 /** 99 * Cache/working directory location 100 */ 101 final File working_dir = new File(Main.pref.getPreferencesDir(), "plugins/Lakewalker"); 102 103 /* 104 * Collect options 105 */ 106 final int waylen = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_MAX_SEG, "500")); 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")); 109 final double epsilon = Double.parseDouble(Main.pref.get(LakewalkerPreferences.PREF_EPSILON, "0.0003")); 110 final int resolution = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_LANDSAT_RES, "4000")); 111 final int tilesize = Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_LANDSAT_SIZE, "2000")); 112 final String startdir = Main.pref.get(LakewalkerPreferences.PREF_START_DIR, "east"); 113 final String wmslayer = Main.pref.get(LakewalkerPreferences.PREF_WMS, "IR1"); 114 115 try { 116 PleaseWaitRunnable lakewalkerTask = new PleaseWaitRunnable(tr("Tracing")){ 117 @Override protected void realRun() throws SAXException { 118 processnodelist(pos, topLeft, botRight, waylen,maxnode,threshold,epsilon,resolution,tilesize,startdir,wmslayer,working_dir); 119 } 120 @Override protected void finish() { 121 122 } 123 @Override protected void cancel() { 124 cancel(); 125 } 126 }; 127 Thread executeThread = new Thread(lakewalkerTask); 128 executeThread.start(); 129 } 130 catch (Exception ex) { 131 System.out.println("Exception caught: " + ex.getMessage()); 132 } 133 } 134 135 private void processnodelist(LatLon pos, LatLon topLeft, LatLon botRight, int waylen, int maxnode, int threshold, double epsilon, int resolution, int tilesize, String startdir, String wmslayer, File workingdir){ 136 137 ArrayList<double[]> nodelist = new ArrayList<double[]>(); 138 139 Lakewalker lw = new Lakewalker(waylen,maxnode,threshold,epsilon,resolution,tilesize,startdir,wmslayer,workingdir); 140 try { 141 nodelist = lw.trace(pos.lat(),pos.lon(),topLeft.lon(),botRight.lon(),topLeft.lat(),botRight.lat()); 142 } catch(LakewalkerException e){ 143 System.out.println(e.getError()); 144 } 145 146 System.out.println(nodelist.size()+" nodes generated"); 147 148 /** 149 * Run the nodelist through a vertex reduction algorithm 150 */ 151 152 nodelist = lw.vertex_reduce(nodelist, epsilon); 153 154 System.out.println("After vertex reduction "+nodelist.size()+" nodes remain."); 155 156 /** 157 * And then through douglas-peucker reduction 158 */ 159 160 nodelist = lw.douglas_peucker(nodelist, epsilon); 161 162 System.out.println("After Douglas-Peucker approximation "+nodelist.size()+" nodes remain."); 163 164 /** 165 * Turn the arraylist into osm nodes 166 */ 167 168 Way way = new Way(); 169 Node n = null; 170 Node tn = null; 171 Node fn = null; 172 173 double eastOffset = 0.0; 174 double northOffset = 0.0; 175 try { 176 eastOffset = Double.parseDouble(Main.pref.get(LakewalkerPreferences.PREF_EAST_OFFSET, "0.0")); 177 northOffset = Double.parseDouble(Main.pref.get(LakewalkerPreferences.PREF_NORTH_OFFSET, "0.0")); 178 } 179 catch (Exception e) { 180 181 } 182 char option = ' '; 183 184 int nodesinway = 0; 185 186 for(int i = 0; i< nodelist.size(); i++){ 187 if (cancel) { 188 return; 189 } 190 191 try { 192 LatLon ll = new LatLon(nodelist.get(i)[0]+northOffset, nodelist.get(i)[1]+eastOffset); 193 n = new Node(ll); 194 if(fn==null){ 195 fn = n; 196 } 197 commands.add(new AddCommand(n)); 198 199 } catch (Exception ex) { 200 } 201 202 way.nodes.add(n); 203 204 if(nodesinway > Integer.parseInt(Main.pref.get(LakewalkerPreferences.PREF_MAX_SEG, "500"))){ 205 String waytype = Main.pref.get(LakewalkerPreferences.PREF_WAYTYPE, "water"); 206 207 if(!waytype.equals("none")){ 208 way.put("natural",waytype); 209 } 210 211 way.put("created_by", "Dshpak_landsat_lakes"); 212 commands.add(new AddCommand(way)); 213 214 way = new Way(); 215 216 way.nodes.add(n); 217 218 nodesinway = 0; 219 } 220 nodesinway++; 221 } 222 223 commands.add(new AddCommand(way)); 224 String waytype = Main.pref.get(LakewalkerPreferences.PREF_WAYTYPE, "water"); 106 225 107 108 try { 109 /* 110 * Start the Lakewalker 111 */ 112 Runtime rt = Runtime.getRuntime(); 113 System.out.println("dir: " + working_dir + ", target: " + target); 114 final Process p = rt.exec(target, null, working_dir); 115 final BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); 116 117 /* 118 * Start a thread to read the output 119 */ 120 final LakewalkerReader reader = new LakewalkerReader(); 121 122 PleaseWaitRunnable lakewalkerTask = new PleaseWaitRunnable(tr("Tracing")){ 123 @Override protected void realRun() throws SAXException { 124 reader.read(input); 125 } 126 @Override protected void finish() { 127 128 } 129 @Override protected void cancel() { 130 reader.cancel(); 131 executeThread.interrupt(); 132 p.destroy(); 133 } 134 }; 135 Thread executeThread = new Thread(lakewalkerTask); 136 executeThread.start(); 137 } 138 catch (Exception ex) { 139 System.out.println("Exception caught: " + ex.getMessage()); 140 } 141 142 226 if(!waytype.equals("none")){ 227 way.put("natural",waytype); 228 } 229 230 way.put("created_by", "Dshpak_landsat_lakes"); 231 232 way.nodes.add(fn); 233 234 235 if (!commands.isEmpty()) { 236 Main.main.undoRedo.add(new SequenceCommand(tr("Lakewalker trace"), commands)); 237 Main.ds.setSelected(ways); 238 } else { 239 System.out.println("Failed"); 240 } 241 } 242 243 public void cancel() { 244 cancel = true; 143 245 } 144 246 … … 164 266 public void mouseReleased(MouseEvent e) { 165 267 } 166 167 168 // class DuplicateDialog extends JDialog { 169 // private static final long serialVersionUID = 1L; 170 // protected Box mainPanel; 171 // protected IntConfigurer offset; 172 // protected boolean cancelled; 173 // protected String right; 174 // protected String left; 175 // protected JComboBox moveCombo; 176 // 177 // public DuplicateDialog(String title) { 178 // super(); 179 // this.setTitle(title); 180 // this.setModal(true); 181 // initComponents(); 182 // } 183 // 184 // protected void initComponents() { 185 // mainPanel = Box.createVerticalBox(); 186 // offset = new IntConfigurer("", tr("Offset (metres): "), new Integer(15)); 187 // mainPanel.add(offset.getControls()); 188 // getContentPane().add(mainPanel); 189 // 190 // right = tr("right/down"); 191 // left = tr("left/up"); 192 // Box movePanel = Box.createHorizontalBox(); 193 // movePanel.add(new JLabel(tr("Create new segments to the "))); 194 // moveCombo = new JComboBox(new String[] {right, left}); 195 // movePanel.add(moveCombo); 196 // movePanel.add(new JLabel(tr(" of existing segments."))); 197 // mainPanel.add(movePanel); 198 // 199 // Box buttonPanel = Box.createHorizontalBox(); 200 // JButton okButton = new JButton(tr("Ok")); 201 // okButton.addActionListener(new ActionListener() { 202 // public void actionPerformed(ActionEvent e) { 203 // cancelled = false; 204 // setVisible(false); 205 // 206 // } 207 // }); 208 // JButton canButton = new JButton(tr("Cancel")); 209 // canButton.addActionListener(new ActionListener() { 210 // public void actionPerformed(ActionEvent e) { 211 // cancelled = true; 212 // setVisible(false); 213 // } 214 // }); 215 // buttonPanel.add(okButton); 216 // buttonPanel.add(canButton); 217 // mainPanel.add(buttonPanel); 218 // 219 // pack(); 220 // } 221 // 222 // protected int getOffset() { 223 // int off = offset.getIntValue(15); 224 // return right.equals(moveCombo.getSelectedItem()) ? off : -off; 225 // } 226 // 227 // protected boolean isCancelled() { 228 // return cancelled; 229 // } 230 // 231 // } 268 232 269 } -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPlugin.java
r5979 r6910 20 20 21 21 protected String name; 22 protected String name2; 22 23 23 24 public LakewalkerPlugin() { 24 25 name = tr("Lake Walker"); 26 name2 = tr("Lake Walker (Old)"); 25 27 JMenu toolsMenu = null; 26 28 for (int i = 0; i < Main.main.menu.getMenuCount() && toolsMenu == null; i++) { … … 40 42 toolsMenu.addSeparator(); 41 43 toolsMenu.add(new JMenuItem(new LakewalkerAction(name))); 44 toolsMenu.add(new JMenuItem(new LakewalkerActionOld(name2))); 42 45 } 43 46
Note:
See TracChangeset
for help on using the changeset viewer.