shared_ptr<OsmMap> PertyMatchScorer::_loadReferenceMap(const QString referenceMapInputPath, const QString referenceMapOutputPath) { LOG_DEBUG("Loading the reference data with status Unknown1 and adding REF1 tags to it; Saving " << "a copy to " << referenceMapOutputPath << "..."); shared_ptr<OsmMap> referenceMap(new OsmMap()); OsmUtils::loadMap(referenceMap, referenceMapInputPath, false, Status::Unknown1); //TODO: should this be removed? MapCleaner().apply(referenceMap); shared_ptr<AddRef1Visitor> addRef1Visitor(new AddRef1Visitor()); referenceMap->visitRw(*addRef1Visitor); //TODO: this could eventually be replaced with a SetTagVisitor passed in from the command line //instead shared_ptr<SetTagVisitor> setAccuracyVisitor( new SetTagVisitor("error:circular", QString::number(_searchDistance))); referenceMap->visitRw(*setAccuracyVisitor); LOG_VARD(referenceMap->getNodeMap().size()); LOG_VARD(referenceMap->getWays().size()); if (Log::getInstance().getLevel() <= Log::Debug) { TagCountVisitor tagCountVisitor; referenceMap->visitRo(tagCountVisitor); const long numTotalTags = (long)tagCountVisitor.getStat(); LOG_VARD(numTotalTags); } shared_ptr<OsmMap> referenceMapCopy(referenceMap); MapProjector::projectToWgs84(referenceMapCopy); OsmUtils::saveMap(referenceMapCopy, referenceMapOutputPath); return referenceMap; }
void runTest() { OsmReader reader; shared_ptr<OsmMap> map(new OsmMap()); OsmMap::resetCounters(); reader.setDefaultStatus(Status::Unknown1); reader.read("test-files/ops/CookieCutterOp/DcTigerRoads-cropped.osm", map); reader.setDefaultStatus(Status::Unknown2); reader.read("test-files/DcGisRoads.osm", map); MapCleaner().apply(map); CookieCutterOp uut; uut.setAlpha(1000.0); uut.setAlphaShapeBuffer(0.0); uut.setCrop(false); uut.setOutputBuffer(0.0); uut.apply(map); MapProjector::projectToWgs84(map); QDir().mkpath("test-output/ops/CookieCutterOp"); OsmWriter writer; writer.write(map, "test-output/ops/CookieCutterOp/CookieCutterOpTest.osm"); HOOT_FILE_EQUALS("test-files/ops/CookieCutterOp/CookieCutterOpTest.osm", "test-output/ops/CookieCutterOp/CookieCutterOpTest.osm"); }
void PertyMatchScorer::_loadPerturbedMap(const QString perturbedMapInputPath, const QString perturbedMapOutputPath) { LOG_DEBUG("Loading the reference data to be used by the data to be perturbed; " << "renaming REF1 tags to REF2..."); //load from the modified reference data output to get the added ref1 tags; don't copy the map, //since updates to the names of the ref tags on this map will propagate to the map copied from shared_ptr<OsmMap> perturbedMap(new OsmMap()); OsmUtils::loadMap(perturbedMap, perturbedMapInputPath, false, Status::Unknown2); //TODO: should this be removed? MapCleaner().apply(perturbedMap); shared_ptr<TagRenameKeyVisitor> tagRenameKeyVisitor(new TagRenameKeyVisitor("REF1", "REF2")); perturbedMap->visitRw(*tagRenameKeyVisitor); //TODO: this could eventually be replaced with a SetTagVisitor passed in from the command line //instead shared_ptr<SetTagVisitor> setAccuracyVisitor( new SetTagVisitor("error:circular", QString::number(_searchDistance))); perturbedMap->visitRw(*setAccuracyVisitor); LOG_VARD(perturbedMap->getNodeMap().size()); LOG_VARD(perturbedMap->getWays().size()); if (Log::getInstance().getLevel() <= Log::Debug) { TagCountVisitor tagCountVisitor; perturbedMap->visitRo(tagCountVisitor); const long numTotalTags = (long)tagCountVisitor.getStat(); LOG_VARD(numTotalTags); } LOG_DEBUG("Perturbing the copied reference data and saving it to: " << perturbedMapOutputPath); PertyOp pertyOp; pertyOp.setConfiguration(_settings); LOG_DEBUG("Details: " << pertyOp.toString()); pertyOp.apply(perturbedMap); LOG_VARD(perturbedMap->getNodeMap().size()); LOG_VARD(perturbedMap->getWays().size()); if (Log::getInstance().getLevel() <= Log::Debug) { TagCountVisitor tagCountVisitor; perturbedMap->visitRo(tagCountVisitor); const long numTotalTags = (long)tagCountVisitor.getStat(); LOG_VARD(numTotalTags); } MapProjector::projectToWgs84(perturbedMap); OsmUtils::saveMap(perturbedMap, perturbedMapOutputPath); }
shared_ptr<OsmMap> load(QString s1, QString s2) { OsmReader reader; Tgs::Random::instance()->seed(0); OsmMap::resetCounters(); shared_ptr<OsmMap> map(new OsmMap()); reader.setDefaultStatus(Status::Unknown1); reader.read(s1, map); reader.setDefaultStatus(Status::Unknown2); reader.read(s2, map); // make the results consistent. MapProjector::projectToAeac(map); MapCleaner().apply(map); return map; }
/** * Load the source data up into memory for later conflation. */ void Conflator::loadSource(shared_ptr<OsmMap> map) { LOG_INFO("Preprocessing inputs..."); _map = map; if (_debug) { _saveMap(QString("/tmp/conflated/pre.osm")); } MapCleaner().apply(_map); if (_debug) { _saveMap(QString("/tmp/conflated/post.osm")); } setSource(_map); }
void runBasicTest() { Settings::getInstance().clear(); OsmReader reader; OsmMap::resetCounters(); OsmSchema::getInstance().loadDefault(); shared_ptr<OsmMap> map(new OsmMap()); reader.setDefaultStatus(Status::Unknown1); reader.read("test-files/DcTigerRoads.osm", map); MapCleaner().apply(map); MapProjector::projectToWgs84(map); QDir().mkpath("test-output/conflate"); OsmWriter writer; writer.write(map, "test-output/conflate/MapCleaner.osm"); HOOT_FILE_EQUALS("test-files/conflate/MapCleaner.osm", "test-output/conflate/MapCleaner.osm"); }
void SearchRadiusCalculator::apply(shared_ptr<OsmMap>& map) { //make a copy of the map with previously conflated data removed, as the rubber sheeting can't //use it OsmMapPtr mapWithOnlyUnknown1And2(new OsmMap(map)); RemoveElementsVisitor elementRemover1(ElementCriterionPtr(new StatusCriterion(Status::Conflated))); elementRemover1.setRecursive(true); mapWithOnlyUnknown1And2->visitRw(elementRemover1); RemoveElementsVisitor elementRemover2(ElementCriterionPtr(new StatusCriterion(Status::Invalid))); elementRemover2.setRecursive(true); mapWithOnlyUnknown1And2->visitRw(elementRemover2); if (map->getElementCount() > mapWithOnlyUnknown1And2->getElementCount()) { LOG_INFO( "Skipping " << map->getElementCount() - mapWithOnlyUnknown1And2->getElementCount() << " conflated or invalid features out of " << map->getElementCount() << " total features."); } if (mapWithOnlyUnknown1And2->getElementCount() == 0) { _result = _circularError; LOG_WARN( "Unable to automatically calculate search radius. All features have already been " << "conflated or are invalid.\n Using default search radius value = " << QString::number(_result)); return; } RubberSheet rubberSheet; rubberSheet.setReference(_rubberSheetRef); rubberSheet.setMinimumTies(_minTies); try { rubberSheet.calculateTransform(mapWithOnlyUnknown1And2); } catch (const HootException& e) { //In many cases, the input map will have already been cleaned by this point...but possibly not. //Try to clean it to get around this error (call to the stats command, for example). LOG_INFO( "An error occurred calculating the rubber sheet transform during automatic search radius " << "calculation. Cleaning the data and attempting to calculate the transform again..."); MapCleaner().apply(mapWithOnlyUnknown1And2); try { rubberSheet.calculateTransform(mapWithOnlyUnknown1And2); } catch (const HootException& e) { _result = _circularError; LOG_WARN( QString("Unable to automatically calculate search radius: ") + e.getWhat() + QString("\n") + QString("Using default search radius value = ") + QString::number(_result)); return; } } vector<double> tiePointDistances; try { tiePointDistances = rubberSheet.calculateTiePointDistances(); } catch (const HootException& /*e*/) { //unrecoverable error...we'll end up using the default search distance instead } _calculateSearchRadius(tiePointDistances); }