public static OsmChange Merge(Osm reference, Osm subject, string scopeName, GeoJsonAPISource.Municipality municipality) { Log = Log ?? Static.LogFactory.CreateLogger(typeof(Conflate)); // Can blacklist subject elements also! Fixme: colisions between different element types with the same ID var subjectElements = subject.GetElements().Where(e => !municipality.BlackList.Contains(e.Id.Value)); var subjectElementIndex = new ElementIndex(subjectElements.ToArray()); List <OsmGeo> create = new List <OsmGeo>(reference.Nodes); List <OsmGeo> modify = new List <OsmGeo>(); List <OsmGeo> delete = new List <OsmGeo>(); Log.LogInformation("Starting conflation, matching by tags"); MergeNodesByTags(new[] { "addr:street", "addr:housenumber", "addr:unit" }, subjectElementIndex, municipality.WhiteList, create, modify); MergeNodesByTags(new[] { "addr:street", "addr:housenumber" }, subjectElementIndex, municipality.WhiteList, create, modify); MergeNodesByTags(new[] { "name" }, subjectElementIndex, municipality.WhiteList, create, modify); Log.LogInformation("Starting conflation, matching by geometry"); MergeNodesByGeometry(subjectElementIndex, municipality.WhiteList, create, modify); ValidateNamesMatch(subjectElementIndex, create.Concat(modify), "highway", "addr:street", (element, key) => ShouldStreetBeAPlace(element, subjectElementIndex)); ValidateNamesMatch(subjectElementIndex, create.Concat(modify), "place", "addr:place"); Log.LogInformation($"Writing {scopeName} review files"); var review = GatherExceptions(municipality.WhiteList, municipality.IgnoreList, subjectElementIndex, create, delete, modify); WriteToFileWithChildrenIfAny(scopeName + "/Conflated.Review.osm", review, subjectElementIndex); WriteToFileWithChildrenIfAny(scopeName + "/Conflated.Create.osm", create, subjectElementIndex); WriteToFileWithChildrenIfAny(scopeName + "/Conflated.Delete.osm", delete, subjectElementIndex); WriteToFileWithChildrenIfAny(scopeName + "/Conflated.Modify.osm", modify, subjectElementIndex); RemoveReviewTags(create, delete, modify); var change = Changes.FromGeos(create, modify, delete, "OsmPipeline"); LogSummary(change, review); return(change); }
public static long?GetHighestChangeSetId(this Osm osm) { return(osm.GetElements().Max(e => e.ChangeSetId)); }
public static Osm[] SliceRecusive(Osm osm, int maxElementsPerslice) { var index = OsmSharp.Db.Impl.Extensions.CreateSnapshotDb(new MemorySnapshotDb(osm.GetElements())); var completeWays = index.GetComplete().OfType <CompleteWay>().ToArray(); var slices = completeWays.SliceRecusive(maxElementsPerslice).ToDictionary(); var simpleSlices = slices.Select(kvp => kvp.Value.Select(e => e.ToSimple()).WithChildren(index).AsOsm(null, .6, kvp.Key)).ToArray(); return(simpleSlices); }