Changeset 24018 in osm for applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap
- Timestamp:
- 2010-11-02T15:40:03+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses
- Files:
-
- 2 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressFinderThread.java
r23982 r24018 150 150 progressMonitor.setTicksCount(addressesToGuess.size()); 151 151 152 153 152 154 List<AddressNode> shadowCopy = new ArrayList<AddressNode>(addressesToGuess); 153 155 for (AddressNode aNode : shadowCopy) { … … 155 157 curAddressNode = aNode; 156 158 157 if (aNode.hasStreetName()) { 159 // setup guessing handlers for address tags 160 GuessedValueHandler[] guessers = new GuessedValueHandler[]{ 161 new GuessStreetValueHandler(TagUtils.ADDR_STREET_TAG, aNode), 162 new GuessedValueHandler(TagUtils.ADDR_POSTCODE_TAG, aNode, 500.0), 163 new GuessedValueHandler(TagUtils.ADDR_CITY_TAG, aNode, 2000.0) 164 }; 165 166 if (!aNode.needsGuess()) { // nothing to do 158 167 progressMonitor.worked(1); 159 168 continue; … … 170 179 break; 171 180 } 172 osmPrimitive.visit(this); 173 181 182 // guess values 183 for (int i = 0; i < guessers.length; i++) { 184 osmPrimitive.visit(guessers[i]); 185 } 174 186 } 175 187 … … 189 201 } 190 202 } 203 204 private class GuessStreetValueHandler extends GuessedValueHandler { 205 206 public GuessStreetValueHandler(String tag, AddressNode aNode) { 207 super(tag, aNode); 208 } 209 210 /* (non-Javadoc) 211 * @see org.openstreetmap.josm.plugins.fixAddresses.GuessedValueHandler#visit(org.openstreetmap.josm.data.osm.Node) 212 */ 213 @Override 214 public void visit(Node n) { 215 // do nothing 216 } 217 218 /* (non-Javadoc) 219 * @see org.openstreetmap.josm.plugins.fixAddresses.GuessedValueHandler#visit(org.openstreetmap.josm.data.osm.Way) 220 */ 221 @Override 222 public void visit(Way w) { 223 if (TagUtils.hasHighwayTag(w)) { 224 AddressNode aNode = getAddressNode(); 225 double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w); 226 if (dist < minDist && dist < getMaxDistance()) { 227 minDist = dist; 228 currentValue = TagUtils.getNameValue(w); 229 230 System.out.println(String.format("New guess (way) for tag %s (%4.2f m): %s (%s)", 231 getTag(), minDist, currentValue, aNode.toString())); 232 aNode.setGuessedValue(getTag(), currentValue); 233 } 234 } 235 } 236 } 191 237 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressNode.java
r24014 r24018 14 14 package org.openstreetmap.josm.plugins.fixAddresses; 15 15 16 import java.util.HashMap; 17 16 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 19 … … 19 21 public static final String MISSING_TAG = "?"; 20 22 21 private String guessedStreetName;23 private HashMap<String, String> guessedValues = new HashMap<String, String>(); 22 24 23 25 public AddressNode(OsmPrimitive osmObject) { … … 48 50 */ 49 51 public String getStreetName() { 52 return getTagValueWithGuess(TagUtils.ADDR_STREET_TAG); 53 } 54 55 /** 56 * Gets the tag value with guess. If the object does not have the given tag, this mehtod looks for 57 * an appropriate guess. If both, real value and guess, are missing, a question mark is returned. 58 * 59 * @param tag the tag 60 * @return the tag value with guess 61 */ 62 private String getTagValueWithGuess(String tag) { 63 if (StringUtils.isNullOrEmpty(tag)) return MISSING_TAG; 50 64 if (osmObject == null) return MISSING_TAG; 51 /* 52 if (!TagUtils.hasAddrStreetTag(osmObject)) { 53 // check, if referrers have a street 54 for (OsmPrimitive osm : osmObject.getReferrers()) { 55 if (TagUtils.hasAddrStreetTag(osm)) { 56 String refStreetName = TagUtils.getAddrStreetValue(osm); 57 58 if (!StringUtils.isNullOrEmpty(refStreetName)) { 59 return refStreetName; 60 } 61 } 62 } 63 return MISSING_TAG; // nothing found 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; 65 66 if (!osmObject.hasKey(tag)) { 67 // object does not have this tag -> check for guess 68 if (hasGuessedValue(tag)) { 69 return "*" + getGuessedValue(tag); 71 70 } else { 71 // give up 72 72 return MISSING_TAG; 73 73 } 74 } else { // get existing tag value 75 String val = osmObject.get(tag); 76 if (StringUtils.isNullOrEmpty(val)) { 77 // empty value -> check for guess 78 if (hasGuessedValue(tag)) { 79 return "*" + getGuessedValue(tag); 80 } else { 81 // tag is empty and no guess available -> give up 82 return MISSING_TAG; 83 } 84 } else { 85 // ok, return existing tag value 86 return val; 87 } 74 88 } 75 89 } … … 88 102 */ 89 103 public String getGuessedStreetName() { 90 return g uessedStreetName;104 return getGuessedValue(TagUtils.ADDR_STREET_TAG); 91 105 } 92 106 … … 95 109 */ 96 110 public void setGuessedStreetName(String guessedStreetName) { 97 this.guessedStreetName = guessedStreetName; 98 //fireEntityChanged(this); 99 } 100 111 setGuessedValue(TagUtils.ADDR_STREET_TAG, guessedStreetName); 112 } 113 114 /** 115 * Checks for a guessed street name. 116 * 117 * @return true, if this instance has a guessed street name. 118 */ 101 119 public boolean hasGuessedStreetName() { 102 return !StringUtils.isNullOrEmpty(guessedStreetName); 103 } 104 120 return hasGuessedValue(TagUtils.ADDR_STREET_TAG); 121 } 122 123 /** 124 * @return the guessedPostCode 125 */ 126 public String getGuessedPostCode() { 127 return getGuessedValue(TagUtils.ADDR_POSTCODE_TAG); 128 } 129 130 /** 131 * @param guessedPostCode the guessedPostCode to set 132 */ 133 public void setGuessedPostCode(String guessedPostCode) { 134 setGuessedValue(TagUtils.ADDR_POSTCODE_TAG, guessedPostCode); 135 } 136 137 /** 138 * Checks for a guessed post code. 139 * 140 * @return true, if this instance has a guessed post code. 141 */ 142 public boolean hasGuessedPostCode() { 143 return hasGuessedValue(TagUtils.ADDR_POSTCODE_TAG); 144 } 145 146 /** 147 * @return the guessedCity 148 */ 149 public String getGuessedCity() { 150 return getGuessedValue(TagUtils.ADDR_CITY_TAG); 151 } 152 153 /** 154 * @param guessedCity the guessedCity to set 155 */ 156 public void setGuessedCity(String guessedCity) { 157 setGuessedValue(TagUtils.ADDR_CITY_TAG, guessedCity); 158 } 159 160 /** 161 * Checks for a guessed city name. 162 * 163 * @return true, if this instance has a guessed city name. 164 */ 165 public boolean hasGuessedCity() { 166 return hasGuessedValue(TagUtils.ADDR_CITY_TAG); 167 } 168 105 169 /** 106 170 * Returns true, if this instance has guesses regarding address tags. … … 108 172 */ 109 173 public boolean hasGuesses() { 110 return hasGuessedStreetName(); // to be extended later174 return guessedValues.size() > 0; 111 175 } 112 176 … … 115 179 */ 116 180 public void applyAllGuesses() { 117 if (hasGuessedStreetName()) applyGuessedStreet(); 181 for (String tag : guessedValues.keySet()) { 182 String val = guessedValues.get(tag); 183 if (!StringUtils.isNullOrEmpty(val)) { 184 setOSMTag(tag, val); 185 } 186 } 118 187 } 119 188 … … 123 192 */ 124 193 public String getPostCode() { 125 if (!TagUtils.hasAddrPostcodeTag(osmObject)) { 126 return MISSING_TAG; 127 } 128 return TagUtils.getAddrPostcodeValue(osmObject); 194 return getTagValueWithGuess(TagUtils.ADDR_POSTCODE_TAG); 195 } 196 197 /** 198 * Checks for post code tag. 199 * 200 * @return true, if successful 201 */ 202 public boolean hasPostCode() { 203 return TagUtils.hasAddrPostcodeTag(osmObject); 129 204 } 130 205 … … 145 220 */ 146 221 public String getCity() { 147 if (!TagUtils.hasAddrCityTag(osmObject)) { 148 return MISSING_TAG; 149 } 150 return TagUtils.getAddrCityValue(osmObject); 222 return getTagValueWithGuess(TagUtils.ADDR_CITY_TAG); 223 } 224 225 /** 226 * Checks for city tag. 227 * 228 * @return true, if successful 229 */ 230 public boolean hasCity() { 231 return TagUtils.hasAddrCityTag(osmObject); 151 232 } 152 233 … … 245 326 246 327 /** 247 * Applies the guessed street name to the addr:street tag value. 248 */ 249 public void applyGuessedStreet() { 250 if (hasGuessedStreetName()) { 251 setOSMTag(TagUtils.ADDR_STREET_TAG, guessedStreetName); 252 guessedStreetName = null; 253 } 328 * Gets the guessed value for the given tag. 329 * @param tag The tag to get the guessed value for. 330 * @return 331 */ 332 public String getGuessedValue(String tag) { 333 if (!hasGuessedValue(tag)) { 334 return null; 335 } 336 return guessedValues.get(tag); 337 } 338 339 /** 340 * Check if this instance needs guessed values. This is the case, if the underlying OSM node 341 * has either no street name, post code or city. 342 * 343 * @return true, if successful 344 */ 345 public boolean needsGuess() { 346 return !hasStreetName() || !hasCity() || !hasPostCode(); 347 } 348 349 /** 350 * Clears all guessed values. 351 */ 352 public void clearAllGuesses() { 353 guessedValues.clear(); 354 } 355 356 /** 357 * Checks if given tag has a guessed value (tag exists and has a non-empty value). 358 * 359 * @param tag the tag 360 * @return true, if tag has a guessed value. 361 */ 362 private boolean hasGuessedValue(String tag) { 363 return guessedValues.containsKey(tag) && 364 !StringUtils.isNullOrEmpty(guessedValues.get(tag)); 365 } 366 367 /** 368 * Sets the guessed value with the given tag. 369 * 370 * @param tag the tag to set the guess for 371 * @param value the value of the guessed tag. 372 */ 373 public void setGuessedValue(String tag, String value) { 374 guessedValues.put(tag, value); 254 375 } 255 376 -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/TagUtils.java
r23933 r24018 24 24 */ 25 25 public final class TagUtils { 26 26 27 /** 27 28 * Checks if the given OSM primitive is an address node. … … 1072 1073 public static String getAddrHousenumberValue(OsmPrimitive osmPrimitive) { 1073 1074 return osmPrimitive != null ? osmPrimitive.get(ADDR_HOUSENUMBER_TAG) 1075 : null; 1076 } 1077 1078 /** 1079 * Check if OSM primitive has a tag 'addr:housename'. 1080 * 1081 * @param osmPrimitive 1082 * The OSM entity to check. 1083 */ 1084 public static boolean hasAddrHousenameTag(OsmPrimitive osmPrimitive) { 1085 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_HOUSENAME_TAG) 1086 : false; 1087 } 1088 1089 /** 1090 * Gets the value of tag 'addr:housename'. 1091 * 1092 * @param osmPrimitive 1093 * The OSM entity to check. 1094 */ 1095 public static String getAddrHousenameValue(OsmPrimitive osmPrimitive) { 1096 return osmPrimitive != null ? osmPrimitive.get(ADDR_HOUSENAME_TAG) 1074 1097 : null; 1075 1098 } … … 1944 1967 public static final String WHITEWATER_TAG = "whitewater"; 1945 1968 public static final String EMBANKMENT_TAG = "embankment"; 1969 public static final String ADDR_HOUSENAME_TAG = "addr:housename"; 1946 1970 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditDialog.java
r23982 r24018 130 130 unresolvedTable.getSelectionModel().addListSelectionListener(this); 131 131 unresolvedTable.getSelectionModel().addListSelectionListener(new IncompleteAddressListener()); 132 unresolvedTable.addMouseListener( new IncompleteAddressesMouseListener());132 unresolvedTable.addMouseListener(applyAllGuessesAction); 133 133 134 134 JScrollPane scroll2 = new JScrollPane(unresolvedTable); -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/ApplyAllGuessesAction.java
r23970 r24018 16 16 import static org.openstreetmap.josm.tools.I18n.tr; 17 17 18 import java.awt.Point; 19 import java.awt.event.MouseEvent; 20 import java.awt.event.MouseListener; 18 21 import java.util.ArrayList; 19 22 import java.util.List; 20 23 24 import javax.swing.JTable; 25 21 26 import org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer; 22 27 import org.openstreetmap.josm.plugins.fixAddresses.AddressNode; 28 import org.openstreetmap.josm.plugins.fixAddresses.INodeEntity; 23 29 24 30 /** … … 29 35 30 36 @SuppressWarnings("serial") 31 public class ApplyAllGuessesAction extends AbstractAddressEditAction {37 public class ApplyAllGuessesAction extends AbstractAddressEditAction implements MouseListener{ 32 38 33 39 public ApplyAllGuessesAction() { … … 72 78 applyGuesses(addrToFix); 73 79 } 80 81 @Override 82 public void mouseClicked(MouseEvent e) { 83 JTable table = (JTable)e.getSource(); 84 Point p = e.getPoint(); 85 if(e.getClickCount() == 2) { 86 AddressEditTableModel model = (AddressEditTableModel) table.getModel(); 87 if (model != null) { 88 int row = table.rowAtPoint(p); 89 INodeEntity node = model.getEntityOfRow(row); 90 if (node instanceof AddressNode) { 91 beginTransaction(tr("Applied guessed values for ") + node.getOsmObject()); 92 beginObjectTransaction(node); 93 AddressNode aNode = (AddressNode) node; 94 if (aNode.hasGuessedStreetName()) { 95 aNode.applyAllGuesses(); 96 } 97 finishObjectTransaction(node); 98 finishTransaction(); 99 } 100 } 101 } 102 } 103 104 @Override 105 public void mouseEntered(MouseEvent arg0) { 106 // TODO Auto-generated method stub 107 108 } 109 110 @Override 111 public void mouseExited(MouseEvent arg0) { 112 // TODO Auto-generated method stub 113 114 } 115 116 @Override 117 public void mousePressed(MouseEvent arg0) { 118 // TODO Auto-generated method stub 119 120 } 121 122 @Override 123 public void mouseReleased(MouseEvent arg0) { 124 // TODO Auto-generated method stub 125 126 } 74 127 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/UnresolvedAddressesTableModel.java
r24014 r24018 34 34 import org.openstreetmap.josm.plugins.fixAddresses.AddressNode; 35 35 import org.openstreetmap.josm.plugins.fixAddresses.INodeEntity; 36 import org.openstreetmap.josm.plugins.fixAddresses.StringUtils; 37 import org.openstreetmap.josm.plugins.fixAddresses.TagUtils; 36 38 37 39 /** … … 102 104 switch (column) { 103 105 case 0: 104 String guessed = aNode.getGuessedStreetName(); 105 String cur = aNode.getStreetName(); 106 if (aNode.hasGuessedStreetName() && AddressNode.MISSING_TAG.equals(cur)) { 107 return "*" + guessed; 108 } else { 109 return aNode.getStreetName(); 110 } 106 return aNode.getStreetName(); 111 107 case 1: 112 108 return aNode.getHouseNumber(); … … 116 112 return aNode.getPostCode(); 117 113 case 4: 118 return aNode.getName(); 114 String name = aNode.getName(); 115 if (!StringUtils.isNullOrEmpty(name)) { 116 // TODO: Provide a getter/setter for this? 117 return TagUtils.getAddrHousenameValue(aNode.getOsmObject()); 118 } 119 return ""; 119 120 default: 120 121 throw new RuntimeException("Invalid column index: " + column);
Note:
See TracChangeset
for help on using the changeset viewer.