Changeset 32676 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-07-20T23:02:04+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/lakewalker
- Files:
-
- 1 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/lakewalker/.project
r32286 r32676 16 16 </arguments> 17 17 </buildCommand> 18 <buildCommand> 19 <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> 20 <arguments> 21 </arguments> 22 </buildCommand> 18 23 </buildSpec> 19 24 <natures> 20 25 <nature>org.eclipse.jdt.core.javanature</nature> 26 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> 21 27 </natures> 22 28 </projectDescription> -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/BooleanConfigurer.java
r23190 r32676 1 /* 2 * $Id: BooleanConfigurer.java 705 2005-09-15 13:24:50 +0000 (Thu, 15 Sep 2005) rodneykinney $ 3 * 4 * Copyright (c) 2000-2007 by Rodney Kinney, Brent Easton 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License (LGPL) as published by the Free Software Foundation. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, copies are available 17 * at http://www.opensource.org. 18 */ 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.lakewalker; 3 4 import java.awt.Component; 5 6 import javax.swing.JCheckBox; 20 7 21 8 /** … … 23 10 */ 24 11 public class BooleanConfigurer extends Configurer { 25 private javax.swing.JCheckBox box;12 private JCheckBox box; 26 13 27 14 public BooleanConfigurer() { … … 73 60 74 61 @Override 75 public java.awt.Component getControls() {62 public Component getControls() { 76 63 if (box == null) { 77 64 box = new javax.swing.JCheckBox(getName()); -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/Configurer.java
r23190 r32676 1 /* 2 * $Id: Configurer.java 2175 2007-06-04 04:19:59 +0000 (Mon, 04 Jun 2007) rodneykinney $ 3 * 4 * Copyright (c) 2000-2007 by Rodney Kinney, Brent Easton 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License (LGPL) as published by the Free Software Foundation. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, copies are available 17 * at http://www.opensource.org. 18 */ 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.lakewalker; 20 3 -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/DoubleConfigurer.java
r23190 r32676 1 /* 2 * $Id: DoubleConfigurer.java 5 2003-10-02 15:11:38 +0000 (Thu, 02 Oct 2003) rodneykinney $ 3 * 4 * Copyright (c) 2000-2007 by Rodney Kinney, Brent Easton 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License (LGPL) as published by the Free Software Foundation. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, copies are available 17 * at http://www.opensource.org. 18 */ 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.lakewalker; 20 3 … … 41 24 try { 42 25 d = Double.valueOf(s); 43 } 44 catch (NumberFormatException e) { 26 } catch (NumberFormatException e) { 45 27 d = null; 46 28 } -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/IntConfigurer.java
r23190 r32676 1 /* 2 * $Id: IntConfigurer.java 874 2006-03-15 14:20:56 +0000 (Wed, 15 Mar 2006) rodneykinney $ 3 * 4 * Copyright (c) 2000-2007 by Rodney Kinney, Brent Easton 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License (LGPL) as published by the Free Software Foundation. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, copies are available 17 * at http://www.opensource.org. 18 */ 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.lakewalker; 20 3 … … 44 27 try { 45 28 i = Integer.valueOf(s); 46 } 47 catch (NumberFormatException e) { 29 } catch (NumberFormatException e) { 48 30 i = null; 49 31 } … … 55 37 public int getIntValue(int defaultValue) { 56 38 if (getValue() instanceof Integer) { 57 return ((Integer)getValue()).intValue(); 58 } 59 else { 39 return ((Integer) getValue()).intValue(); 40 } else { 60 41 return defaultValue; 61 42 } -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/Lakewalker.java
r30860 r32676 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.lakewalker; 2 3 … … 18 19 private String wmslayer; 19 20 20 private int[] dirslat = new int[] {0, 1,1,1,0,-1,-1,-1};21 private int[] dirslon = new int[] {1, 1,0,-1,-1,-1,0,1};21 private int[] dirslat = new int[] {0, 1, 1, 1, 0, -1, -1, -1}; 22 private int[] dirslon = new int[] {1, 1, 0, -1, -1, -1, 0, 1}; 22 23 23 24 double start_radius_big = 0.001; 24 25 double start_radius_small = 0.0002; 25 26 26 public Lakewalker(int waylen, int maxnode, int threshold, double epsilon, int resolution, int tilesize, String startdir, String wmslayer) {27 public Lakewalker(int waylen, int maxnode, int threshold, double epsilon, int resolution, int tilesize, String startdir, String wmslayer) { 27 28 this.maxnode = maxnode; 28 29 this.threshold = threshold; … … 43 44 * southeast = 7 44 45 */ 45 private int getDirectionIndex(String direction) throws ArrayIndexOutOfBoundsException {46 int i =0;47 if (direction.equals("East") || direction.equals("east")){46 private int getDirectionIndex(String direction) throws ArrayIndexOutOfBoundsException { 47 int i = 0; 48 if (direction.equals("East") || direction.equals("east")) { 48 49 i = 0; 49 } else if (direction.equals("Northeast") || direction.equals("northeast")){50 i = 51 } else if (direction.equals("North") || direction.equals("north")){52 i = 53 } else if (direction.equals("Northwest") || direction.equals("northwest")){54 i = 55 } else if (direction.equals("West") || direction.equals("west")){56 i = 57 } else if (direction.equals("Southwest") || direction.equals("southwest")){58 i = 59 } else if (direction.equals("South") || direction.equals("south")){60 i = 61 } else if (direction.equals("Southeast") || direction.equals("southeast")){62 i = 50 } else if (direction.equals("Northeast") || direction.equals("northeast")) { 51 i = 1; 52 } else if (direction.equals("North") || direction.equals("north")) { 53 i = 2; 54 } else if (direction.equals("Northwest") || direction.equals("northwest")) { 55 i = 3; 56 } else if (direction.equals("West") || direction.equals("west")) { 57 i = 4; 58 } else if (direction.equals("Southwest") || direction.equals("southwest")) { 59 i = 5; 60 } else if (direction.equals("South") || direction.equals("south")) { 61 i = 6; 62 } else if (direction.equals("Southeast") || direction.equals("southeast")) { 63 i = 7; 63 64 } else { 64 throw new ArrayIndexOutOfBoundsException(tr("Direction index ''{0}'' not found", direction));65 throw new ArrayIndexOutOfBoundsException(tr("Direction index ''{0}'' not found", direction)); 65 66 } 66 67 return i; … … 69 70 /** 70 71 * Do a trace 71 * 72 * @param lat 73 * @param lon 74 * @param tl_lon 75 * @param br_lon 76 * @param tl_lat 77 * @param br_lat 78 */ 79 public ArrayList<double[]> trace(double lat, double lon, double tl_lon, double br_lon, double tl_lat, double br_lat, ProgressMonitor progressMonitor) throws LakewalkerException { 72 */ 73 public ArrayList<double[]> trace(double lat, double lon, double tl_lon, double br_lon, double tl_lat, double br_lat, 74 ProgressMonitor progressMonitor) throws LakewalkerException { 80 75 81 76 progressMonitor.beginTask(null); … … 84 79 85 80 LakewalkerWMS wms = new LakewalkerWMS(this.resolution, this.tilesize, this.wmslayer); 86 LakewalkerBBox bbox = new LakewalkerBBox(tl_lat, tl_lon,br_lat,br_lon);81 LakewalkerBBox bbox = new LakewalkerBBox(tl_lat, tl_lon, br_lat, br_lon); 87 82 88 83 Boolean detect_loop = false; … … 90 85 ArrayList<double[]> nodelist = new ArrayList<>(); 91 86 92 int[] xy = geo_to_xy(lat, lon,this.resolution);93 94 if (!bbox.contains(lat, lon)){87 int[] xy = geo_to_xy(lat, lon, this.resolution); 88 89 if (!bbox.contains(lat, lon)) { 95 90 throw new LakewalkerException(tr("The starting location was not within the bbox")); 96 91 } … … 100 95 progressMonitor.indeterminateSubTask(tr("Looking for shoreline...")); 101 96 102 while (true){103 double[] geo = xy_to_geo(xy[0], xy[1],this.resolution);104 if (bbox.contains(geo[0],geo[1])==false){97 while (true) { 98 double[] geo = xy_to_geo(xy[0], xy[1], this.resolution); 99 if (bbox.contains(geo[0], geo[1]) == false) { 105 100 break; 106 101 } 107 102 108 103 v = wms.getPixel(xy[0], xy[1], progressMonitor.createSubTaskMonitor(0, false)); 109 if (v > this.threshold){104 if (v > this.threshold) { 110 105 break; 111 106 } … … 116 111 xy[0] = xy[0]+delta_lon; 117 112 xy[1] = xy[1]+delta_lat; 118 119 113 } 120 114 121 115 int[] startxy = new int[] {xy[0], xy[1]}; 122 double[] startgeo = xy_to_geo(xy[0], xy[1],this.resolution);116 double[] startgeo = xy_to_geo(xy[0], xy[1], this.resolution); 123 117 124 118 //System.out.printf("Found shore at lat %.4f lon %.4f\n",lat,lon); … … 126 120 int last_dir = this.getDirectionIndex(this.startdir); 127 121 128 for (int i = 0; i < this.maxnode; i++){122 for (int i = 0; i < this.maxnode; i++) { 129 123 130 124 // Print a counter 131 if (i % 250 == 0){132 progressMonitor.indeterminateSubTask(tr("{0} nodes so far...", i));125 if (i % 250 == 0) { 126 progressMonitor.indeterminateSubTask(tr("{0} nodes so far...", i)); 133 127 //System.out.println(i+" nodes so far..."); 134 128 } … … 136 130 // Some variables we need 137 131 int d; 138 int test_x =0;139 int test_y =0;132 int test_x = 0; 133 int test_y = 0; 140 134 int new_dir = 0; 141 135 142 136 // Loop through all the directions we can go 143 for (d = 1; d <= this.dirslat.length; d++){137 for (d = 1; d <= this.dirslat.length; d++) { 144 138 145 139 // Decide which direction we want to look at from this pixel … … 149 143 test_y = xy[1] + this.dirslat[new_dir]; 150 144 151 double[] geo = xy_to_geo(test_x, test_y,this.resolution);152 153 if (!bbox.contains(geo[0], geo[1])){145 double[] geo = xy_to_geo(test_x, test_y, this.resolution); 146 147 if (!bbox.contains(geo[0], geo[1])) { 154 148 System.out.println("Outside bbox"); 155 149 break; … … 157 151 158 152 v = wms.getPixel(test_x, test_y, progressMonitor.createSubTaskMonitor(0, false)); 159 if (v > this.threshold){153 if (v > this.threshold) { 160 154 break; 161 155 } 162 156 163 if (d == this.dirslat.length-1){157 if (d == this.dirslat.length-1) { 164 158 System.out.println("Got stuck"); 165 159 break; … … 175 169 176 170 // Break the loop if we managed to get back to our starting point 177 if (xy[0] == startxy[0] && xy[1] == startxy[1]){171 if (xy[0] == startxy[0] && xy[1] == startxy[1]) { 178 172 break; 179 173 } 180 174 181 175 // Store this node 182 double[] geo = xy_to_geo(xy[0], xy[1],this.resolution);176 double[] geo = xy_to_geo(xy[0], xy[1], this.resolution); 183 177 nodelist.add(geo); 184 178 //System.out.println("Adding node at "+xy[0]+","+xy[1]+" ("+geo[1]+","+geo[0]+")"); 185 179 186 180 // Check if we got stuck in a loop 187 double start_proximity = Math.pow((geo[0] - startgeo[0]), 2) + Math.pow((geo[1] - startgeo[1]),2);188 189 if (detect_loop){190 if (start_proximity < Math.pow(start_radius_small,2)){181 double start_proximity = Math.pow((geo[0] - startgeo[0]), 2) + Math.pow((geo[1] - startgeo[1]), 2); 182 183 if (detect_loop) { 184 if (start_proximity < Math.pow(start_radius_small, 2)) { 191 185 System.out.println("Detected loop"); 192 186 break; 193 187 } 194 } else{195 if (start_proximity > Math.pow(start_radius_big,2)){188 } else { 189 if (start_proximity > Math.pow(start_radius_big, 2)) { 196 190 detect_loop = true; 197 191 } … … 207 201 /** 208 202 * Remove duplicate nodes from the list 209 * 210 * @param nodes 211 * @return 212 */ 213 public ArrayList<double[]> duplicateNodeRemove(ArrayList<double[]> nodes){ 214 215 if(nodes.size() <= 1){ 203 */ 204 public ArrayList<double[]> duplicateNodeRemove(ArrayList<double[]> nodes) { 205 206 if (nodes.size() <= 1) { 216 207 return nodes; 217 208 } 218 209 219 double lastnode[]= new double[] {nodes.get(0)[0], nodes.get(0)[1]};220 221 for (int i = 1; i < nodes.size(); i++){210 double[] lastnode = new double[] {nodes.get(0)[0], nodes.get(0)[1]}; 211 212 for (int i = 1; i < nodes.size(); i++) { 222 213 double[] thisnode = new double[] {nodes.get(i)[0], nodes.get(i)[1]}; 223 214 224 if (thisnode[0] == lastnode[0] && thisnode[1] == lastnode[1]){215 if (thisnode[0] == lastnode[0] && thisnode[1] == lastnode[1]) { 225 216 // Remove the node 226 217 nodes.remove(i); … … 237 228 /** 238 229 * Reduce the number of vertices based on their proximity to each other 239 * 240 * @param nodes 241 * @param proximity 242 * @return 243 */ 244 public ArrayList<double[]> vertexReduce(ArrayList<double[]> nodes, double proximity){ 230 */ 231 public ArrayList<double[]> vertexReduce(ArrayList<double[]> nodes, double proximity) { 245 232 246 233 // Check if node list is empty 247 if (nodes.size()<=1){234 if (nodes.size() <= 1) { 248 235 return nodes; 249 236 } … … 254 241 double prox_sq = Math.pow(proximity, 2); 255 242 256 for (int v = 0; v < nodes.size(); v++){257 if (Math.pow(nodes.get(v)[0] - test_v[0],2) + Math.pow(nodes.get(v)[1] - test_v[1],2) > prox_sq){243 for (int v = 0; v < nodes.size(); v++) { 244 if (Math.pow(nodes.get(v)[0] - test_v[0], 2) + Math.pow(nodes.get(v)[1] - test_v[1], 2) > prox_sq) { 258 245 reducednodes.add(nodes.get(v)); 259 246 test_v = nodes.get(v); … … 264 251 } 265 252 266 public double pointLineDistance(double[] p1, double[] p2, double[] p3) {253 public double pointLineDistance(double[] p1, double[] p2, double[] p3) { 267 254 268 255 double x0 = p1[0]; … … 273 260 double y2 = p3[1]; 274 261 275 if (x2 == x1 && y2 == y1){276 return Math.sqrt(Math.pow(x1-x0, 2) + Math.pow(y1-y0,2));262 if (x2 == x1 && y2 == y1) { 263 return Math.sqrt(Math.pow(x1-x0, 2) + Math.pow(y1-y0, 2)); 277 264 } else { 278 return Math.abs((x2-x1)*(y1-y0) - (x1-x0)*(y2-y1)) / Math.sqrt(Math.pow(x2-x1, 2) + Math.pow(y2-y1,2));265 return Math.abs((x2-x1)*(y1-y0) - (x1-x0)*(y2-y1)) / Math.sqrt(Math.pow(x2-x1, 2) + Math.pow(y2-y1, 2)); 279 266 } 280 267 } 281 268 282 269 /* 283 public ArrayList<double[]> douglasPeuckerNR(ArrayList<double[]> nodes, double epsilon) {270 public ArrayList<double[]> douglasPeuckerNR(ArrayList<double[]> nodes, double epsilon) { 284 271 command_stack = [(0, len(nodes) - 1)] 285 272 286 273 Vector result_stack = new Vector(); 287 274 288 while (command_stack.size() > 0){275 while (command_stack.size() > 0) { 289 276 cmd = command_stack.pop(); 290 if (type(cmd) == tuple){277 if (type(cmd) == tuple) { 291 278 (start, end) = cmd 292 279 (node, dist) = dp_findpoint(nodes, start, end) 293 if (dist > epsilon){280 if (dist > epsilon) { 294 281 command_stack.append("+") 295 282 command_stack.append((start, node)) … … 298 285 result_stack.append((start, end)) 299 286 } 300 } elseif (cmd == "+"){287 } elseif (cmd == "+") { 301 288 first = result_stack.pop() 302 289 second = result_stack.pop() 303 if (first[-1] == second[0]){290 if (first[-1] == second[0]) { 304 291 result_stack.append(first + second[1:]) 305 292 //print "Added %s and %s; result is %s" % (first, second, result_stack[-1]) … … 314 301 return 315 302 316 if (len(result_stack) == 1){303 if (len(result_stack) == 1) { 317 304 return [nodes[x] for x in result_stack[0]]; 318 305 } else { … … 326 313 last = nodes[-1] 327 314 328 for (i in xrange(1, len(nodes) - 1){315 for (i in xrange(1, len(nodes) - 1) { 329 316 d = point_line_distance(nodes[i], first, last) 330 if (d > farthest_dist){317 if (d > farthest_dist) { 331 318 farthest_dist = d 332 319 farthest_node = i 333 320 } 334 321 } 335 if (farthest_dist > epsilon){322 if (farthest_dist > epsilon) { 336 323 seg_a = douglas_peucker(nodes[0:farthest_node+1], epsilon) 337 324 seg_b = douglas_peucker(nodes[farthest_node:-1], epsilon) … … 345 332 */ 346 333 347 public ArrayList<double[]> douglasPeucker(ArrayList<double[]> nodes, double epsilon, int depth) {334 public ArrayList<double[]> douglasPeucker(ArrayList<double[]> nodes, double epsilon, int depth) { 348 335 349 336 // Check if node list is empty 350 if (nodes.size()<=1 || depth > 500){337 if (nodes.size() <= 1 || depth > 500) { 351 338 return nodes; 352 339 } … … 361 348 double d = 0; 362 349 363 for (int i = 1; i < nodes.size(); i++){364 d = pointLineDistance(nodes.get(i), first,last);365 if (d>farthest_dist){350 for (int i = 1; i < nodes.size(); i++) { 351 d = pointLineDistance(nodes.get(i), first, last); 352 if (d > farthest_dist) { 366 353 farthest_dist = d; 367 354 farthest_node = i; … … 372 359 List<double[]> seg_b; 373 360 374 if (farthest_dist > epsilon){375 seg_a = douglasPeucker(sublist(nodes, 0,farthest_node+1),epsilon, depth+1);376 seg_b = douglasPeucker(sublist(nodes, farthest_node,nodes.size()-1),epsilon,depth+1);361 if (farthest_dist > epsilon) { 362 seg_a = douglasPeucker(sublist(nodes, 0, farthest_node+1), epsilon, depth+1); 363 seg_b = douglasPeucker(sublist(nodes, farthest_node, nodes.size()-1), epsilon, depth+1); 377 364 378 365 new_nodes.addAll(seg_a); … … 388 375 ArrayList<double[]> sub = new ArrayList<>(); 389 376 390 if (f<i || i < 0 || f < 0 || f > l.size()){377 if (f < i || i < 0 || f < 0 || f > l.size()) { 391 378 throw new ArrayIndexOutOfBoundsException(); 392 379 } 393 380 394 for (int j = i; j < f; j++){381 for (int j = i; j < f; j++) { 395 382 sub.add(l.get(j)); 396 383 } … … 398 385 } 399 386 400 public double[] xy_to_geo(int x, int y, double resolution) {387 public double[] xy_to_geo(int x, int y, double resolution) { 401 388 double[] geo = new double[2]; 402 389 geo[0] = y / resolution; … … 405 392 } 406 393 407 public int[] geo_to_xy(double lat, double lon, double resolution) {394 public int[] geo_to_xy(double lat, double lon, double resolution) { 408 395 int[] xy = new int[2]; 409 396 410 xy[0] = (int) Math.floor(lon * resolution + 0.5);411 xy[1] = (int) Math.floor(lat * resolution + 0.5);397 xy[0] = (int) Math.floor(lon * resolution + 0.5); 398 xy[1] = (int) Math.floor(lat * resolution + 0.5); 412 399 413 400 return xy; … … 433 420 private double right = 180; 434 421 435 protected LakewalkerBBox(double top, double left, double bottom, double right) {422 protected LakewalkerBBox(double top, double left, double bottom, double right) { 436 423 this.left = left; 437 424 this.right = right; … … 440 427 } 441 428 442 protected Boolean contains(double lat, double lon) {443 if (lat >= this.top || lat <= this.bottom){429 protected Boolean contains(double lat, double lon) { 430 if (lat >= this.top || lat <= this.bottom) { 444 431 return false; 445 432 } 446 if (lon >= this.right || lon <= this.left){433 if (lon >= this.right || lon <= this.left) { 447 434 return false; 448 435 } 449 if ((this.right - this.left) % 360 == 0){436 if ((this.right - this.left) % 360 == 0) { 450 437 return true; 451 438 } -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerAction.java
r32492 r32676 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.lakewalker; 2 3 … … 49 50 protected Collection<Way> ways = new ArrayList<>(); 50 51 51 publicLakewalkerAction(String name) {52 LakewalkerAction(String name) { 52 53 super(name, "lakewalker-sml", tr("Lake Walker."), 53 54 Shortcut.registerShortcut("tools:lakewalker", tr("Tool: {0}", tr("Lake Walker")), … … 58 59 59 60 public void actionPerformed(ActionEvent e) { 60 if (Main.map == null || Main.map.mapView == null || active)61 if (Main.map == null || Main.map.mapView == null || active) 61 62 return; 62 63 … … 79 80 80 81 if (wmsCacheDir.exists() && wmsCacheDir.isDirectory()) { 81 File wmsCache[]= wmsCacheDir.listFiles();82 File[] wmsCache = wmsCacheDir.listFiles(); 82 83 83 84 // sort files by date (most recent first) 84 85 Arrays.sort(wmsCache, new Comparator<File>() { 85 86 public int compare(File f1, File f2) { 86 return (int) (f2.lastModified()-f1.lastModified());87 return (int) (f2.lastModified()-f1.lastModified()); 87 88 } 88 89 }); … … 110 111 if (!wmsCacheDir.mkdirs()) { 111 112 JOptionPane.showMessageDialog(Main.parent, 112 113 tr("Error creating cache directory: {0}", wmsCacheDir.getPath())); 113 114 } 114 115 } … … 116 117 } 117 118 118 protected void lakewalk(Point clickPoint) {119 protected void lakewalk(Point clickPoint) { 119 120 // Positional data 120 121 final LatLon pos = Main.map.mapView.getLatLon(clickPoint.x, clickPoint.y); … … 136 137 137 138 try { 138 PleaseWaitRunnable lakewalkerTask = new PleaseWaitRunnable(tr("Tracing")) {139 PleaseWaitRunnable lakewalkerTask = new PleaseWaitRunnable(tr("Tracing")) { 139 140 @Override protected void realRun() throws SAXException { 140 141 progressMonitor.subTask(tr("checking cache...")); 141 142 cleanupCache(); 142 143 processnodelist(pos, topLeft, botRight, waylen, maxnode, threshold, 143 epsilon, resolution,tilesize,startdir,wmslayer,144 epsilon, resolution, tilesize, startdir, wmslayer, 144 145 progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 145 146 } 147 146 148 @Override protected void finish() { 147 149 } … … 153 155 Thread executeThread = new Thread(lakewalkerTask); 154 156 executeThread.start(); 155 } 156 catch (Exception ex) { 157 } catch (Exception ex) { 157 158 System.out.println("Exception caught: " + ex.getMessage()); 158 159 } … … 160 161 161 162 private void processnodelist(LatLon pos, LatLon topLeft, LatLon botRight, int waylen, int maxnode, int threshold, 162 double epsilon, int resolution, int tilesize, String startdir, String wmslayer, ProgressMonitor progressMonitor){163 double epsilon, int resolution, int tilesize, String startdir, String wmslayer, ProgressMonitor progressMonitor) { 163 164 progressMonitor.beginTask(null, 3); 164 165 try { 165 166 ArrayList<double[]> nodelist = new ArrayList<>(); 166 167 167 Lakewalker lw = new Lakewalker(waylen, maxnode,threshold,epsilon,resolution,tilesize,startdir,wmslayer);168 Lakewalker lw = new Lakewalker(waylen, maxnode, threshold, epsilon, resolution, tilesize, startdir, wmslayer); 168 169 try { 169 nodelist = lw.trace(pos.lat(), pos.lon(),topLeft.lon(),botRight.lon(),topLeft.lat(),botRight.lat(),170 nodelist = lw.trace(pos.lat(), pos.lon(), topLeft.lon(), botRight.lon(), topLeft.lat(), botRight.lat(), 170 171 progressMonitor.createSubTaskMonitor(1, false)); 171 } catch (LakewalkerException e){172 } catch (LakewalkerException e) { 172 173 System.out.println(e.getMessage()); 173 174 } … … 226 227 int nodesinway = 0; 227 228 228 for (int i = 0; i< nodelist.size(); i++){229 for (int i = 0; i < nodelist.size(); i++) { 229 230 if (cancel) { 230 231 return; … … 234 235 LatLon ll = new LatLon(nodelist.get(i)[0]+northOffset, nodelist.get(i)[1]+eastOffset); 235 236 n = new Node(ll); 236 if (fn==null){237 if (fn == null) { 237 238 fn = n; 238 239 } … … 245 246 way.addNode(n); 246 247 247 if (nodesinway > Main.pref.getInteger(LakewalkerPreferences.PREF_MAX_SEG, 500)){248 if (nodesinway > Main.pref.getInteger(LakewalkerPreferences.PREF_MAX_SEG, 500)) { 248 249 String waytype = Main.pref.get(LakewalkerPreferences.PREF_WAYTYPE, "water"); 249 250 250 if (!waytype.equals("none")){251 way.put("natural", waytype);251 if (!waytype.equals("none")) { 252 way.put("natural", waytype); 252 253 } 253 254 … … 267 268 String waytype = Main.pref.get(LakewalkerPreferences.PREF_WAYTYPE, "water"); 268 269 269 if (!waytype.equals("none")){270 way.put("natural", waytype);270 if (!waytype.equals("none")) { 271 way.put("natural", waytype); 271 272 } 272 273 … … 296 297 297 298 public void mouseClicked(MouseEvent e) { 298 if(active) 299 { 299 if (active) { 300 300 active = false; 301 301 Main.map.mapView.removeMouseListener(this); -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerException.java
r23190 r32676 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.lakewalker; 2 3 … … 4 5 5 6 class LakewalkerException extends Exception { 6 public LakewalkerException(){7 LakewalkerException() { 7 8 super(tr("An unknown error has occurred")); 8 9 } 9 10 10 public LakewalkerException(String err){11 LakewalkerException(String err) { 11 12 super(err); 12 13 } -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPlugin.java
r30860 r32676 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.lakewalker; 2 3 … … 28 29 29 30 public static File getLakewalkerCacheDir() { 30 31 return new File(Main.pref.getCacheDirectory(), "lakewalkerwms"); 31 32 } 32 33 } -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPreferences.java
r29854 r32676 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.lakewalker; 2 3 … … 109 110 110 111 public void buildPreferences(JPanel prefPanel) { 111 GBC labelConstraints = GBC.std().insets(10, 5,5,0);112 GBC dataConstraints = GBC.eol().insets(0, 5,0,0).fill(GridBagConstraints.HORIZONTAL);112 GBC labelConstraints = GBC.std().insets(10, 5, 5, 0); 113 GBC dataConstraints = GBC.eol().insets(0, 5, 0, 0).fill(GridBagConstraints.HORIZONTAL); 113 114 114 115 prefPanel.add(maxSegsLabel, labelConstraints); -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerWMS.java
r30860 r32676 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.lakewalker; 2 3 … … 31 32 private List<BufferedImage> images = new Vector<>(); 32 33 // Hashmap to hold the mapping of cached images 33 private Map<String, Integer> imageindex = new HashMap<>();34 private Map<String, Integer> imageindex = new HashMap<>(); 34 35 35 36 private int resolution; … … 38 39 private String wmslayer; 39 40 40 public LakewalkerWMS(int resolution, int tilesize, String wmslayer) {41 public LakewalkerWMS(int resolution, int tilesize, String wmslayer) { 41 42 this.resolution = resolution; 42 43 this.tilesize = tilesize; … … 50 51 51 52 int[] bottom_left_xy = new int[2]; 52 bottom_left_xy[0] = floor(x, this.tilesize);53 bottom_left_xy[1] = floor(y, this.tilesize);53 bottom_left_xy[0] = floor(x, this.tilesize); 54 bottom_left_xy[1] = floor(y, this.tilesize); 54 55 55 56 int[] top_right_xy = new int[2]; … … 57 58 top_right_xy[1] = bottom_left_xy[1] + this.tilesize; 58 59 59 double[] topright_geo = xy_to_geo(top_right_xy[0], top_right_xy[1],this.resolution);60 double[] bottomleft_geo = xy_to_geo(bottom_left_xy[0], bottom_left_xy[1],this.resolution);60 double[] topright_geo = xy_to_geo(top_right_xy[0], top_right_xy[1], this.resolution); 61 double[] bottomleft_geo = xy_to_geo(bottom_left_xy[0], bottom_left_xy[1], this.resolution); 61 62 62 63 String filename = this.wmslayer+"/landsat_"+this.resolution+"_"+this.tilesize+ … … 66 67 // to convert to a locale that uses that to build the proper URL 67 68 NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); 68 DecimalFormat df = (DecimalFormat) nf;69 DecimalFormat df = (DecimalFormat) nf; 69 70 df.applyLocalizedPattern("0.000000"); 70 71 … … 81 82 82 83 // See if this image is already loaded 83 if (this.image != null){84 if (this.imagex != bottom_left_xy[0] || this.imagey != bottom_left_xy[1]){84 if (this.image != null) { 85 if (this.imagex != bottom_left_xy[0] || this.imagey != bottom_left_xy[1]) { 85 86 86 87 // Check if this image exists in the hashmap 87 if (this.imageindex.containsKey(hashkey)){88 if (this.imageindex.containsKey(hashkey)) { 88 89 // Store which image we have 89 90 this.imagex = bottom_left_xy[0]; … … 108 109 109 110 this.images.add(this.image); 110 this.imageindex.put(hashkey, this.images.size()-1);111 112 } catch (FileNotFoundException e){111 this.imageindex.put(hashkey, this.images.size()-1); 112 113 } catch (FileNotFoundException e) { 113 114 System.out.println("Could not find cached image, downloading."); 114 } catch (IOException e){115 } catch (IOException e) { 115 116 System.out.println(e.getMessage()); 116 } catch (Exception e){117 } catch (Exception e) { 117 118 System.out.println(e.getMessage()); 118 119 } 119 120 120 if (this.image == null){121 if (this.image == null) { 121 122 /** 122 123 * Try downloading the image … … 128 129 URL url = new URL(urlloc); 129 130 this.image = ImageIO.read(url); // this can return null! 130 } catch (MalformedURLException e){131 } catch (MalformedURLException e) { 131 132 System.out.println(e.getMessage()); 132 } catch (IOException e){133 } catch (IOException e) { 133 134 System.out.println(e.getMessage()); 134 } catch (Exception e){135 } catch (Exception e) { 135 136 System.out.println(e.getMessage()); 136 137 } … … 138 139 if (this.image != null) { 139 140 this.images.add(this.image); 140 this.imageindex.put(hashkey, this.images.size()-1);141 142 this.saveimage(file, this.image);141 this.imageindex.put(hashkey, this.images.size()-1); 142 143 this.saveimage(file, this.image); 143 144 } 144 145 } … … 147 148 this.imagey = bottom_left_xy[1]; 148 149 149 if (this.image == null){150 if (this.image == null) { 150 151 throw new LakewalkerException(tr("Could not acquire image")); 151 152 } … … 157 158 } 158 159 159 public void saveimage(File file, BufferedImage image) {160 public void saveimage(File file, BufferedImage image) { 160 161 /** 161 162 * Save the image to the cache … … 164 165 ImageIO.write(image, "png", file); 165 166 System.out.println("Saved image to cache"); 166 } catch (Exception e){167 } catch (Exception e) { 167 168 System.out.println(e.getMessage()); 168 169 } 169 170 } 170 171 171 public int getPixel(int x, int y, ProgressMonitor progressMonitor) throws LakewalkerException {172 public int getPixel(int x, int y, ProgressMonitor progressMonitor) throws LakewalkerException { 172 173 // Get the previously shown text 173 174 … … 176 177 177 178 try { 178 image = this.getTile(x, y, progressMonitor);179 } catch (LakewalkerException e){179 image = this.getTile(x, y, progressMonitor); 180 } catch (LakewalkerException e) { 180 181 System.out.println(e.getMessage()); 181 182 throw e; 182 183 } 183 184 184 int tx = floor(x, this.tilesize);185 int ty = floor(y, this.tilesize);185 int tx = floor(x, this.tilesize); 186 int ty = floor(y, this.tilesize); 186 187 187 188 int pixel_x = (x-tx); … … 190 191 //System.out.println("("+x+","+y+") maps to ("+pixel_x+","+pixel_y+") by ("+tx+", "+ty+")"); 191 192 192 int rgb = image.getRGB(pixel_x, pixel_y);193 int rgb = image.getRGB(pixel_x, pixel_y); 193 194 194 195 int pixel; 195 196 196 197 int r = (rgb >> 16) & 0xff; 197 int g = (rgb >> 198 int b = (rgb >> 199 200 pixel = (int) ((0.30 * r) + (0.59 * b) + (0.11 * g));198 int g = (rgb >> 8) & 0xff; 199 int b = (rgb >> 0) & 0xff; 200 201 pixel = (int) ((0.30 * r) + (0.59 * b) + (0.11 * g)); 201 202 202 203 return pixel; 203 204 } 204 205 205 public int floor(int num, int precision) {206 double dnum = num/(double) precision;207 BigDecimal val = new BigDecimal(dnum) 206 public int floor(int num, int precision) { 207 double dnum = num/(double) precision; 208 BigDecimal val = new BigDecimal(dnum); 208 209 val = val.setScale(0, BigDecimal.ROUND_FLOOR); 209 210 return val.intValue()*precision; … … 211 212 212 213 public double floor(double num) { 213 BigDecimal val = new BigDecimal(num) 214 BigDecimal val = new BigDecimal(num); 214 215 val = val.setScale(0, BigDecimal.ROUND_FLOOR); 215 return val.doubleValue() 216 } 217 218 public double[] xy_to_geo(int x, int y, double resolution) {216 return val.doubleValue(); 217 } 218 219 public double[] xy_to_geo(int x, int y, double resolution) { 219 220 double[] geo = new double[2]; 220 221 geo[0] = y / resolution; … … 223 224 } 224 225 225 public int[] geo_to_xy(double lat, double lon, double resolution) {226 public int[] geo_to_xy(double lat, double lon, double resolution) { 226 227 int[] xy = new int[2]; 227 228 228 xy[0] = (int) Math.floor(lon * resolution + 0.5);229 xy[1] = (int) Math.floor(lat * resolution + 0.5);229 xy[0] = (int) Math.floor(lon * resolution + 0.5); 230 xy[1] = (int) Math.floor(lat * resolution + 0.5); 230 231 231 232 return xy; -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/StringConfigurer.java
r23190 r32676 1 /* 2 * $Id: StringConfigurer.java 2073 2007-05-10 14:34:31 +0000 (Thu, 10 May 2007) rodneykinney $ 3 * 4 * Copyright (c) 2000-2007 by Rodney Kinney, Brent Easton 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License (LGPL) as published by the Free Software Foundation. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, copies are available 17 * at http://www.opensource.org. 18 */ 1 // License: GPL. For details, see LICENSE file. 19 2 package org.openstreetmap.josm.plugins.lakewalker; 20 3 … … 66 49 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); 67 50 p.add(new JLabel(getName())); 68 nameField.setMaximumSize 69 (new java.awt.Dimension(nameField.getMaximumSize().width, 51 nameField.setMaximumSize(new java.awt.Dimension(nameField.getMaximumSize().width, 70 52 nameField.getPreferredSize().height)); 71 53 nameField.setText(getValueString()); -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/StringEnumConfigurer.java
r30532 r32676 1 /* 2 * $Id: StringEnumConfigurer.java 2472 2007-10-01 04:10:19 +0000 (Mon, 01 Oct 2007) rodneykinney $ 3 * 4 * Copyright (c) 2000-2007 by Rodney Kinney, Brent Easton 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License (LGPL) as published by the Free Software Foundation. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, copies are available 17 * at http://www.opensource.org. 18 */ 19 /* 20 * Created by IntelliJ IDEA. 21 * User: rkinney 22 * Date: Jul 20, 2002 23 * Time: 3:52:36 AM 24 * To change template for new class use 25 * Code Style | Class Templates options (Tools | IDE Options). 26 */ 1 // License: GPL. For details, see LICENSE file. 27 2 package org.openstreetmap.josm.plugins.lakewalker; 28 3 … … 52 27 this.validValues = validValues; 53 28 transValues = new String[validValues.length]; 54 for (int i = 0; i < validValues.length; ++i)29 for (int i = 0; i < validValues.length; ++i) { 55 30 transValues[i] = tr(validValues[i]); 31 } 56 32 } 57 33 … … 63 39 tooltipText = s; 64 40 } 41 65 42 @Override 66 43 public Component getControls() { … … 70 47 box = new JComboBox<>(transValues); 71 48 box.setToolTipText(tooltipText); 72 box.setMaximumSize(new Dimension(box.getMaximumSize().width, box.getPreferredSize().height));49 box.setMaximumSize(new Dimension(box.getMaximumSize().width, box.getPreferredSize().height)); 73 50 setValue(value); 74 51 box.addActionListener(new ActionListener() { … … 86 63 @Override 87 64 public void setValue(Object o) { 88 if (o == null)65 if (o == null) 89 66 o = 0; 90 67 super.setValue(o); 91 if (!noUpdate && box != null)92 box.setSelectedIndex((Integer) o);68 if (!noUpdate && box != null) 69 box.setSelectedIndex((Integer) o); 93 70 } 94 71 … … 96 73 public void setValue(String s) { 97 74 Integer n = 0; 98 for (int i = 0; i < transValues.length; ++i) 99 { 100 if (transValues[i].equals(s) || validValues[i].equals(s)){ 75 for (int i = 0; i < transValues.length; ++i) { 76 if (transValues[i].equals(s) || validValues[i].equals(s)) { 101 77 n = i; 102 78 break; … … 108 84 @Override 109 85 public String getValueString() { 110 return validValues[(Integer) value];86 return validValues[(Integer) value]; 111 87 } 112 88 }
Note:
See TracChangeset
for help on using the changeset viewer.