Changeset 28037 in osm for applications/editors/josm
- Timestamp:
- 2012-03-11T05:26:49+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationSettings.java
r28036 r28037 21 21 private OsmDataLayer subjectLayer; 22 22 private DataSet referenceDataSet; 23 24 public double distanceWeight; 25 public double distanceCutoff; 26 public String keyString; 27 public double stringWeight; 28 public double stringCutoff; 23 29 24 30 /** -
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationToggleDialog.java
r28036 r28037 274 274 for (int j = 0; j < m; j++) { 275 275 cost[i][j] = ConflationUtils.calcCost( 276 settings.getSubjectSelection().get(i), settings.getReferenceSelection().get(j) );276 settings.getSubjectSelection().get(i), settings.getReferenceSelection().get(j), settings); 277 277 } 278 278 } -
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationUtils.java
r27971 r28037 5 5 import org.openstreetmap.josm.data.coor.LatLon; 6 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 import org.openstreetmap.josm.tools.StringMetrics; 7 8 8 9 public final class ConflationUtils { … … 22 23 * @param subjectObject the non-reference <code>OsmPrimitive</code>. 23 24 */ 24 public static double calcCost(OsmPrimitive referenceObject, OsmPrimitive subjectObject) { 25 public static double calcCost(OsmPrimitive referenceObject, OsmPrimitive subjectObject, ConflationSettings settings) { 26 double cost; 27 25 28 if (referenceObject==subjectObject) { 26 29 return MAX_COST; 27 30 } 31 32 double distance = 0; 33 double stringCost = 1.0; 34 if (settings.distanceWeight != 0) { 35 distance = getCenter(referenceObject).distance(getCenter(subjectObject)); 36 } 37 if (settings.stringWeight != 0) { 38 String referenceString = referenceObject.getKeys().get(settings.keyString); 39 String subjectString = subjectObject.getKeys().get(settings.keyString); 40 41 if (referenceString == null ? subjectString == null : referenceString.equals(subjectString)) 42 stringCost = 0.0; 43 else if (referenceString == null || subjectString == null) 44 stringCost = 1.0; 45 else 46 stringCost = 1.0 - StringMetrics.getByName("levenshtein").getSimilarity(subjectString, referenceString); 47 } 28 48 29 try { 30 return getCenter(referenceObject).distance(getCenter(subjectObject)); 31 } catch (Exception e) { 32 return MAX_COST; 33 } 49 if (distance > settings.distanceCutoff || stringCost > settings.stringCutoff) 50 cost = MAX_COST; 51 else 52 cost = distance * settings.distanceWeight + stringCost * settings.stringWeight; 34 53 35 // TODO: use other "distance" measures, i.e. matching tags54 return cost; 36 55 } 37 56 } -
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/SettingsDialog.java
r28036 r28037 2 2 3 3 import java.awt.Component; 4 import java.awt.GridBagLayout; 4 5 import java.awt.event.ActionEvent; 5 6 import java.util.ArrayList; … … 10 11 import org.openstreetmap.josm.gui.ExtendedDialog; 11 12 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 13 import org.openstreetmap.josm.tools.GBC; 12 14 import static org.openstreetmap.josm.tools.I18n.tr; 13 15 … … 16 18 */ 17 19 public class SettingsDialog extends ExtendedDialog { 18 19 private JPanel costsPanel; 20 private JCheckBox distanceCheckBox; 20 21 21 private JButton freezeReferenceButton; 22 22 private JButton freezeSubjectButton; … … 31 31 private JPanel subjectPanel; 32 32 private JLabel subjectSelectionLabel; 33 JCheckBox distanceCheckBox; 34 JSpinner distanceWeightSpinner; 35 JSpinner distanceCutoffSpinner; 36 JCheckBox stringCheckBox; 37 JSpinner stringWeightSpinner; 38 JSpinner stringCutoffSpinner; 39 JTextField stringTextField; 40 33 41 ArrayList<OsmPrimitive> subjectSelection = null; 34 42 ArrayList<OsmPrimitive> referenceSelection = null; … … 41 49 super(Main.parent, 42 50 tr("Configure conflation settings"), 43 new String[]{tr(" Conflate"), tr("Cancel")},51 new String[]{tr("OK"), tr("Cancel")}, 44 52 false); 45 53 initComponents(); … … 62 70 restoreSubjectButton = new JButton(new RestoreSubjectAction()); 63 71 freezeSubjectButton = new JButton(new FreezeSubjectAction()); 64 costsPanel = new JPanel();65 distanceCheckBox = new JCheckBox();66 72 JPanel pnl = new JPanel(); 67 73 pnl.setLayout(new BoxLayout(pnl, BoxLayout.PAGE_AXIS)); … … 91 97 subjectPanel.add(jPanel5); 92 98 pnl.add(subjectPanel); 99 100 JPanel costsPanel = new JPanel(); 93 101 costsPanel.setBorder(BorderFactory.createTitledBorder(tr("Costs"))); 94 costsPanel.setLayout(new BoxLayout(costsPanel, BoxLayout.LINE_AXIS)); 102 costsPanel.setLayout(new GridBagLayout()); 103 104 costsPanel.add(GBC.glue(1, 1), GBC.std()); 105 costsPanel.add(new JLabel(tr("Weight")), GBC.std()); 106 costsPanel.add(new JLabel(tr("Cutoff")), GBC.eol()); 107 108 distanceCheckBox = new JCheckBox(); 95 109 distanceCheckBox.setSelected(true); 96 110 distanceCheckBox.setText(tr("Distance")); 97 distanceCheckBox.setEnabled(false); 98 costsPanel.add(distanceCheckBox); 111 costsPanel.add(distanceCheckBox, GBC.std()); 112 distanceWeightSpinner = new JSpinner(new SpinnerNumberModel(1.0, null, null, 1.0)); 113 costsPanel.add(distanceWeightSpinner, GBC.std()); 114 distanceCutoffSpinner = new JSpinner(new SpinnerNumberModel(100.0, null, null, 1.0)); 115 costsPanel.add(distanceCutoffSpinner, GBC.eol()); 116 117 stringCheckBox = new JCheckBox(); 118 stringCheckBox.setSelected(false); 119 stringCheckBox.setText(tr("String")); 120 costsPanel.add(stringCheckBox, GBC.std()); 121 stringWeightSpinner = new JSpinner(new SpinnerNumberModel(10.0, null, null, 1.0)); 122 costsPanel.add(stringWeightSpinner, GBC.std()); 123 stringCutoffSpinner = new JSpinner(new SpinnerNumberModel(100.0, null, null, 1.0)); 124 costsPanel.add(stringCutoffSpinner, GBC.eol()); 125 stringTextField = new JTextField("name", 14); 126 costsPanel.add(stringTextField, GBC.std()); 127 99 128 pnl.add(costsPanel); 100 129 setContent(pnl); … … 120 149 settings.setSubjectLayer(subjectLayer); 121 150 settings.setSubjectSelection(subjectSelection); 151 152 settings.distanceCutoff = (Double)distanceCutoffSpinner.getValue(); 153 if (distanceCheckBox.isSelected()) 154 settings.distanceWeight = (Double)distanceWeightSpinner.getValue(); 155 else 156 settings.distanceWeight = 0; 157 settings.stringCutoff = (Double)stringCutoffSpinner.getValue(); 158 if (stringCheckBox.isSelected()) 159 settings.stringWeight = (Double)stringWeightSpinner.getValue(); 160 else 161 settings.stringWeight = 0; 162 163 settings.keyString = stringTextField.getText(); 164 122 165 return settings; 123 166 }
Note:
See TracChangeset
for help on using the changeset viewer.