Changeset 24023 in osm for applications/editors
- Timestamp:
- 2010-11-02T18:43:09+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressEditContainer.java
r24014 r24023 227 227 // Assignment failed: Street is not known (yet) -> add to 'unresolved' list 228 228 shadowUnresolvedAddresses.add(aNode); 229 230 if ("BaDaubringen".equals(aNode.getCity())) { 231 @SuppressWarnings("unused") 232 int x = 0; 233 } 229 234 } 230 235 231 236 if (!aNode.isComplete()) { 232 237 shadowIncompleteAddresses.add(aNode); 238 239 if ("BaDaubringen".equals(aNode.getCity())) { 240 @SuppressWarnings("unused") 241 int x = 0; 242 } 233 243 } 234 244 } … … 451 461 if (assignAddressToStreet(node)) { 452 462 resolvedAddresses.add(node); 453 } 463 } 454 464 } 455 465 -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressFinderThread.java
r24018 r24023 35 35 public class AddressFinderThread extends PleaseWaitRunnable implements Visitor { 36 36 private List<AddressNode> addressesToGuess; 37 private List<IProgressMonitorFinishedListener> finishListeners = new ArrayList<IProgressMonitorFinishedListener>(); 37 38 private double minDist; 38 39 private AddressNode curAddressNode; … … 57 58 } 58 59 59 public List<AddressNode> getAddress EditContainer() {60 public List<AddressNode> getAddressesToGuess() { 60 61 return addressesToGuess; 61 62 } … … 65 66 public boolean isRunning() { 66 67 return isRunning; 68 } 69 70 /** 71 * Adds a finish listener. 72 * 73 * @param l the listener to add 74 */ 75 public void addFinishListener(IProgressMonitorFinishedListener l) { 76 finishListeners.add(l); 77 } 78 79 /** 80 * Removes a finish listener. 81 * 82 * @param l the listener to remove 83 */ 84 public void removeFinishListener(IProgressMonitorFinishedListener l) { 85 finishListeners.remove(l); 86 } 87 88 protected void fireFinished() { 89 for (IProgressMonitorFinishedListener l : finishListeners) { 90 l.finished(); 91 } 92 // this event is fired only once, then we disconnect all listeners 93 finishListeners.clear(); 67 94 } 68 95 … … 173 200 break; 174 201 } 202 203 progressMonitor.subTask(tr("Guess values for ") + aNode); 175 204 176 205 // visit osm data … … 186 215 } 187 216 188 // we found something189 if (nearestName != null) {190 progressMonitor.subTask(String.format("%s: %s (%4.1f m)", tr("Guess"), nearestName, minDist));191 aNode.setGuessedStreetName(nearestName);192 nearestName = null;193 } else {194 System.out.println("Did not find a street for " + aNode);195 }196 217 // report progress 197 218 progressMonitor.worked(1); … … 199 220 } finally { 200 221 isRunning = false; 222 fireFinished(); 201 223 } 202 224 } … … 227 249 minDist = dist; 228 250 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 251 aNode.setGuessedValue(getTag(), currentValue); 233 252 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressNode.java
r24018 r24023 21 21 public static final String MISSING_TAG = "?"; 22 22 23 /** The dictionary containing guessed values. */ 23 24 private HashMap<String, String> guessedValues = new HashMap<String, String>(); 25 /** The dictionary containing indirect values. */ 26 private HashMap<String, String> derivedValues = new HashMap<String, String>(); 24 27 25 28 public AddressNode(OsmPrimitive osmObject) { … … 33 36 public void setOsmObject(OsmPrimitive osmObject) { 34 37 super.setOsmObject(osmObject); 38 39 String streetNameViaRel = OsmUtils.getAssociatedStreet(this.osmObject); 40 if (!StringUtils.isNullOrEmpty(streetNameViaRel)) { 41 setDerivedValue(TagUtils.ADDR_STREET_TAG, streetNameViaRel); 42 } 35 43 } 36 44 … … 42 50 return TagUtils.hasAddrCityTag(osmObject) && TagUtils.hasAddrCountryTag(osmObject) && 43 51 TagUtils.hasAddrHousenumberTag(osmObject) && TagUtils.hasAddrPostcodeTag(osmObject) && 44 TagUtils.hasAddrStateTag(osmObject) && TagUtils.hasAddrStreetTag(osmObject); 52 TagUtils.hasAddrStateTag(osmObject) && 53 (TagUtils.hasAddrStreetTag(osmObject) || hasDerivedValue(TagUtils.ADDR_STREET_TAG)); 45 54 } 46 55 … … 64 73 if (osmObject == null) return MISSING_TAG; 65 74 66 if (!osmObject.hasKey(tag)) { 67 // object does not have this tag -> check for guess 68 if (hasGuessedValue(tag)) { 69 return "*" + getGuessedValue(tag); 70 } else { 71 // give up 72 return MISSING_TAG; 73 } 74 } else { // get existing tag value 75 String val = osmObject.get(tag); 76 if (StringUtils.isNullOrEmpty(val)) { 77 // empty value -> check for guess 75 if (!osmObject.hasKey(tag) || StringUtils.isNullOrEmpty(osmObject.get(tag))) { 76 if (!hasDerivedValue(tag)) { 77 // object does not have this tag -> check for guess 78 78 if (hasGuessedValue(tag)) { 79 79 return "*" + getGuessedValue(tag); 80 80 } else { 81 // tag is empty and no guess available ->give up81 // give up 82 82 return MISSING_TAG; 83 83 } 84 } else { 85 // ok, return existing tag value 86 return val; 84 } else { // ok, use derived value known via associated relation or way 85 return getDerivedValue(tag); 87 86 } 87 } else { // get existing tag value 88 return osmObject.get(tag); 88 89 } 89 90 } … … 376 377 377 378 /** 379 * Checks if given tag has a derived value (value is available via a referrer). 380 * 381 * @param tag the tag 382 * @return true, if tag has a derived value. 383 */ 384 private boolean hasDerivedValue(String tag) { 385 return derivedValues.containsKey(tag) && 386 !StringUtils.isNullOrEmpty(derivedValues.get(tag)); 387 } 388 389 /** 390 * Gets the derived value for the given tag. 391 * @param tag The tag to get the derived value for. 392 * @return 393 */ 394 public String getDerivedValue(String tag) { 395 if (!hasDerivedValue(tag)) { 396 return null; 397 } 398 return derivedValues.get(tag); 399 } 400 401 /** 402 * Sets the value known indirectly via a referrer with the given tag. 403 * 404 * @param tag the tag to set the derived value for 405 * @param value the value of the derived tag. 406 */ 407 public void setDerivedValue(String tag, String value) { 408 derivedValues.put(tag, value); 409 } 410 411 /** 378 412 * Sets the street name of the address node. 379 413 * @param streetName -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OsmUtils.java
r24018 r24023 18 18 import org.openstreetmap.josm.data.coor.LatLon; 19 19 import org.openstreetmap.josm.data.osm.Node; 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 import org.openstreetmap.josm.data.osm.Relation; 22 import org.openstreetmap.josm.data.osm.RelationMember; 20 23 import org.openstreetmap.josm.data.osm.Way; 21 24 import org.openstreetmap.josm.tools.Pair; … … 84 87 } 85 88 } 89 90 /** 91 * Gets the associated street name via relation of the address node, if present. 92 * 93 * @param addrNode the OSM node containing the address. 94 * @return the associated street or null, if no associated street has been found. 95 */ 96 public static String getAssociatedStreet(OsmPrimitive addrNode) { 97 if (addrNode == null) { 98 return null; 99 } 100 101 for (OsmPrimitive osm : addrNode.getReferrers()) { 102 if (osm instanceof Relation) { 103 Relation r = (Relation) osm; 104 105 if (!TagUtils.isAssociatedStreetRelation(r)) continue; 106 107 for (RelationMember rm : r.getMembers()) { 108 if (TagUtils.isStreetMember(rm)) { 109 OsmPrimitive street = rm.getMember(); 110 if (TagUtils.hasHighwayTag(street)) { 111 return TagUtils.getNameValue(street); 112 } // TODO: Issue a warning here 113 } 114 } 115 } 116 } 117 return null; 118 } 86 119 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/TagUtils.java
r24018 r24023 15 15 16 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 import org.openstreetmap.josm.data.osm.Relation; 18 import org.openstreetmap.josm.data.osm.RelationMember; 17 19 18 20 /** … … 1875 1877 public static String getEmbankmentValue(OsmPrimitive osmPrimitive) { 1876 1878 return osmPrimitive != null ? osmPrimitive.get(EMBANKMENT_TAG) : null; 1879 } 1880 1881 // Relation support 1882 1883 /** 1884 * Check if OSM relation is a 'associatedStreet' relation. 1885 * 1886 * @param osmPrimitive 1887 * The OSM entity to check. 1888 */ 1889 public static boolean isAssociatedStreetRelation(Relation rel) { 1890 return rel != null && 1891 rel.hasKey(RELATION_TYPE) && 1892 ASSOCIATEDSTREET_RELATION_TYPE.equals(rel.get(RELATION_TYPE)); 1893 } 1894 1895 /** 1896 * Checks if given relation member has role "street". 1897 * 1898 * @param relMember the relation member 1899 * @return true, if is street member 1900 */ 1901 public static boolean isStreetMember(RelationMember relMember) { 1902 return relMember != null && STREET_RELATION_ROLE.equals(relMember.getRole()); 1903 } 1904 1905 /** 1906 * Checks if given relation member has role "house". 1907 * 1908 * @param relMember the relation member 1909 * @return true, if is street member 1910 */ 1911 public static boolean isHouseMember(RelationMember relMember) { 1912 return relMember != null && STREET_RELATION_ROLE.equals(relMember.getRole()); 1877 1913 } 1878 1914 … … 1968 2004 public static final String EMBANKMENT_TAG = "embankment"; 1969 2005 public static final String ADDR_HOUSENAME_TAG = "addr:housename"; 2006 2007 /* Relation keys */ 2008 2009 // Associated street: See http://wiki.openstreetmap.org/wiki/Proposed_features/De:Hausnummern 2010 public static final String RELATION_TYPE = "type"; 2011 public static final String ASSOCIATEDSTREET_RELATION_TYPE = "associatedStreet"; 2012 public static final String STREET_RELATION_ROLE = "street"; 2013 public static final String HOUSE_RELATION_ROLE = "house"; 1970 2014 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/GuessAddressDataAction.java
r23982 r24023 22 22 import org.openstreetmap.josm.plugins.fixAddresses.AddressFinderThread; 23 23 import org.openstreetmap.josm.plugins.fixAddresses.AddressNode; 24 import org.openstreetmap.josm.plugins.fixAddresses.IProgressMonitorFinishedListener; 24 25 25 26 /** … … 31 32 32 33 @SuppressWarnings("serial") 33 public class GuessAddressDataAction extends AbstractAddressEditAction {34 public class GuessAddressDataAction extends AbstractAddressEditAction implements IProgressMonitorFinishedListener { 34 35 35 36 public GuessAddressDataAction() { … … 80 81 */ 81 82 private void internalGuessAddresses(List<AddressNode> nodes) { 82 Main.worker.submit(new AddressFinderThread(nodes, tr("Guess street names"))); 83 AddressFinderThread aft = new AddressFinderThread(nodes, tr("Guess street names")); 84 aft.addFinishListener(this); 85 Main.worker.submit(aft); 86 } 87 88 @Override 89 public void finished() { 83 90 if (container != null) { 84 91 container.invalidate(); -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/IncompleteAddressesTableModel.java
r24014 r24023 16 16 import static org.openstreetmap.josm.tools.I18n.tr; 17 17 18 import java.util.ArrayList; 19 import java.util.List; 20 18 21 import org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer; 19 22 import org.openstreetmap.josm.plugins.fixAddresses.AddressNode; 20 23 import org.openstreetmap.josm.plugins.fixAddresses.INodeEntity; 24 import org.openstreetmap.josm.plugins.fixAddresses.IProgressMonitorFinishedListener; 21 25 import org.openstreetmap.josm.plugins.fixAddresses.StringUtils; 22 26 23 public class IncompleteAddressesTableModel extends AddressEditTableModel {27 public class IncompleteAddressesTableModel extends AddressEditTableModel { 24 28 /** 25 29 * … … 31 35 private static final Class<?>[] COLUMN_CLASSES = new Class<?>[]{ 32 36 String.class, String.class, String.class, String.class, String.class}; 37 33 38 34 39 /** … … 76 81 return aNode.getPostCode(); 77 82 case 4: 78 if (!StringUtils.isNullOrEmpty(aNode.getGuessedStreetName()) && 79 AddressNode.MISSING_TAG.equals(aNode.getStreetName())) { 80 81 return "(" + aNode.getGuessedStreetName() + ")"; 82 } else { 83 return aNode.getStreetName(); 84 } 83 aNode.getStreetName(); 85 84 default: 86 85 throw new RuntimeException("Invalid column index: " + column);
Note:
See TracChangeset
for help on using the changeset viewer.