private SimpleMatchList generateMatches(SimpleMatchSettings settings) { JosmTaskMonitor monitor = new JosmTaskMonitor(); monitor.beginTask("Generating matches"); // create Features and collections from primitive selections Set<OsmPrimitive> allPrimitives = new HashSet<>(); allPrimitives.addAll(settings.getReferenceSelection()); allPrimitives.addAll(settings.getSubjectSelection()); FeatureCollection allFeatures = createFeatureCollection(allPrimitives); FeatureCollection refColl = new FeatureDataset(allFeatures.getFeatureSchema()); FeatureCollection subColl = new FeatureDataset(allFeatures.getFeatureSchema()); for (Feature f : allFeatures.getFeatures()) { OsmFeature osmFeature = (OsmFeature) f; if (settings.getReferenceSelection().contains(osmFeature.getPrimitive())) refColl.add(osmFeature); if (settings.getSubjectSelection().contains(osmFeature.getPrimitive())) subColl.add(osmFeature); } // TODO: pass to MatchFinderPanel to use as hint/default for DistanceMatchers // get maximum possible distance so scores can be scaled (FIXME: not quite accurate) // Envelope envelope = refColl.getEnvelope(); // envelope.expandToInclude(subColl.getEnvelope()); // double maxDistance = Point2D.distance( // envelope.getMinX(), // envelope.getMinY(), // envelope.getMaxX(), // envelope.getMaxY()); // build matcher FCMatchFinder finder = settings.getMatchFinder(); // FIXME: ignore/filter duplicate objects (i.e. same object in both sets) // FIXME: fix match functions to work on point/linestring features as well // find matches Map<Feature, Matches> map = finder.match(refColl, subColl, monitor); monitor.subTask("Finishing match list"); // convert to simple one-to-one match SimpleMatchList list = new SimpleMatchList(); for (Map.Entry<Feature, Matches> entry : map.entrySet()) { OsmFeature target = (OsmFeature) entry.getKey(); OsmFeature subject = (OsmFeature) entry.getValue().getTopMatch(); if (target != null && subject != null) list.add( new SimpleMatch( target.getPrimitive(), subject.getPrimitive(), entry.getValue().getTopScore())); } monitor.finishTask(); monitor.close(); return list; }