/// <summary> /// Adds or appends the tag value to the value collection. /// </summary> public static void AddOrAppend(this TagsCollectionBase tags, Tag tag) { foreach (var t in tags) { if (t.Key == tag.Key) { if (!string.IsNullOrWhiteSpace(t.Value)) { var values = t.Value.Split(','); for (var i = 0; i < values.Length; i++) { if (values[i] == tag.Value) { return; } } tags.AddOrReplace(tag.Key, t.Value + "," + tag.Value); } else { tags.AddOrReplace(tag); } return; } } tags.Add(tag); }
private void SetWebsiteUrl(TagsCollectionBase tags, PointOfInterestExtended pointOfInterest) { var regexp = new Regex("((https?://)|^)([a-z]+).wikipedia.org/wiki/(.*)"); var nonWikipediaUrls = new List <string>(); foreach (var url in pointOfInterest.References.Select(r => r.Url)) { var match = regexp.Match(url ?? string.Empty); if (!match.Success) { nonWikipediaUrls.Add(url); continue; } var language = match.Groups[3].Value; var pageTitle = Uri.UnescapeDataString(match.Groups[4].Value.Replace("_", " ")); var key = FeatureAttributes.WIKIPEDIA + ":" + language; tags.AddOrReplace(key, pageTitle); key = FeatureAttributes.WIKIPEDIA; pageTitle = language + ":" + pageTitle; if (tags.ContainsKey(key) == false) { tags.Add(key, pageTitle); } } SetMultipleValuesForTag(tags, FeatureAttributes.WEBSITE, nonWikipediaUrls.ToArray()); }
private void SetMultipleValuesForTag(TagsCollectionBase tags, string tagKey, string[] values) { for (var index = 0; index < values.Length; index++) { var value = values[index]; var tagName = index == 0 ? tagKey : tagKey + index; tags.AddOrReplace(tagName, value); } }
private void AddTagsByIcon(TagsCollectionBase tags, string icon) { var tagsList = _tagsHelper.FindTagsForIcon(icon); if (tagsList.Any()) { tags.AddOrReplace(tagsList.First().Key, tagsList.First().Value); } }
public static FeatureCollection GetFeaturesIn(this RouterDb db, float minLatitude, float minLongitude, float maxLatitude, float maxLongitude) { RoutingNetwork network = db.Network; FeatureCollection featureCollection = new FeatureCollection(); HashSet <uint> uintSet1 = network.GeometricGraph.Search(minLatitude, minLongitude, maxLatitude, maxLongitude); HashSet <long> longSet = new HashSet <long>(); RoutingNetwork.EdgeEnumerator edgeEnumerator = network.GetEdgeEnumerator(); HashSet <uint> uintSet2 = new HashSet <uint>(); foreach (uint vertex1 in uintSet1) { GeoCoordinateSimple vertex2 = network.GeometricGraph.GetVertex(vertex1); featureCollection.Add(new Feature((Geometry) new Point(new GeoCoordinate((double)vertex2.Latitude, (double)vertex2.Longitude)), (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>) new Tag[1] { Tag.Create("id", vertex1.ToInvariantString()) }))); edgeEnumerator.MoveTo(vertex1); edgeEnumerator.Reset(); while (edgeEnumerator.MoveNext()) { if (!longSet.Contains((long)edgeEnumerator.Id)) { longSet.Add((long)edgeEnumerator.Id); List <ICoordinate> shape = network.GetShape(edgeEnumerator.Current); List <GeoCoordinate> geoCoordinateList = new List <GeoCoordinate>(); foreach (ICoordinate coordinate in shape) { geoCoordinateList.Add(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude)); } LineString lineString = new LineString((IEnumerable <GeoCoordinate>)geoCoordinateList); RouterDb db1 = db; EdgeData data = edgeEnumerator.Data; int profile = (int)data.Profile; data = edgeEnumerator.Data; int metaId = (int)data.MetaId; TagsCollectionBase profileAndMeta = db1.GetProfileAndMeta((uint)profile, (uint)metaId); profileAndMeta.AddOrReplace(Tag.Create("id", edgeEnumerator.Id.ToInvariantString())); featureCollection.Add(new Feature((Geometry)lineString, (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>)profileAndMeta))); if (!uintSet1.Contains(edgeEnumerator.To)) { uintSet2.Add(edgeEnumerator.To); } } } } foreach (uint vertex1 in uintSet2) { GeoCoordinateSimple vertex2 = network.GeometricGraph.GetVertex(vertex1); featureCollection.Add(new Feature((Geometry) new Point(new GeoCoordinate((double)vertex2.Latitude, (double)vertex2.Longitude)), (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>) new Tag[1] { Tag.Create("id", vertex1.ToInvariantString()) }))); } return(featureCollection); }
public static FeatureCollection GetFeatures(this RouterDb db) { RoutingNetwork network = db.Network; FeatureCollection featureCollection = new FeatureCollection(); HashSet <long> longSet = new HashSet <long>(); RoutingNetwork.EdgeEnumerator edgeEnumerator = network.GetEdgeEnumerator(); for (uint vertex1 = 0; vertex1 < network.VertexCount; ++vertex1) { GeoCoordinateSimple vertex2 = network.GeometricGraph.GetVertex(vertex1); featureCollection.Add(new Feature((Geometry) new Point(new GeoCoordinate((double)vertex2.Latitude, (double)vertex2.Longitude)), (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>) new Tag[1] { Tag.Create("id", vertex1.ToInvariantString()) }))); edgeEnumerator.MoveTo(vertex1); edgeEnumerator.Reset(); while (edgeEnumerator.MoveNext()) { if (!longSet.Contains((long)edgeEnumerator.Id)) { longSet.Add((long)edgeEnumerator.Id); List <ICoordinate> shape = network.GetShape(edgeEnumerator.Current); List <GeoCoordinate> geoCoordinateList = new List <GeoCoordinate>(); foreach (ICoordinate coordinate in shape) { geoCoordinateList.Add(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude)); } LineString lineString = new LineString((IEnumerable <GeoCoordinate>)geoCoordinateList); TagsCollectionBase profileAndMeta = db.GetProfileAndMeta((uint)edgeEnumerator.Data.Profile, edgeEnumerator.Data.MetaId); profileAndMeta.AddOrReplace(Tag.Create("id", edgeEnumerator.Id.ToInvariantString())); featureCollection.Add(new Feature((Geometry)lineString, (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>)profileAndMeta))); } } } return(featureCollection); }
/// <summary> /// The actual conflation. /// Returns true if conflation is finished and this grbPoly has been matched /// </summary> private static bool AttemptConflate(Geometry grbPoly, Geometry osmPoly, TagsCollectionBase grbTags, ICompleteOsmGeo osmObj, EasyChangeset cs) { // Is there geographical match? if (Math.Abs(osmPoly.Centroid.Distance(grbPoly.Centroid)) > 0.000001) { return(false); } if (osmPoly.Difference(grbPoly).Area > 0.000000001) { return(false); } if (grbPoly.Difference(osmPoly).Area > 0.000000001) { return(false); } if (grbTags == null) { Console.WriteLine("PANIC for grb object " + grbPoly); return(false); } if (osmObj.Tags.TryGetValue("building", out var osmBuildingValue)) { if (osmBuildingValue.Equals("yes")) { osmObj.Tags.RemoveKey("building"); } else { grbTags.TryGetValue("building", out var grbBuildingValue); if (grbBuildingValue == null) { Console.WriteLine("GRB Building value is null"); } else if (osmBuildingValue != grbBuildingValue) { if (!grbBuildingValue.Equals("yes")) { Console.WriteLine( $"Preferring OSM building-tag '{osmBuildingValue}' over the grb tag '{grbBuildingValue}'"); } grbTags.RemoveKey("building"); } } } if (osmObj.Tags.TryGetValue("source:geometry:ref", out var osmSourceRef)) { grbTags.TryGetValue("source:geometry:ref", out var grbRef); if (!osmSourceRef.Equals(grbRef)) { throw new Exception($"MISMATCH for {osmObj}: {osmSourceRef} != {grbRef}"); } osmObj.Tags.RemoveKey("source:geometry:date"); } if (osmObj.Tags.TryGetValue("addr:housenumber", out var osmHouseNumber)) { grbTags.TryGetValue("addr:housenumber", out var grbHouseNumber); if (!osmHouseNumber.Equals(grbHouseNumber)) { grbTags.RemoveKey("addr:housenumber"); var msg = "GRB thinks that this has number " + (string.IsNullOrEmpty(grbHouseNumber) ? "no number" : grbHouseNumber); Console.WriteLine( $"GRB and OSM disagree over housenumber of {osmObj}. Putting a fixme instead: grb: {grbHouseNumber} != osm {osmHouseNumber}"); if (grbTags.ContainsKey("fixme")) { msg += ";" + grbTags.GetValue("fixme"); } grbTags.AddOrReplace("fixme", msg); } } if (osmObj.Tags.TryGetValue("addr:street", out var osmStreet)) { grbTags.TryGetValue("addr:street", out var grbStreet); if (!string.IsNullOrEmpty(grbStreet) && !osmStreet.Equals(grbStreet)) { grbTags.RemoveKey("addr:street"); var msg = "GRB thinks that this lays in street " + grbStreet; Console.WriteLine( $"GRB and OSM disagree over streetname of {osmObj}. Putting a fixme instead: grb: {grbStreet} != osm {osmStreet}"); if (grbTags.ContainsKey("fixme")) { msg += ";" + grbTags.GetValue("fixme"); } grbTags.AddOrReplace("fixme", msg); } } try { foreach (var grbTag in grbTags) { if (grbTag.Key.Contains("wrong")) { continue; } osmObj.AddNewTag(grbTag.Key, grbTag.Value); } cs.AddChange(osmObj); } catch (Exception e) { Console.WriteLine($"{osmObj}: {e.Message}: skipping match"); } return(true); }
/// <summary> /// Adds or replaces an attribute. /// </summary> public void AddOrReplace(string key, string value) { _tagCollection.AddOrReplace(key, value); }