MCPcopy Create free account
hub / github.com/comaps/comaps / MigrateWayOrRelatonFeatureIndex

Function MigrateWayOrRelatonFeatureIndex

libs/editor/edits_migration.cpp:47–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47FeatureID MigrateWayOrRelatonFeatureIndex(
48 osm::Editor::ForEachFeaturesNearByFn & forEach, XMLFeature const & xml,
49 FeatureStatus const /* Unused for now (we don't create/delete area features)*/,
50 GenerateIDFn const & /*Unused for the same reason*/)
51{
52 std::optional<FeatureID> fid;
53 auto bestScore = 0.6; // initial score is used as a threshold.
54 auto geometry = xml.GetGeometry();
55 auto count = 0;
56
57 if (geometry.empty())
58 MYTHROW(MigrationError, ("Feature has invalid geometry", xml));
59
60 // This can be any point on a feature.
61 auto const someFeaturePoint = geometry[0];
62
63 forEach([&fid, &geometry, &count, &bestScore](FeatureType & ft)
64 {
65 if (ft.GetGeomType() != feature::GeomType::Area)
66 return;
67 ++count;
68
69 std::vector<m2::PointD> ftGeometry;
70 assign_range(ftGeometry, ft.GetTrianglesAsPoints(FeatureType::BEST_GEOMETRY));
71
72 double score = 0.0;
73 try
74 {
75 score = matcher::ScoreTriangulatedGeometries(geometry, ftGeometry);
76 }
77 catch (geometry::NotAPolygonException & ex)
78 {
79 LOG(LWARNING, (ex.Msg()));
80 // Support migration for old application versions.
81 // TODO(a): To remove it when version 8.0.x will no longer be supported.
82 base::SortUnique(geometry);
83 base::SortUnique(ftGeometry);
84 score = matcher::ScoreTriangulatedGeometriesByPoints(geometry, ftGeometry);
85 }
86
87 if (score > bestScore)
88 {
89 bestScore = score;
90 fid = ft.GetID();
91 }
92 }, someFeaturePoint);
93
94 if (count == 0)
95 MYTHROW(MigrationError, ("No ways returned for point", someFeaturePoint));
96
97 if (!fid)
98 MYTHROW(MigrationError, ("None of returned ways suffice. Possibly, the feature has been deleted."));
99 return *fid;
100}
101
102FeatureID MigrateFeatureIndex(osm::Editor::ForEachFeaturesNearByFn & forEach, XMLFeature const & xml,
103 FeatureStatus const featureStatus, GenerateIDFn const & generateID)

Callers 1

MigrateFeatureIndexFunction · 0.85

Calls 8

assign_rangeFunction · 0.85
SortUniqueFunction · 0.85
GetGeometryMethod · 0.45
emptyMethod · 0.45
GetGeomTypeMethod · 0.45
GetIDMethod · 0.45

Tested by

no test coverage detected