Changeset 4026 in osm for applications
- Timestamp:
- 2007-08-08T22:36:58+02:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/SimilarNamedWays.java
r3262 r4026 6 6 import java.util.*; 7 7 8 import org.openstreetmap.josm.data.osm.*; 9 import org.openstreetmap.josm.plugins.validator.*; 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 import org.openstreetmap.josm.data.osm.Way; 10 import org.openstreetmap.josm.plugins.validator.Severity; 11 import org.openstreetmap.josm.plugins.validator.Test; 12 import org.openstreetmap.josm.plugins.validator.TestError; 10 13 import org.openstreetmap.josm.plugins.validator.util.Bag; 14 import org.openstreetmap.josm.plugins.validator.util.Util; 11 15 /** 12 16 * Checks for similar named ways, symptom of a possible typo. It uses the … … 55 59 return; 56 60 57 List<List<Way>> cellWays = getWaysInCell(w);58 for( List<Way> ways : cellWays)61 List<List<Way>> theCellWays = Util.getWaysInCell(w, cellWays); 62 for( List<Way> ways : theCellWays) 59 63 { 60 64 for( Way w2 : ways) … … 64 68 65 69 String name2 = w2.get("name"); 66 if( name2 .length() < 6 )70 if( name2 == null || name2.length() < 6 ) 67 71 continue; 68 72 … … 81 85 } 82 86 83 84 /**85 * Returns the start and end cells of a way.86 * @param w The way87 * @return A list with all the cells the way starts or ends88 */89 public List<List<Way>> getWaysInCell(Way w)90 {91 int numSegments = w.segments.size();92 if( numSegments == 0)93 return Collections.emptyList();94 95 Segment start = w.segments.get(0);96 Segment end = start;97 if( numSegments > 1 )98 {99 end = w.segments.get(numSegments - 1);100 }101 102 if( start.incomplete || end.incomplete )103 return Collections.emptyList();104 105 List<List<Way>> cells = new ArrayList<List<Way>>(2);106 Set<Point2D> cellNodes = new HashSet<Point2D>();107 Point2D cell;108 109 // First, round coordinates110 long x0 = Math.round(start.from.eastNorth.east() * 100000);111 long y0 = Math.round(start.from.eastNorth.north() * 100000);112 long x1 = Math.round(end.to.eastNorth.east() * 100000);113 long y1 = Math.round(end.to.eastNorth.north() * 100000);114 115 // Start of the way116 cell = new Point2D.Double(x0, y0);117 cellNodes.add(cell);118 List<Way> ways = cellWays.get( cell );119 if( ways == null )120 {121 ways = new ArrayList<Way>();122 cellWays.put(cell, ways);123 }124 cells.add(ways);125 126 // End of the way127 cell = new Point2D.Double(x1, y1);128 if( !cellNodes.contains(cell) )129 {130 cellNodes.add(cell);131 ways = cellWays.get( cell );132 if( ways == null )133 {134 ways = new ArrayList<Way>();135 cellWays.put(cell, ways);136 }137 cells.add(ways);138 }139 140 // Then floor coordinates, in case the way is in the border of the cell.141 x0 = (long)Math.floor(start.from.eastNorth.east() * 100000);142 y0 = (long)Math.floor(start.from.eastNorth.north() * 100000);143 x1 = (long)Math.floor(end.to.eastNorth.east() * 100000);144 y1 = (long)Math.floor(end.to.eastNorth.north() * 100000);145 146 // Start of the way147 cell = new Point2D.Double(x0, y0);148 if( !cellNodes.contains(cell) )149 {150 cellNodes.add(cell);151 ways = cellWays.get( cell );152 if( ways == null )153 {154 ways = new ArrayList<Way>();155 cellWays.put(cell, ways);156 }157 cells.add(ways);158 }159 160 // End of the way161 cell = new Point2D.Double(x1, y1);162 if( !cellNodes.contains(cell) )163 {164 cellNodes.add(cell);165 ways = cellWays.get( cell );166 if( ways == null )167 {168 ways = new ArrayList<Way>();169 cellWays.put(cell, ways);170 }171 cells.add(ways);172 }173 174 return cells;175 }176 177 178 87 /** 179 88 * Compute Levenshtein distance … … 238 147 /** 239 148 * Get minimum of three values 149 * @param a First value 150 * @param b Second value 151 * @param c Third value 152 * @return The minimum of the tre values 240 153 */ 241 154 private static int Minimum(int a, int b, int c) -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/util/Util.java
r4024 r4026 4 4 5 5 import java.awt.event.ActionListener; 6 import java.awt.geom.Point2D; 6 7 import java.io.*; 7 8 import java.net.URL; 8 9 import java.net.URLConnection; 9 import java.util. StringTokenizer;10 import java.util.*; 10 11 11 12 import javax.swing.JButton; 12 13 13 14 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm. plugins.Plugin;15 import org.openstreetmap.josm. plugins.PluginInformation;16 import org.openstreetmap.josm.plugins. PluginProxy;15 import org.openstreetmap.josm.data.osm.Segment; 16 import org.openstreetmap.josm.data.osm.Way; 17 import org.openstreetmap.josm.plugins.*; 17 18 import org.openstreetmap.josm.tools.ImageProvider; 18 19 … … 231 232 return new File(localPath); 232 233 } 234 235 /** 236 * Returns the start and end cells of a way. 237 * @param w The way 238 * @param cellWays The map with all cells 239 * @return A list with all the cells the way starts or ends 240 */ 241 public static List<List<Way>> getWaysInCell(Way w, Map<Point2D,List<Way>> cellWays) 242 { 243 int numSegments = w.segments.size(); 244 if( numSegments == 0) 245 return Collections.emptyList(); 246 247 Segment start = w.segments.get(0); 248 Segment end = start; 249 if( numSegments > 1 ) 250 { 251 end = w.segments.get(numSegments - 1); 252 } 253 254 if( start.incomplete || end.incomplete ) 255 return Collections.emptyList(); 256 257 List<List<Way>> cells = new ArrayList<List<Way>>(2); 258 Set<Point2D> cellNodes = new HashSet<Point2D>(); 259 Point2D cell; 260 261 // First, round coordinates 262 long x0 = Math.round(start.from.eastNorth.east() * 100000); 263 long y0 = Math.round(start.from.eastNorth.north() * 100000); 264 long x1 = Math.round(end.to.eastNorth.east() * 100000); 265 long y1 = Math.round(end.to.eastNorth.north() * 100000); 266 267 // Start of the way 268 cell = new Point2D.Double(x0, y0); 269 cellNodes.add(cell); 270 List<Way> ways = cellWays.get( cell ); 271 if( ways == null ) 272 { 273 ways = new ArrayList<Way>(); 274 cellWays.put(cell, ways); 275 } 276 cells.add(ways); 277 278 // End of the way 279 cell = new Point2D.Double(x1, y1); 280 if( !cellNodes.contains(cell) ) 281 { 282 cellNodes.add(cell); 283 ways = cellWays.get( cell ); 284 if( ways == null ) 285 { 286 ways = new ArrayList<Way>(); 287 cellWays.put(cell, ways); 288 } 289 cells.add(ways); 290 } 291 292 // Then floor coordinates, in case the way is in the border of the cell. 293 x0 = (long)Math.floor(start.from.eastNorth.east() * 100000); 294 y0 = (long)Math.floor(start.from.eastNorth.north() * 100000); 295 x1 = (long)Math.floor(end.to.eastNorth.east() * 100000); 296 y1 = (long)Math.floor(end.to.eastNorth.north() * 100000); 297 298 // Start of the way 299 cell = new Point2D.Double(x0, y0); 300 if( !cellNodes.contains(cell) ) 301 { 302 cellNodes.add(cell); 303 ways = cellWays.get( cell ); 304 if( ways == null ) 305 { 306 ways = new ArrayList<Way>(); 307 cellWays.put(cell, ways); 308 } 309 cells.add(ways); 310 } 311 312 // End of the way 313 cell = new Point2D.Double(x1, y1); 314 if( !cellNodes.contains(cell) ) 315 { 316 cellNodes.add(cell); 317 ways = cellWays.get( cell ); 318 if( ways == null ) 319 { 320 ways = new ArrayList<Way>(); 321 cellWays.put(cell, ways); 322 } 323 cells.add(ways); 324 } 325 326 return cells; 327 } 233 328 }
Note:
See TracChangeset
for help on using the changeset viewer.