Changeset 23967 in osm
- Timestamp:
- 2010-10-31T17:18:52+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressEditContainer.java
r23966 r23967 68 68 private List<AddressNode> shadowIncompleteAddresses = new ArrayList<AddressNode>(100); 69 69 70 private HashMap<String, AddressNode> addressCache = new HashMap<String, AddressNode>();71 70 private HashSet<Node> visitedNodes = new HashSet<Node>(); 72 71 private HashSet<Way> visitedWays = new HashSet<Way>(); … … 135 134 } 136 135 136 AddressNode aNode = null; 137 137 // Address nodes are recycled in order to keep instance variables like guessed names 138 String aid = "" + n.getId(); 139 AddressNode aNode = null; 140 if (!addressCache.containsKey(aid)) { 141 aNode = NodeFactory.createNode(n); 142 if (aNode != null) { 143 addressCache.put(aid, aNode); 144 } 145 } else { 146 aNode = addressCache.get(aid); 147 aNode.setOsmObject(n); 148 } 149 138 aNode = NodeFactory.createNode(n); 139 150 140 if (aNode != null) { 151 141 addAndClassifyAddress(aNode); 152 } else {142 } /*else { 153 143 // check, if node is referred by a way 154 144 for (OsmPrimitive osm : n.getReferrers()) { … … 161 151 } 162 152 163 } 153 }*/ 164 154 markNodeAsVisited(n); 165 155 } 156 157 /* (non-Javadoc) 158 * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Way) 159 */ 160 @Override 161 public void visit(Way w) { 162 // This doesn't matter, we just need the street name 163 //if (w.isIncomplete()) return; 164 165 if (hasBeenVisited(w)) { 166 return; 167 } 168 169 createNodeFromWay(w); 170 markWayAsVisited(w); 171 } 172 166 173 167 174 private void addAndClassifyAddress(AddressNode aNode) { … … 176 183 } 177 184 178 /* (non-Javadoc)179 * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Way)180 */181 @Override182 public void visit(Way w) {183 // This doesn't matter, we just need the street name184 //if (w.isIncomplete()) return;185 186 createNodeFromWay(w);187 /*188 for (Node n : w.getNodes()) {189 190 }*/191 }192 185 193 186 /** … … 198 191 private void createNodeFromWay(Way w) { 199 192 INodeEntity ne = NodeFactory.createNodeFromWay(w); 200 201 processNode(ne, w);202 203 markWayAsVisited(w); 204 205 // Look also into nodes for addresses (unlikely, but at least they206 // get marked as visited).207 for (Node n : w.getNodes()) {208 visit(n);209 } 210 211 for (String key : w.keySet()) {212 if (!tags.contains(key)) {213 tags.add(key);193 194 195 if (!processNode(ne, w)) { 196 197 // Look also into nodes for addresses (unlikely, but at least they 198 // get marked as visited). 199 for (Node n : w.getNodes()) { 200 visit(n); 201 } 202 203 for (String key : w.keySet()) { 204 if (!tags.contains(key)) { 205 tags.add(key); 206 } 214 207 } 215 208 } … … 219 212 * Process a entity node. 220 213 * 221 * @param ne the ne 222 * @param w the w 223 */ 224 private void processNode(INodeEntity ne, Way w) { 214 * @param ne the entity node. 215 * @param w the corresponding OSM way 216 * @return true, if node has been processed 217 */ 218 private boolean processNode(INodeEntity ne, Way w) { 225 219 if (ne != null) { 220 // Node is a street (segment) 226 221 if (ne instanceof StreetSegmentNode) { 227 222 StreetSegmentNode newSegment = (StreetSegmentNode) ne; … … 229 224 if (newSegment != null) { 230 225 String name = newSegment.getName(); 231 if (StringUtils.isNullOrEmpty(name)) return ;226 if (StringUtils.isNullOrEmpty(name)) return false; 232 227 233 228 StreetNode sNode = null; … … 243 238 // names are the same. Then the streets should be split up... 244 239 sNode.addStreetSegment(newSegment); 240 return true; 245 241 } else { 246 242 throw new RuntimeException("Street node is null!"); … … 252 248 if (ne instanceof AddressNode) { 253 249 AddressNode aNode = (AddressNode) ne; 254 addAndClassifyAddress(aNode); 255 } 256 } 250 addAndClassifyAddress(aNode); 251 return true; 252 } 253 } 254 return false; 257 255 } 258 256 -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressFinderThread.java
r23962 r23967 172 172 if (nearestName != null) { 173 173 progressMonitor.subTask(String.format("%s: %s (%4.1f m)", tr("Guess"), nearestName, minDist)); 174 System.out.println("Guessed street: " + nearestName + " for node " + aNode); 174 175 aNode.setGuessedStreetName(nearestName); 175 176 nearestName = null; 177 } else { 178 System.out.println("Did not find a street for " + aNode); 176 179 } 177 180 // report progress -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressNode.java
r23966 r23967 49 49 public String getStreet() { 50 50 if (osmObject == null) return MISSING_TAG; 51 51 /* 52 52 if (!TagUtils.hasAddrStreetTag(osmObject)) { 53 53 // check, if referrers have a street … … 62 62 } 63 63 return MISSING_TAG; // nothing found 64 } 65 return TagUtils.getAddrStreetValue(osmObject); 64 }*/ 65 if (!TagUtils.hasAddrStreetTag(osmObject)) { 66 return MISSING_TAG; 67 } else { 68 String sName = TagUtils.getAddrStreetValue(osmObject); 69 if (!StringUtils.isNullOrEmpty(sName)) { 70 return sName; 71 } else { 72 return MISSING_TAG; 73 } 74 } 66 75 } 67 76 -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/NodeEntityBase.java
r23961 r23967 111 111 */ 112 112 protected void setOSMTag(String tag, String newValue) { 113 Node oldNode = (Node)osmObject; 114 OsmPrimitive newNode = new Node(oldNode); 115 newNode.put(tag, newValue); 116 Main.main.undoRedo.add( new ChangeCommand(oldNode, newNode)); 117 fireEntityChanged(this); 113 OsmPrimitive oldObject = osmObject; 114 OsmPrimitive newObject = null; 115 116 // I would appreciate a clone method... 117 if (oldObject instanceof Node) { 118 newObject = new Node(); 119 } else if (oldObject instanceof Way) { 120 newObject = new Way(); 121 } 122 123 if (newObject != null) { 124 newObject.cloneFrom(oldObject); 125 newObject.put(tag, newValue); 126 Main.main.undoRedo.add( new ChangeCommand(oldObject, newObject)); 127 fireEntityChanged(this); 128 } else { 129 throw new RuntimeException("Cannot modify tag for " + osmObject); 130 } 118 131 } 119 132 -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/NodeFactory.java
r23966 r23967 14 14 package org.openstreetmap.josm.plugins.fixAddresses; 15 15 16 import java.util.HashMap; 17 16 18 import org.openstreetmap.josm.data.osm.Node; 17 19 import org.openstreetmap.josm.data.osm.Way; 18 20 19 21 public class NodeFactory { 22 private static HashMap<String, AddressNode> addressCache = new HashMap<String, AddressNode>(); 23 20 24 /** 21 25 * Creates an address node from an OSM node, if possible. 22 * @param osm26 * @param node 23 27 * @return 24 28 */ 25 public static AddressNode createNode(Node osm) { 26 if (TagUtils.isAddress(osm)) { 27 return new AddressNode(osm); 29 public static AddressNode createNode(Node node) { 30 if (TagUtils.isAddress(node)) { 31 String aid = "" + node.getId(); 32 33 AddressNode aNode = lookup(aid); 34 if (aNode == null) { 35 aNode = new AddressNode(node); 36 addressCache.put(aid, aNode); 37 } else { 38 aNode.setOsmObject(node); 39 } 40 return aNode; 28 41 } 29 42 … … 43 56 // Check for building with address 44 57 if (way.isClosed() && TagUtils.hasBuildingTag(way) && TagUtils.isAddress(way)) { 45 return new AddressNode(way); 58 String aid = "" + way.getId(); 59 60 AddressNode aNode = lookup(aid); 61 if (aNode == null) { 62 aNode = new AddressNode(way); 63 addressCache.put(aid, aNode); 64 } else { 65 aNode.setOsmObject(way); 66 } 67 68 return aNode; 69 } 70 return null; 71 } 72 73 private static AddressNode lookup(String aid) { 74 if (addressCache.containsKey(aid)) { 75 return addressCache.get(aid); 46 76 } 47 77 return null; -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/SelectIncompleteAddressesAction.java
r23964 r23967 28 28 29 29 private AddressEditContainer addressEditContainer; 30 31 /** 32 * 33 */ 30 34 31 public SelectIncompleteAddressesAction() { 35 32 super(tr("Select incomplete addresses"), "select_invaddr_24",
Note:
See TracChangeset
for help on using the changeset viewer.