Exemplo n.º 1
0
        public static long[] UndoTagFromAllUserChanges(long userId, Tag badTag, Tag?replaceWith = null)
        {
            var changesetids    = OneOffs.GetUsersChangesetIds(userId);
            var changes         = OneOffs.GetElementsFromChanges(changesetids);
            var badChanges      = changes.Where(e => e.Tags != null && e.Tags.Contains(badTag)).Select(e => new OsmGeoKey(e)).Distinct().ToArray();
            var currentVersions = OsmApiClient.GetElements(badChanges).Result;
            var fix             = OneOffs.UndoTagFromElements(badTag, currentVersions, replaceWith);
            var changesetTags   = GetCommitTags($"Undo all instances of {badTag} from user {userId}.");
            var fixIds          = Subjects.UploadChange(fix, changesetTags, @"FIX Offices\Uploaded\").Result;

            return(fixIds);
        }
Exemplo n.º 2
0
        public static void FixImportedNames()
        {
            var nameIndex = OneOffs.GetAllChangeElements(e => e.Tags != null && e.Tags.ContainsKey("addr:unit"))
                            .GroupBy(e => e.Tags["addr:unit"])
                            .ToDictionary(g => g.Key, g => g.ToArray());

            Console.Write(string.Join(Environment.NewLine,
                                      nameIndex.OrderByDescending(kvp => kvp.Value.Length).Select(kvp => kvp.Value.Length + "x: " + kvp.Key + "\texample: " + kvp.Value.First().Type + " " + kvp.Value.First().Id)));
            var nameDestinations = new Dictionary <string, string>
            {
            };
            var toUpdate = new List <OsmGeo>();

            var currentKeys = nameDestinations.Keys.SelectMany(n => nameIndex[n].Select(e => new OsmGeoKey(e))).Distinct().ToArray();
            var allCurrents = GetCurrentVersionOfElements(currentKeys).ToDictionary(e => new OsmGeoKey(e));
            var missing     = currentKeys.Except(allCurrents.Keys).Select(k => k.Type + " " + k.Id).ToArray();

            foreach (var name in nameDestinations)
            {
                var keys = nameIndex[name.Key].Select(e => new OsmGeoKey(e)).ToArray();

                var currents = keys
                               .Where(k => allCurrents.ContainsKey(k))
                               .Select(k => allCurrents[k])
                               .Where(e => e.Visible == true && e.Tags != null && e.Tags.Contains("addr:unit", name.Key))
                               .ToArray();

                foreach (var element in currents)
                {
                    if (name.Value == null)
                    {
                        element.Tags.RemoveKey("addr:unit");
                    }
                    else
                    {
                        element.Tags.AddOrReplace("addr:unit", name.Value);
                    }

                    toUpdate.Add(element);
                }
            }

            var fix = new OsmChange()
            {
                Modify = toUpdate.ToArray()
            };

            FileSerializer.WriteXml("temp change.osc", fix);
            var changesetTags = GetCommitTags($"Fixing bad addr:unit previously imported.");
            var fixIds        = Subjects.UploadChange(fix, changesetTags, @"FIX Offices\Uploaded\").Result;
        }