Changeset 19881 in osm for applications/editors/josm/plugins
- Timestamp:
- 2010-02-05T15:09:00+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/tracer/src
- Files:
-
- 3 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/tracer/src/org/openstreetmap/josm/plugins/tracer/TracerAction.java
r19872 r19881 36 36 import org.openstreetmap.josm.data.osm.BBox; 37 37 import org.openstreetmap.josm.data.osm.OsmPrimitive; 38 import org.openstreetmap.josm.tools.Pair; 38 39 39 40 class TracerAction extends MapMode implements MouseListener { … … 126 127 List<Command> cmds = new LinkedList<Command>(); 127 128 Way newWay = new Way(way); 128 for (int i = 1; i < way.getNodesCount(); i++) { 129 Node n = way.getNode(i); 129 for (Node n : way.getNodes()) { 130 130 LatLon ll = n.getCoor(); 131 131 BBox bbox = new BBox( … … 153 153 //System.out.println("-------"); 154 154 if (nearestNode == null) { 155 tryConnectNodeToAnyWay(way, newWay, n, cmds);155 cmds.addAll(tryConnectNodeToAnyWay(n)); 156 156 } else { 157 nearestNode.setCoor(ll.getCenter(nearestNode.getCoor())); 158 int j = newWay.getNodes().indexOf(n); 159 newWay.addNode(j, nearestNode); 160 if (j == 0) { 161 // first + last point 162 newWay.addNode(newWay.getNodesCount(), nearestNode); 163 } 164 newWay.removeNode(n); 165 cmds.add(new DeleteCommand(n)); 166 } 167 } 168 trySplitWayByAnyNodes(way, newWay); 157 cmds.add(mergeNodes(nearestNode, n, newWay)); 158 } 159 } 160 newWay = trySplitWayByAnyNodes(way); 169 161 170 162 cmds.add(new ChangeCommand(way, newWay)); … … 175 167 176 168 /** 177 * Try connect node "node" from way "oldWay" to way of other building. 169 * Merges two nodes 170 * @param n1 First node 171 * @param n2 Second node 172 * @param way Way containing first node 173 * @return Command 174 */ 175 private Command mergeNodes(Node n1, Node n2, Way way){ 176 n2.setCoor(n1.getCoor().getCenter(n2.getCoor())); 177 int j = way.getNodes().indexOf(n1); 178 way.addNode(j, n2); 179 if (j == 0) { 180 // first + last point 181 way.addNode(way.getNodesCount(), n2); 182 } 183 way.removeNode(n1); 184 return new DeleteCommand(n1); 185 } 186 187 /** 188 * Try connect node "node" from way "way" to way of other building. 178 189 * 179 190 * Zkusi zjistit, zda node neni tak blizko nejake usecky existujici budovy, 180 191 * ze by mel byt zacnenen do teto usecky. Pokud ano, provede to. 181 192 * 182 * @param oldWay Way which contains node "node".183 * @param newWay Modified way.184 193 * @param node Node to connect. 185 * @param cmds Command list.186 194 * @throws IllegalStateException 187 195 * @throws IndexOutOfBoundsException 196 * @return List of Commands. 188 197 */ 189 private void tryConnectNodeToAnyWay(Way oldWay, Way newWay, Node node, List<Command> cmds)198 private List<Command> tryConnectNodeToAnyWay(Node node) 190 199 throws IllegalStateException, IndexOutOfBoundsException { 191 200 192 201 final double MIN_DISTANCE = 0.000015; 202 List<Command> cmds = new LinkedList<Command>(); 193 203 194 204 LatLon ll = node.getCoor(); … … 206 216 int nearestNodeIndex = 0; 207 217 for (Way ww : ways) { 208 if (!ww.isUsable() || ww == oldWay || ww == newWay|| !isBuilding(ww)) {218 if (!ww.isUsable() || ww.containsNode(node) || !isBuilding(ww)) { 209 219 continue; 210 220 } 211 for (int nindex = 0; nindex < ww.getNodesCount(); nindex++) { 212 Node n1 = ww.getNode(nindex); 213 Node n2 = ww.getNode((nindex + 1) % ww.getNodesCount()); 214 double dist = TracerGeometry.distanceFromSegment(ll, n1.getCoor(), n2.getCoor()); 221 for (Pair<Node, Node> np : ww.getNodePairs(false)) { 222 double dist = TracerGeometry.distanceFromSegment(ll, np.a.getCoor(), np.b.getCoor()); 215 223 if (dist < minDist) { 216 224 minDist = dist; 217 225 nearestWay = ww; 218 nearestNodeIndex = nindex;226 nearestNodeIndex = ww.getNodes().indexOf(np.a); 219 227 } 220 228 } … … 227 235 cmds.add(new ChangeCommand(nearestWay, newNWay)); 228 236 } 237 return cmds; 229 238 } 230 239 … … 232 241 * Try split way by any existing buiding nodes. 233 242 * 234 * Zkusi zjistit zda nejake usecka z oldWay by nemela prochazet nejakym existujicim bodem,243 * Zkusi zjistit zda nejake usecka z way by nemela prochazet nejakym existujicim bodem, 235 244 * ktery je ji velmi blizko. Pokud ano, tak puvodni usecku rozdeli na dve tak, aby 236 245 * prochazela takovym bodem. 237 246 * 238 * @param oldWay Way to split. 239 * @param newWay Modified way. 247 * @param way Way to split. 240 248 * @throws IndexOutOfBoundsException 241 249 * @throws IllegalStateException 250 * @return Modified way 242 251 */ 243 private void trySplitWayByAnyNodes(Way oldWay, Way newWay)252 private Way trySplitWayByAnyNodes(Way way) 244 253 throws IndexOutOfBoundsException, IllegalStateException { 245 254 246 255 // projdi kazdou novou usecku a zjisti, zda by nemela vest pres existujici body 247 256 int i = 0; 248 while (i < newWay.getNodesCount()) {257 while (i < way.getNodesCount()) { 249 258 // usecka n1, n2 250 LatLon n1 = newWay.getNodes().get(i).getCoor();251 LatLon n2 = newWay.getNodes().get((i + 1) % newWay.getNodesCount()).getCoor();252 //System.out.println( newWay.getNodes().get(i) + "-----" + newWay.getNodes().get((i + 1) % newWay.getNodesCount()));259 LatLon n1 = way.getNodes().get(i).getCoor(); 260 LatLon n2 = way.getNodes().get((i + 1) % way.getNodesCount()).getCoor(); 261 //System.out.println(way.getNodes().get(i) + "-----" + way.getNodes().get((i + 1) % way.getNodesCount())); 253 262 double minDistanceSq = 0.000015; 254 263 double maxAngle = 15; 255 List<Node> nodes = Main.main.getCurrentDataSet().searchNodes(new BBox(Math.min(n1.getX(), n2.getX()) - minDistanceSq, Math.min(n1.getY(), n2.getY()) - minDistanceSq, Math.max(n1.getX(), n2.getX()) + minDistanceSq, Math.max(n1.getY(), n2.getY()) + minDistanceSq)); 264 List<Node> nodes = Main.main.getCurrentDataSet().searchNodes(new BBox( 265 Math.min(n1.getX(), n2.getX()) - minDistanceSq, 266 Math.min(n1.getY(), n2.getY()) - minDistanceSq, 267 Math.max(n1.getX(), n2.getX()) + minDistanceSq, 268 Math.max(n1.getY(), n2.getY()) + minDistanceSq 269 )); 256 270 Node nearestNode = null; 257 271 for (Node nod : nodes) { 258 if (!nod.isUsable() || oldWay.containsNode(nod) || newWay.containsNode(nod) || !isInBuilding(nod)) {272 if (!nod.isUsable() || way.containsNode(nod) || !isInBuilding(nod)) { 259 273 continue; 260 274 } … … 275 289 } else { 276 290 // rozdeleni usecky 277 newWay.addNode(i + 1, nearestNode);291 way.addNode(i + 1, nearestNode); 278 292 continue; // i nezvetsuji, treba bude treba rozdelit usecku znovu 279 293 } 280 294 } 295 return way; 281 296 } 282 297 283 298 private void tagBuilding(Way way) { 284 way.put("building", "yes");299 if(alt) way.put("building", "yes"); 285 300 way.put("source", "cuzk:km"); 286 301 } -
applications/editors/josm/plugins/tracer/src/org/openstreetmap/josm/plugins/tracer/TracerGeometry.java
r19867 r19881 44 44 double r_numerator = (cx - ax) * (bx - ax) + (cy - ay) * (by - ay); 45 45 double r_denomenator = (bx - ax) * (bx - ax) + (by - ay) * (by - ay); 46 if(r_denomenator == 0)System.out.println("r_denomenator == 0 ------------"); 46 47 double r = r_numerator / r_denomenator; 47 48 double s = ((ay - cy) * (bx - ax) - (ax - cx) * (by - ay)) / r_denomenator; -
applications/editors/josm/plugins/tracer/src/org/openstreetmap/josm/plugins/tracer/TracerPlugin.java
r19868 r19881 5 5 */ 6 6 7 package tracer;7 package org.openstreetmap.josm.plugins.tracer; 8 8 9 9 import org.openstreetmap.josm.Main; -
applications/editors/josm/plugins/tracer/src/org/openstreetmap/josm/plugins/tracer/TracerServer.java
r19867 r19881 47 47 * @return Building border. 48 48 */ 49 public ArrayList< double[]> trace(LatLon pos) {49 public ArrayList<LatLon> trace(LatLon pos) { 50 50 try { 51 51 String content = callServer("trace/simple/" + pos.lat() + ";" + pos.lon()); 52 ArrayList< double[]> nodelist = new ArrayList<double[]>();52 ArrayList<LatLon> nodelist = new ArrayList<LatLon>(); 53 53 String[] lines = content.split("\\|"); 54 54 for (String line : lines) { … … 56 56 double x = Double.parseDouble(items[0]); 57 57 double y = Double.parseDouble(items[1]); 58 double[] d = new double[2]; 59 d[0] = x; 60 d[1] = y; 61 nodelist.add(d); 58 nodelist.add(new LatLon(x, y)); 62 59 } 63 60 return nodelist; 64 61 } catch (Exception e) { 65 ArrayList<double[]> nodelist = new ArrayList<double[]>(); 66 return nodelist; 62 return new ArrayList<LatLon>(); 67 63 } 68 64 }
Note:
See TracChangeset
for help on using the changeset viewer.