public IList <GeoCoordinate> GetCoordinates() { List <GeoCoordinate> geoCoordinateList = new List <GeoCoordinate>(); for (int index = 0; index < this.Members.Count; ++index) { if (this.Members[index].Member is Node) { Node member = this.Members[index].Member as Node; geoCoordinateList.Add(member.Coordinate); } else if (this.Members[index].Member is CompleteWay) { CompleteWay member = this.Members[index].Member as CompleteWay; geoCoordinateList.AddRange((IEnumerable <GeoCoordinate>)member.GetCoordinates()); } else if (this.Members[index].Member is CompleteRelation) { CompleteRelation member = this.Members[index].Member as CompleteRelation; geoCoordinateList.AddRange((IEnumerable <GeoCoordinate>)member.GetCoordinates()); } } return((IList <GeoCoordinate>)geoCoordinateList); }
public static CompleteRelation CreateFrom(Relation simpleRelation, IOsmGeoSource osmGeoSource, IDictionary <long, CompleteWay> ways, IDictionary <long, CompleteRelation> relations) { if (simpleRelation == null) { throw new ArgumentNullException("simpleRelation"); } if (osmGeoSource == null) { throw new ArgumentNullException("osmGeoSource"); } if (!simpleRelation.Id.HasValue) { throw new Exception("simpleRelation.Id is null"); } CompleteRelation completeRelation1 = CompleteRelation.Create(simpleRelation.Id.Value); completeRelation1.ChangeSetId = simpleRelation.ChangeSetId; foreach (Tag tag in simpleRelation.Tags) { completeRelation1.Tags.Add(tag); } long?nullable1; for (int index = 0; index < simpleRelation.Members.Count; ++index) { nullable1 = simpleRelation.Members[index].MemberId; long num = nullable1.Value; string memberRole = simpleRelation.Members[index].MemberRole; CompleteRelationMember completeRelationMember = new CompleteRelationMember(); completeRelationMember.Role = memberRole; switch (simpleRelation.Members[index].MemberType.Value) { case OsmGeoType.Node: Node node = osmGeoSource.GetNode(num); if (node == null) { return((CompleteRelation)null); } completeRelationMember.Member = (ICompleteOsmGeo)node; break; case OsmGeoType.Way: CompleteWay from1; if (!ways.TryGetValue(num, out from1)) { Way way = osmGeoSource.GetWay(num); if (way != null) { from1 = CompleteWay.CreateFrom(way, (INodeSource)osmGeoSource); } } if (!((CompleteOsmBase)from1 != (CompleteOsmBase)null)) { return((CompleteRelation)null); } completeRelationMember.Member = (ICompleteOsmGeo)from1; break; case OsmGeoType.Relation: CompleteRelation from2; if (!relations.TryGetValue(num, out from2)) { Relation relation = osmGeoSource.GetRelation(num); if (relation != null) { from2 = CompleteRelation.CreateFrom(relation, osmGeoSource); } } if (!((CompleteOsmBase)from2 != (CompleteOsmBase)null)) { return((CompleteRelation)null); } completeRelationMember.Member = (ICompleteOsmGeo)from2; break; } completeRelation1.Members.Add(completeRelationMember); } completeRelation1.TimeStamp = simpleRelation.TimeStamp; completeRelation1.User = simpleRelation.UserName; completeRelation1.UserId = simpleRelation.UserId; CompleteRelation completeRelation2 = completeRelation1; long? nullable2; if (!simpleRelation.Version.HasValue) { nullable1 = new long?(); nullable2 = nullable1; } else { nullable2 = new long?((long)simpleRelation.Version.Value); } completeRelation2.Version = nullable2; completeRelation1.Visible = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value; return(completeRelation1); }
public static CompleteRelation CreateFrom(ObjectTable <string> table, Relation simpleRelation, IDictionary <long, Node> nodes, IDictionary <long, CompleteWay> ways, IDictionary <long, CompleteRelation> relations) { if (simpleRelation == null) { throw new ArgumentNullException("simpleRelation"); } if (nodes == null) { throw new ArgumentNullException("nodes"); } if (ways == null) { throw new ArgumentNullException("ways"); } if (relations == null) { throw new ArgumentNullException("relations"); } if (!simpleRelation.Id.HasValue) { throw new Exception("simpleRelation.Id is null"); } CompleteRelation completeRelation1 = CompleteRelation.Create(table, simpleRelation.Id.Value); completeRelation1.ChangeSetId = simpleRelation.ChangeSetId; foreach (Tag tag in simpleRelation.Tags) { completeRelation1.Tags.Add(tag); } long?nullable1; for (int index = 0; index < simpleRelation.Members.Count; ++index) { nullable1 = simpleRelation.Members[index].MemberId; long key = nullable1.Value; string memberRole = simpleRelation.Members[index].MemberRole; CompleteRelationMember completeRelationMember = new CompleteRelationMember(); completeRelationMember.Role = memberRole; switch (simpleRelation.Members[index].MemberType.Value) { case OsmGeoType.Node: Node node = (Node)null; if (!nodes.TryGetValue(key, out node)) { return((CompleteRelation)null); } completeRelationMember.Member = (ICompleteOsmGeo)node; break; case OsmGeoType.Way: CompleteWay completeWay = (CompleteWay)null; if (!ways.TryGetValue(key, out completeWay)) { return((CompleteRelation)null); } completeRelationMember.Member = (ICompleteOsmGeo)completeWay; break; case OsmGeoType.Relation: CompleteRelation completeRelation2 = (CompleteRelation)null; if (!relations.TryGetValue(key, out completeRelation2)) { return((CompleteRelation)null); } completeRelationMember.Member = (ICompleteOsmGeo)completeRelation2; break; } completeRelation1.Members.Add(completeRelationMember); } completeRelation1.TimeStamp = simpleRelation.TimeStamp; completeRelation1.User = simpleRelation.UserName; completeRelation1.UserId = simpleRelation.UserId; CompleteRelation completeRelation3 = completeRelation1; ulong? version = simpleRelation.Version; long? nullable2; if (!version.HasValue) { nullable1 = new long?(); nullable2 = nullable1; } else { version = simpleRelation.Version; nullable2 = new long?((long)version.Value); } completeRelation3.Version = nullable2; completeRelation1.Visible = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value; return(completeRelation1); }
/// <summary> /// Creates a new relation from a SimpleRelation. /// </summary> /// <param name="table"></param> /// <param name="simpleRelation"></param> /// <param name="nodes"></param> /// <param name="ways"></param> /// <param name="relations"></param> /// <returns></returns> public static CompleteRelation CreateFrom(ObjectTable <string> table, Relation simpleRelation, IDictionary <long, Node> nodes, IDictionary <long, CompleteWay> ways, IDictionary <long, CompleteRelation> relations) { if (simpleRelation == null) { throw new ArgumentNullException("simpleRelation"); } if (nodes == null) { throw new ArgumentNullException("nodes"); } if (ways == null) { throw new ArgumentNullException("ways"); } if (relations == null) { throw new ArgumentNullException("relations"); } if (simpleRelation.Id == null) { throw new Exception("simpleRelation.Id is null"); } CompleteRelation relation = Create(table, simpleRelation.Id.Value); relation.ChangeSetId = simpleRelation.ChangeSetId; foreach (Tag pair in simpleRelation.Tags) { relation.Tags.Add(pair); } for (int idx = 0; idx < simpleRelation.Members.Count; idx++) { long memberId = simpleRelation.Members[idx].MemberId.Value; string role = simpleRelation.Members[idx].MemberRole; var member = new CompleteRelationMember(); member.Role = role; switch (simpleRelation.Members[idx].MemberType.Value) { case OsmGeoType.Node: Node node = null; if (nodes.TryGetValue(memberId, out node)) { member.Member = node; } else { return(null); } break; case OsmGeoType.Way: CompleteWay way = null; if (ways.TryGetValue(memberId, out way)) { member.Member = way; } else { return(null); } break; case OsmGeoType.Relation: CompleteRelation relationMember = null; if (relations.TryGetValue(memberId, out relationMember)) { member.Member = relationMember; } else { return(null); } break; } relation.Members.Add(member); } relation.TimeStamp = simpleRelation.TimeStamp; relation.User = simpleRelation.UserName; relation.UserId = simpleRelation.UserId; relation.Version = simpleRelation.Version.HasValue ? (long)simpleRelation.Version.Value : (long?)null; relation.Visible = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value; return(relation); }
/// <summary> /// Adds a new relation. /// </summary> /// <param name="relation"></param> public override void AddRelation(CompleteRelation relation) { _mapCSSInterpreter.Translate(_scene, _projection, relation); }
/// <summary> /// Compares the two complete objects. /// </summary> public static void CompareComplete(CompleteRelation expected, CompleteRelation actual) { if (expected == null) { // ok, if the value is also null. Assert.IsNull(actual); } else { // check and compare the value. Assert.IsNotNull(actual); Assert.AreEqual(expected.Id, actual.Id); Assert.AreEqual(expected.ChangeSetId, actual.ChangeSetId); Assert.AreEqual(expected.TimeStamp, actual.TimeStamp); Assert.AreEqual(expected.User, actual.User); Assert.AreEqual(expected.UserId, actual.UserId); Assert.AreEqual(expected.Version, actual.Version); Assert.AreEqual(expected.Visible, actual.Visible); if (expected.Members == null) { // ok, if the value is also null. Assert.IsNotNull(actual.Members); } else { // check and compare the nodes. Assert.AreEqual(expected.Members.Count, actual.Members.Count); for (int idx = 0; idx < expected.Members.Count; idx++) { CompleteRelationMember expectedMember = expected.Members[idx]; CompleteRelationMember actualMember = actual.Members[idx]; Assert.AreEqual(expectedMember.Role, actualMember.Role); Assert.IsNotNull(expectedMember.Member); Assert.IsNotNull(actualMember.Member); Assert.AreEqual(expectedMember.Member.Type, actualMember.Member.Type); switch (expectedMember.Member.Type) { case CompleteOsmType.Node: ComparisonHelpers.CompareComplete( expectedMember.Member as Node, actualMember.Member as Node); break; case CompleteOsmType.Way: ComparisonHelpers.CompareComplete( expectedMember.Member as CompleteWay, actualMember.Member as CompleteWay); break; case CompleteOsmType.Relation: ComparisonHelpers.CompareComplete( expectedMember.Member as CompleteRelation, actualMember.Member as CompleteRelation); break; } } } } }
/// <summary> /// Creates a relation from a SimpleRelation. /// </summary> /// <param name="simpleRelation"></param> /// <param name="osmGeoSource"></param> /// <param name="ways"></param> /// <param name="relations"></param> /// <returns></returns> public static CompleteRelation CreateFrom(Relation simpleRelation, IOsmGeoSource osmGeoSource, IDictionary <long, CompleteWay> ways, IDictionary <long, CompleteRelation> relations) { if (simpleRelation == null) { throw new ArgumentNullException("simpleRelation"); } if (osmGeoSource == null) { throw new ArgumentNullException("osmGeoSource"); } if (simpleRelation.Id == null) { throw new Exception("simpleRelation.Id is null"); } CompleteRelation relation = Create(simpleRelation.Id.Value); relation.ChangeSetId = simpleRelation.ChangeSetId; foreach (Tag pair in simpleRelation.Tags) { relation.Tags.Add(pair); } for (int idx = 0; idx < simpleRelation.Members.Count; idx++) { long memberId = simpleRelation.Members[idx].MemberId.Value; string role = simpleRelation.Members[idx].MemberRole; var member = new CompleteRelationMember(); member.Role = role; switch (simpleRelation.Members[idx].MemberType.Value) { case OsmGeoType.Node: Node simpleNode = osmGeoSource.GetNode(memberId); if (simpleNode != null) { member.Member = simpleNode; } else { return(null); } break; case OsmGeoType.Way: CompleteWay completeWay; if (!ways.TryGetValue(memberId, out completeWay)) { Way simpleWay = osmGeoSource.GetWay(memberId); if (simpleWay != null) { completeWay = CompleteWay.CreateFrom(simpleWay, osmGeoSource); } } if (completeWay != null) { member.Member = completeWay; } else { return(null); } break; case OsmGeoType.Relation: CompleteRelation completeRelation; if (!relations.TryGetValue(memberId, out completeRelation)) { Relation simpleRelationMember = osmGeoSource.GetRelation(memberId); if (simpleRelationMember != null) { completeRelation = CompleteRelation.CreateFrom(simpleRelationMember, osmGeoSource); } } if (completeRelation != null) { member.Member = completeRelation; } else { return(null); } break; } relation.Members.Add(member); } relation.TimeStamp = simpleRelation.TimeStamp; relation.User = simpleRelation.UserName; relation.UserId = simpleRelation.UserId; relation.Version = simpleRelation.Version.HasValue ? (long)simpleRelation.Version.Value : (long?)null; relation.Visible = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value; return(relation); }
/// <summary> /// Translates a relation. /// </summary> /// <param name="scene">The scene to add primitives to.</param> /// <param name="projection">The projection used to convert the objects.</param> /// <param name="relation"></param> private void TranslateRelation(Scene2D scene, IProjection projection, CompleteRelation relation) { }
/// <summary> /// Adds a relation to the target. /// </summary> /// <param name="relation"></param> public abstract void AddRelation(CompleteRelation relation);
public static List<CompleteWay> GetAllWays(CompleteRelation relation) { return GetAllWaysByRole(relation).SelectMany(kvp => kvp.Value).ToList(); }
private static Dictionary<string, List<CompleteWay>> GetAllWaysByRole(CompleteRelation relation) { var dicionary = relation.Members.GroupBy(m => m.Role ?? string.Empty) .ToDictionary(g => g.Key, g => g.Select(k => k.Member).OfType<CompleteWay>().ToList()); if (relation.Members.All(m => m.Member.Type != CompleteOsmType.Relation)) { return dicionary; } var subRelations = relation.Members.Select(m => m.Member).OfType<CompleteRelation>(); foreach (var subRelation in subRelations) { var subRelationDictionary = GetAllWaysByRole(subRelation); foreach (var key in subRelationDictionary.Keys) { if (dicionary.ContainsKey(key)) { dicionary[key].AddRange(subRelationDictionary[key]); } else { dicionary[key] = subRelationDictionary[key]; } } } return dicionary; }
private Feature ConvertToMultipolygon(CompleteRelation relation) { var outerWays = GetAllWaysByRole(relation).Where(kvp => kvp.Key == OUTER).SelectMany(kvp => kvp.Value).ToList(); var outerPolygons = GetGeometriesFromWays(outerWays).OfType<IPolygon>().ToList(); var innerWays = GetAllWaysByRole(relation).Where(kvp => kvp.Key != OUTER).SelectMany(kvp => kvp.Value).ToList(); var innerPolygons = GetGeometriesFromWays(innerWays).OfType<IPolygon>().ToList(); MergeInnerIntoOuterPolygon(ref outerPolygons, ref innerPolygons); var multiPolygon = new MultiPolygon(outerPolygons.Union(innerPolygons).ToArray()); return new Feature(multiPolygon, ConvertTags(relation.Tags, relation.Id)); }
private Feature ConvertRelation(CompleteRelation relation) { if (IsMultipolygon(relation)) { return ConvertToMultipolygon(relation); } var nodes = relation.Members.Select(m => m.Member).OfType<Node>().ToList(); if (nodes.Any()) { var multiPoint = new MultiPoint(nodes.Select(n => new Point(ConvertNode(n)) as IPoint).ToArray()); return new Feature(multiPoint, ConvertTags(relation.Tags, relation.Id)); } var geometries = GetGeometriesFromWays(GetAllWays(relation)); if (!geometries.Any()) { return null; } var jointLines = geometries.OfType<ILineString>().ToList(); jointLines.AddRange(geometries.OfType<Polygon>().Select(p => new LineString(p.Coordinates) as ILineString)); var multiLineString = new MultiLineString(jointLines.ToArray()); return new Feature(multiLineString, ConvertTags(relation.Tags, relation.Id)); }
/// <summary> /// Returns all restrictions that are represented by the given node. /// </summary> /// <param name="completeRelation"></param> /// <returns></returns> public List<KeyValuePair<Vehicle, long[]>> CalculateRestrictions(CompleteRelation completeRelation) { return new List<KeyValuePair<Vehicle, long[]>>(); }
/// <summary> /// Creates a relation from a SimpleRelation. /// </summary> /// <param name="simpleRelation"></param> /// <param name="cache"></param> /// <returns></returns> public static CompleteRelation CreateFrom(Relation simpleRelation, IDataSourceReadOnly cache) { if (simpleRelation == null) { throw new ArgumentNullException("simpleRelation"); } if (cache == null) { throw new ArgumentNullException("cache"); } if (simpleRelation.Id == null) { throw new Exception("simpleRelation.Id is null"); } CompleteRelation relation = Create(simpleRelation.Id.Value); relation.ChangeSetId = simpleRelation.ChangeSetId; foreach (Tag pair in simpleRelation.Tags) { relation.Tags.Add(pair); } for (int idx = 0; idx < simpleRelation.Members.Count; idx++) { long memberId = simpleRelation.Members[idx].MemberId.Value; string role = simpleRelation.Members[idx].MemberRole; var member = new CompleteRelationMember(); member.Role = role; switch (simpleRelation.Members[idx].MemberType.Value) { case OsmGeoType.Node: Node simpleNode = cache.GetNode(memberId); if (simpleNode != null) { member.Member = CompleteNode.CreateFrom(simpleNode); } else { return(null); } break; case OsmGeoType.Way: Way simpleWay = cache.GetWay(memberId); if (simpleWay != null) { member.Member = CompleteWay.CreateFrom(simpleWay, cache); } else { return(null); } break; case OsmGeoType.Relation: Relation simpleRelationMember = cache.GetRelation(memberId); if (simpleRelationMember != null) { member.Member = CompleteRelation.CreateFrom(simpleRelationMember, cache); } else { return(null); } break; } relation.Members.Add(member); } relation.TimeStamp = simpleRelation.TimeStamp; relation.User = simpleRelation.UserName; relation.UserId = simpleRelation.UserId; relation.Version = simpleRelation.Version.HasValue ? (long)simpleRelation.Version.Value : (long?)null; relation.Visible = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value; return(relation); }
/// <summary> /// Creates a relation from a SimpleRelation. /// </summary> /// <returns></returns> public static CompleteRelation CreateFrom(Relation simpleRelation, IOsmGeoSource osmGeoSource) { if (simpleRelation == null) { throw new ArgumentNullException("simpleRelation"); } if (osmGeoSource == null) { throw new ArgumentNullException("osmGeoSource"); } if (simpleRelation.Id == null) { throw new Exception("simpleRelation.Id is null"); } var relation = Create(simpleRelation.Id.Value); relation.ChangeSetId = simpleRelation.ChangeSetId; if (simpleRelation.Tags != null) { foreach (var pair in simpleRelation.Tags) { relation.Tags.Add(pair); } } if (simpleRelation.Members != null) { for (var idx = 0; idx < simpleRelation.Members.Count; idx++) { var memberId = simpleRelation.Members[idx].MemberId.Value; var role = simpleRelation.Members[idx].MemberRole; var member = new CompleteRelationMember(); member.Role = role; switch (simpleRelation.Members[idx].MemberType.Value) { case OsmGeoType.Node: var simpleNode = osmGeoSource.GetNode(memberId); if (simpleNode == null) { return(null); } var completeNode = simpleNode; if (completeNode != null) { member.Member = completeNode; } else { return(null); } break; case OsmGeoType.Way: var simpleWay = osmGeoSource.GetWay(memberId); if (simpleWay == null) { return(null); } var completeWay = CompleteWay.CreateFrom(simpleWay, osmGeoSource); if (completeWay != null) { member.Member = completeWay; } else { return(null); } break; case OsmGeoType.Relation: var simpleRelationMember = osmGeoSource.GetRelation(memberId); if (simpleRelationMember == null) { return(null); } var completeRelation = CompleteRelation.CreateFrom(simpleRelationMember, osmGeoSource); if (completeRelation != null) { member.Member = completeRelation; } else { return(null); } break; } relation.Members.Add(member); } } relation.TimeStamp = simpleRelation.TimeStamp; relation.User = simpleRelation.UserName; relation.UserId = simpleRelation.UserId; relation.Version = simpleRelation.Version.HasValue ? (long)simpleRelation.Version.Value : (long?)null; relation.Visible = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value; return(relation); }