Changeset 28037 in osm for applications/editors/josm


Ignore:
Timestamp:
2012-03-11T05:26:49+01:00 (13 years ago)
Author:
joshdoe
Message:

conflation: initial support for matching on tags

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  
    2121    private OsmDataLayer subjectLayer;
    2222    private DataSet referenceDataSet;
     23   
     24    public double distanceWeight;
     25    public double distanceCutoff;
     26    public String keyString;
     27    public double stringWeight;
     28    public double stringCutoff;
    2329
    2430    /**
  • applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationToggleDialog.java

    r28036 r28037  
    274274            for (int j = 0; j < m; j++) {
    275275                cost[i][j] = ConflationUtils.calcCost(
    276                         settings.getSubjectSelection().get(i), settings.getReferenceSelection().get(j));
     276                        settings.getSubjectSelection().get(i), settings.getReferenceSelection().get(j), settings);
    277277            }
    278278        }
  • applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationUtils.java

    r27971 r28037  
    55import org.openstreetmap.josm.data.coor.LatLon;
    66import org.openstreetmap.josm.data.osm.OsmPrimitive;
     7import org.openstreetmap.josm.tools.StringMetrics;
    78
    89public final class ConflationUtils {
     
    2223     * @param   subjectObject   the non-reference <code>OsmPrimitive</code>.
    2324     */
    24     public static double calcCost(OsmPrimitive referenceObject, OsmPrimitive subjectObject) {
     25    public static double calcCost(OsmPrimitive referenceObject, OsmPrimitive subjectObject, ConflationSettings settings) {
     26        double cost;
     27
    2528        if (referenceObject==subjectObject) {
    2629            return MAX_COST;
    2730        }
     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        }
    2848       
    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;
    3453
    35         // TODO: use other "distance" measures, i.e. matching tags
     54        return cost;
    3655    }
    3756}
  • applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/SettingsDialog.java

    r28036 r28037  
    22
    33import java.awt.Component;
     4import java.awt.GridBagLayout;
    45import java.awt.event.ActionEvent;
    56import java.util.ArrayList;
     
    1011import org.openstreetmap.josm.gui.ExtendedDialog;
    1112import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     13import org.openstreetmap.josm.tools.GBC;
    1214import static org.openstreetmap.josm.tools.I18n.tr;
    1315
     
    1618 */
    1719public class SettingsDialog extends ExtendedDialog {
    18 
    19     private JPanel costsPanel;
    20     private JCheckBox distanceCheckBox;
     20   
    2121    private JButton freezeReferenceButton;
    2222    private JButton freezeSubjectButton;
     
    3131    private JPanel subjectPanel;
    3232    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   
    3341    ArrayList<OsmPrimitive> subjectSelection = null;
    3442    ArrayList<OsmPrimitive> referenceSelection = null;
     
    4149        super(Main.parent,
    4250                tr("Configure conflation settings"),
    43                 new String[]{tr("Conflate"), tr("Cancel")},
     51                new String[]{tr("OK"), tr("Cancel")},
    4452                false);
    4553        initComponents();
     
    6270        restoreSubjectButton = new JButton(new RestoreSubjectAction());
    6371        freezeSubjectButton = new JButton(new FreezeSubjectAction());
    64         costsPanel = new JPanel();
    65         distanceCheckBox = new JCheckBox();
    6672        JPanel pnl = new JPanel();
    6773        pnl.setLayout(new BoxLayout(pnl, BoxLayout.PAGE_AXIS));
     
    9197        subjectPanel.add(jPanel5);
    9298        pnl.add(subjectPanel);
     99       
     100        JPanel costsPanel = new JPanel();
    93101        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();
    95109        distanceCheckBox.setSelected(true);
    96110        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       
    99128        pnl.add(costsPanel);
    100129        setContent(pnl);
     
    120149        settings.setSubjectLayer(subjectLayer);
    121150        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       
    122165        return settings;
    123166    }
Note: See TracChangeset for help on using the changeset viewer.