Changeset 27326 in osm for applications/editors
- Timestamp:
- 2011-12-28T13:17:21+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/GuessAddressRunnable.java
r27321 r27326 22 22 23 23 import org.openstreetmap.josm.Main; 24 import org.openstreetmap.josm.data.coor.LatLon;25 import org.openstreetmap.josm.data.osm.Changeset;26 24 import org.openstreetmap.josm.data.osm.Node; 27 import org.openstreetmap.josm.data.osm.OsmPrimitive;28 import org.openstreetmap.josm.data.osm.Relation;29 25 import org.openstreetmap.josm.data.osm.Way; 30 import org.openstreetmap.josm.data.osm.visitor.Visitor;31 26 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 32 27 import org.openstreetmap.josm.io.OsmTransferException; … … 43 38 private List<OSMAddress> addressesToGuess; 44 39 private List<IProgressMonitorFinishedListener> finishListeners = new ArrayList<IProgressMonitorFinishedListener>(); 45 private double minDist;46 private OSMAddress curAddressNode;47 40 private boolean isRunning = false; 48 41 private boolean canceled; 49 42 43 private GuessedValueHandler[] wayGuessers = new GuessedValueHandler[]{new GuessStreetValueHandler(TagUtils.ADDR_STREET_TAG)}; 44 private GuessedValueHandler[] nodeGuessers = new GuessedValueHandler[]{ 45 new GuessedValueHandler(TagUtils.ADDR_POSTCODE_TAG, 500.0), 46 new GuessedValueHandler(TagUtils.ADDR_CITY_TAG, 5000.0), 47 new GuessedValueHandler(TagUtils.ADDR_STATE_TAG, 5000.0), 48 new GuessedValueHandler(TagUtils.ADDR_COUNTRY_TAG, 5000.0), 49 new GuessedValueHandler(TagUtils.ADDR_CITY_TAG, 2000.0) 50 }; 50 51 51 52 /** … … 110 111 protected void fireFinished() { 111 112 for (IProgressMonitorFinishedListener l : finishListeners) { 112 l.finished(); 113 l.finished(); 113 114 } 114 115 // this event is fired only once, then we disconnect all listeners 115 116 finishListeners.clear(); 116 117 } 117 118 118 119 /* (non-Javadoc) 119 120 * @see org.openstreetmap.josm.gui.PleaseWaitRunnable#cancel() … … 137 138 @Override 138 139 protected void realRun() throws SAXException, IOException, 139 140 140 OsmTransferException { 141 141 142 if (Main.main.getCurrentDataSet() == null || addressesToGuess == null) return; 142 143 … … 150 151 progressMonitor.setTicksCount(addressesToGuess.size()); 151 152 152 153 154 153 List<OSMAddress> shadowCopy = new ArrayList<OSMAddress>(addressesToGuess); 155 154 for (OSMAddress aNode : shadowCopy) { 156 minDist = Double.MAX_VALUE;157 curAddressNode = aNode;158 159 // setup guessing handlers for address tags160 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, 5000.0),164 new GuessedValueHandler(TagUtils.ADDR_STATE_TAG, aNode, 5000.0),165 new GuessedValueHandler(TagUtils.ADDR_COUNTRY_TAG, aNode, 5000.0),166 new GuessedValueHandler(TagUtils.ADDR_CITY_TAG, aNode, 2000.0)167 };168 169 155 if (!aNode.needsGuess()) { // nothing to do 170 156 progressMonitor.worked(1); … … 176 162 break; 177 163 } 164 178 165 // Update progress monitor 179 166 progressMonitor.subTask(tr("Guess values for ") + aNode); 180 167 181 // visit osm data 182 for (OsmPrimitive osmPrimitive : Main.main.getCurrentDataSet().allPrimitives()) { 183 if (canceled) { 184 break; 185 } 186 187 // guess values 188 for (int i = 0; i < guessers.length; i++) { 189 osmPrimitive.visit(guessers[i]); 190 191 if (guessers[i].currentValue == null && i == 0) { 192 //System.err.println("Guess #" + i + " failed for " + aNode); 168 // Run way-related guessers 169 for (int i = 0; i < wayGuessers.length; i++) { 170 GuessedValueHandler guesser = wayGuessers[i]; 171 172 guesser.setAddressNode(aNode); 173 174 // visit osm data 175 for (Way way : Main.main.getCurrentDataSet().getWays()) { 176 if (canceled) { 177 break; 193 178 } 179 way.visit(guesser); 180 } 181 182 String guessedVal = guesser.getCurrentValue(); 183 if (guessedVal != null) { 184 aNode.setGuessedValue(guesser.getTag(), guessedVal, guesser.getSourceNode()); 185 } 186 } 187 188 // Run node-related guessers 189 for (int i = 0; i < nodeGuessers.length; i++) { 190 GuessedValueHandler guesser = nodeGuessers[i]; 191 192 guesser.setAddressNode(aNode); 193 194 // visit osm data 195 for (Node node : Main.main.getCurrentDataSet().getNodes()) { 196 if (canceled) { 197 break; 198 } 199 node.visit(guesser); 200 } 201 202 String guessedVal = guesser.getCurrentValue(); 203 if (guessedVal != null) { 204 aNode.setGuessedValue(guesser.getTag(), guessedVal, guesser.getSourceNode()); 194 205 } 195 206 } … … 204 215 } 205 216 217 // TODO: Put in separate file 206 218 private class GuessStreetValueHandler extends GuessedValueHandler { 219 public GuessStreetValueHandler(String tag) { 220 this(tag, null); 221 } 207 222 208 223 public GuessStreetValueHandler(String tag, OSMAddress aNode) { … … 225 240 if (TagUtils.isStreetSupportingHousenumbers(w)) { 226 241 OSMAddress aNode = getAddressNode(); 227 double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w); 228 229 if (dist < minDist && dist < getMaxDistance()) { 230 System.out.println(String.format("New guess %s: %4.2f m", TagUtils.getNameValue(w), dist)); 231 minDist = dist; 232 currentValue = TagUtils.getNameValue(w); 233 aNode.setGuessedValue(getTag(), currentValue, w); 234 } else { 235 //System.out.println(String.format("Skipped %s: %4.2f m", TagUtils.getNameValue(w), dist)); 242 String newVal = TagUtils.getNameValue(w); 243 244 if (newVal != null) { 245 double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w); 246 247 if (dist < minDist && dist < getMaxDistance()) { 248 minDist = dist; 249 currentValue = newVal; 250 srcNode = w; 251 //aNode.setGuessedValue(getTag(), currentValue, w); 252 } else { 253 //System.out.println(String.format("Skipped %s: %4.2f m", TagUtils.getNameValue(w), dist)); 254 } 236 255 } 237 256 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/GuessedValueHandler.java
r25373 r27326 16 16 import org.openstreetmap.josm.data.osm.Changeset; 17 17 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 19 import org.openstreetmap.josm.data.osm.Relation; 19 20 import org.openstreetmap.josm.data.osm.Way; … … 37 38 private OSMAddress aNode; 38 39 private double maxDist = DEFAULT_MAX_DIST; 39 40 protected OsmPrimitive srcNode; 41 42 /** 43 * Instantiates a new guessed value handler without node and default maximum distance. 44 * 45 * @param tag the tag to find the guessed value for. 46 */ 47 public GuessedValueHandler(String tag) { 48 this(tag, null, DEFAULT_MAX_DIST); 49 } 50 51 /** 52 * Instantiates a new guessed value handler without node. 53 * 54 * @param tag the tag to find the guessed value for. 55 * @param maxDist the maximum distance for a node/way to be considered as guessed value. 56 */ 57 public GuessedValueHandler(String tag, double maxDist) { 58 this(tag, null, maxDist); 59 } 60 40 61 /** 41 62 * Instantiates a new guessed value handler. … … 63 84 } 64 85 65 if (aNode == null) {66 throw new RuntimeException("Address node must not be null!");67 }68 69 86 if (maxDist < 1.0) { // clip value 70 87 maxDist = 1.0; 71 88 } 89 72 90 this.tag = tag; 73 74 minDist = Double.MAX_VALUE;75 this.aNode = aNode;76 91 this.maxDist = maxDist; 92 setAddressNode(aNode); 77 93 } 78 94 … … 84 100 protected OSMAddress getAddressNode() { 85 101 return aNode; 102 } 103 104 105 /** 106 * Sets the address node to make the guess for. 107 * @param aNode 108 */ 109 public void setAddressNode(OSMAddress aNode) { 110 this.aNode = aNode; 111 // reset search results 112 minDist = Double.MAX_VALUE; 113 srcNode = null; 114 currentValue = null; 86 115 } 87 116 … … 120 149 * @return the currentValue 121 150 */ 122 p rotectedString getCurrentValue() {151 public String getCurrentValue() { 123 152 return currentValue; 153 } 154 155 156 /** 157 * Gets the node/way which has been selected for the guess. 158 * @return The source node or null; if no appropriate source primitive has been found 159 */ 160 public OsmPrimitive getSourceNode() { 161 return srcNode; 124 162 } 125 163 … … 138 176 @Override 139 177 public void visit(Node n) { 178 assert aNode != null; 179 140 180 if (n.hasKey(tag)) { 141 181 double dist = n.getCoor().greatCircleDistance(aNode.getCoor()); … … 143 183 minDist = dist; 144 184 currentValue = n.get(tag); 145 aNode.setGuessedValue(tag, currentValue, n);185 srcNode = n; 146 186 } 147 187 } … … 153 193 @Override 154 194 public void visit(Way w) { 195 assert aNode != null; 196 155 197 if (w.hasKey(tag)) { 156 198 double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w); … … 158 200 minDist = dist; 159 201 currentValue = w.get(tag); 160 aNode.setGuessedValue(tag, currentValue, w);202 srcNode = w; 161 203 } 162 204 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OSMAddress.java
r27322 r27326 21 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 22 import org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AddressActions; 23 import org.openstreetmap.josm.plugins.fixAddresses.gui.actions.ApplyAllGuessesAction;24 23 import org.openstreetmap.josm.tools.CheckParameterUtil; 25 24 … … 548 547 * @param tag the tag to set the guess for 549 548 * @param value the value of the guessed tag. 549 * @param osm the (optional) object which was used for the guess 550 550 */ 551 551 public void setGuessedValue(String tag, String value, OsmPrimitive osm) { … … 713 713 AddressSolution s = new AddressSolution( 714 714 String.format("%s '%s'", tr("Assign to"), getGuessedValue(tag)), 715 new ApplyAllGuessesAction(tag),715 AddressActions.getApplyGuessesAction(), 716 716 SolutionType.Change); 717 717 -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditTableModel.java
r25373 r27326 19 19 20 20 import javax.swing.JTable; 21 import javax.swing.SwingUtilities; 21 22 import javax.swing.event.TableModelEvent; 22 23 import javax.swing.table.DefaultTableModel; … … 44 45 @Override 45 46 public void containerChanged(AddressEditContainer container) { 46 fireTableDataChanged(); // update model 47 if (SwingUtilities.isEventDispatchThread()) { 48 fireTableDataChanged(); // update model 49 } else { 50 SwingUtilities.invokeLater(new Runnable() { 51 52 @Override 53 public void run() { 54 fireTableDataChanged(); // update model 55 } 56 }); 57 } 47 58 } 48 59
Note:
See TracChangeset
for help on using the changeset viewer.