| 1 | 6a7
|
|---|
| 2 | > import java.util.Collection;
|
|---|
| 3 | 151a153
|
|---|
| 4 | > List<Node> nodePool = null;
|
|---|
| 5 | 164c166
|
|---|
| 6 | < //Main.main.getCurrentDataSet().setSelected(m_wayOld);
|
|---|
| 7 | ---
|
|---|
| 8 | > tempWay = new Way(s_oWayOld);
|
|---|
| 9 | 166c168
|
|---|
| 10 | < tempWay = new Way(s_oWayOld);
|
|---|
| 11 | ---
|
|---|
| 12 | > //The following code fragment is based on the utilsplugin2 plugin code (ReplaceGeometryUtils.java)
|
|---|
| 13 | 168,169c170,178
|
|---|
| 14 | < for (i = 0; i < newWay.getNodesCount(); i++) {
|
|---|
| 15 | < tempWay.addNode(tempWay.getNodesCount(), newWay.getNode(i));
|
|---|
| 16 | ---
|
|---|
| 17 | > nodePool = getUnimportantNodes(tempWay);
|
|---|
| 18 | >
|
|---|
| 19 | > System.out.println("nodePool: "+nodePool.size());
|
|---|
| 20 | >
|
|---|
| 21 | > List<Node> geometryPool = new LinkedList<>();
|
|---|
| 22 | > for (Node node : newWay.getNodes()) {
|
|---|
| 23 | > if(!geometryPool.contains(node)) {
|
|---|
| 24 | > geometryPool.add(node);
|
|---|
| 25 | > }
|
|---|
| 26 | 171c180,181
|
|---|
| 27 | < i++;
|
|---|
| 28 | ---
|
|---|
| 29 | >
|
|---|
| 30 | > // We remove all old nodes
|
|---|
| 31 | 175,180c185,215
|
|---|
| 32 | < //cmds.add(new ChangeCommand(m_wayOld, tempWay));
|
|---|
| 33 | < for (i = 0; i < s_oWayOld.getNodesCount() - 1; i++) {
|
|---|
| 34 | < Node n = s_oWayOld.getNode(i);
|
|---|
| 35 | < List<Way> ways = getWaysOfNode(n);
|
|---|
| 36 | < if (ways.size() <= 1) {
|
|---|
| 37 | < cmds2.add(new DeleteCommand(s_oWayOld.getNode(i)));
|
|---|
| 38 | ---
|
|---|
| 39 | >
|
|---|
| 40 | > Map<Node, Node> nodeAssoc = new HashMap<>();
|
|---|
| 41 | > if (geometryPool.size() > 0 && nodePool.size() > 0) {
|
|---|
| 42 | > for (Node n : geometryPool) {
|
|---|
| 43 | > Node nearest = findNearestNode(n, nodePool);
|
|---|
| 44 | > if (nearest != null) {
|
|---|
| 45 | > nodeAssoc.put(n, nearest);
|
|---|
| 46 | > nodePool.remove(nearest);
|
|---|
| 47 | > }
|
|---|
| 48 | > }
|
|---|
| 49 | > }
|
|---|
| 50 | >
|
|---|
| 51 | > // And prepare a list of nodes with all the replacements
|
|---|
| 52 | > List<Node> geometryNodes = newWay.getNodes();
|
|---|
| 53 | > for (i = 0; i < geometryNodes.size(); i++) {
|
|---|
| 54 | > if (nodeAssoc.containsKey(geometryNodes.get(i)))
|
|---|
| 55 | > geometryNodes.set(i, nodeAssoc.get(geometryNodes.get(i)));
|
|---|
| 56 | > }
|
|---|
| 57 | >
|
|---|
| 58 | > // Move old nodes to new positions
|
|---|
| 59 | > for (Node node : nodeAssoc.keySet()) {
|
|---|
| 60 | > cmds.add(new MoveCommand(nodeAssoc.get(node), node.getCoor()));
|
|---|
| 61 | > }
|
|---|
| 62 | >
|
|---|
| 63 | > tempWay.setNodes(geometryNodes);
|
|---|
| 64 | >
|
|---|
| 65 | > // our new way has less nodes than old way
|
|---|
| 66 | > if (!nodePool.isEmpty()){
|
|---|
| 67 | > for(Node d: nodePool){
|
|---|
| 68 | > // don't use nodePool nodes in connectTo(), mergeNodes(), trySplitWayByAnyNodes() etc.
|
|---|
| 69 | > d.setDeleted(true);
|
|---|
| 70 | 182d216
|
|---|
| 71 | < s_oNodes.remove(s_oWayOld.getNode(i));
|
|---|
| 72 | 183a218
|
|---|
| 73 | >
|
|---|
| 74 | 188c223
|
|---|
| 75 | < DataSet ds = MainApplication.getLayerManager().getEditDataSet();
|
|---|
| 76 | ---
|
|---|
| 77 | > DataSet ds = MainApplication.getLayerManager().getEditDataSet();
|
|---|
| 78 | 217a253,261
|
|---|
| 79 | >
|
|---|
| 80 | > // our new way has less nodes than old way
|
|---|
| 81 | > if (nodePool != null && !nodePool.isEmpty()){
|
|---|
| 82 | > for(Node nd: nodePool){
|
|---|
| 83 | > nd.setDeleted(false);
|
|---|
| 84 | > }
|
|---|
| 85 | > cmds2.add(new DeleteCommand(nodePool));
|
|---|
| 86 | > }
|
|---|
| 87 | >
|
|---|
| 88 | 221c265
|
|---|
| 89 | < oTracerDebug.OutputCommands(cmds);
|
|---|
| 90 | ---
|
|---|
| 91 | > //oTracerDebug.OutputCommands(cmds);
|
|---|
| 92 | 495c539,586
|
|---|
| 93 | < }
|
|---|
| 94 | \ Brak znaku nowej linii na końcu pliku
|
|---|
| 95 | ---
|
|---|
| 96 | > /**
|
|---|
| 97 | > * Create a list of nodes that are not used anywhere except in the way.
|
|---|
| 98 | > */
|
|---|
| 99 | > // plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java
|
|---|
| 100 | > protected static List<Node> getUnimportantNodes(Way way) {
|
|---|
| 101 | > List<Node> nodePool = new LinkedList<>();
|
|---|
| 102 | > for (Node n : way.getNodes()) {
|
|---|
| 103 | > List<OsmPrimitive> referrers = n.getReferrers();
|
|---|
| 104 | > if (!n.isDeleted() && referrers.size() == 1 && referrers.get(0).equals(way)
|
|---|
| 105 | > && !hasInterestingKey(n) && !nodePool.contains(n)) {
|
|---|
| 106 | > nodePool.add(n);
|
|---|
| 107 | > }
|
|---|
| 108 | > }
|
|---|
| 109 | > return nodePool;
|
|---|
| 110 | > }
|
|---|
| 111 | >
|
|---|
| 112 | > // plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java
|
|---|
| 113 | > protected static boolean hasInterestingKey(OsmPrimitive object) {
|
|---|
| 114 | > for (String key : object.getKeys().keySet()) {
|
|---|
| 115 | > if (!OsmPrimitive.isUninterestingKey(key)) {
|
|---|
| 116 | > return true;
|
|---|
| 117 | > }
|
|---|
| 118 | > }
|
|---|
| 119 | > return false;
|
|---|
| 120 | > }
|
|---|
| 121 | >
|
|---|
| 122 | > // plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java
|
|---|
| 123 | > protected static Node findNearestNode(Node node, Collection<Node> nodes) {
|
|---|
| 124 | > if (nodes.contains(node))
|
|---|
| 125 | > return node;
|
|---|
| 126 | >
|
|---|
| 127 | > Node nearest = null;
|
|---|
| 128 | > // TODO: use meters instead of degrees, but do it fast
|
|---|
| 129 | > double distance = 1;
|
|---|
| 130 | > LatLon coor = node.getCoor();
|
|---|
| 131 | >
|
|---|
| 132 | > for (Node n : nodes) {
|
|---|
| 133 | > double d = n.getCoor().distance(coor);
|
|---|
| 134 | > if (d < distance) {
|
|---|
| 135 | > distance = d;
|
|---|
| 136 | > nearest = n;
|
|---|
| 137 | > }
|
|---|
| 138 | > }
|
|---|
| 139 | > return nearest;
|
|---|
| 140 | > }
|
|---|
| 141 | >
|
|---|
| 142 | >
|
|---|
| 143 | > }
|
|---|