/// <summary> /// Creates a new way from a SimpleWay. /// </summary> /// <param name="simpleWay"></param> /// <param name="nodeSource"></param> /// <returns></returns> public static CompleteWay CreateFrom(Way simpleWay, INodeSource nodeSource) { if (simpleWay == null) { throw new ArgumentNullException("simpleWay"); } if (nodeSource == null) { throw new ArgumentNullException("nodeSource"); } if (simpleWay.Id == null) { throw new Exception("simpleWay.id is null"); } CompleteWay way = Create(simpleWay.Id.Value); way.ChangeSetId = simpleWay.ChangeSetId; if (simpleWay.Tags != null) { foreach (Tag pair in simpleWay.Tags) { way.Tags.Add(pair); } } for (int idx = 0; idx < simpleWay.Nodes.Count; idx++) { long nodeId = simpleWay.Nodes[idx]; Node node = nodeSource.GetNode(nodeId); if (node == null) { return(null); } CompleteNode completeNode = CompleteNode.CreateFrom(node); if (completeNode != null) { way.Nodes.Add(completeNode); } else { return(null); } } way.TimeStamp = simpleWay.TimeStamp; way.User = simpleWay.UserName; way.UserId = simpleWay.UserId; way.Version = simpleWay.Version.HasValue ? (long)simpleWay.Version.Value : (long?)null; way.Visible = simpleWay.Visible.HasValue && simpleWay.Visible.Value; return(way); }
/// <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 = CompleteNode.CreateFrom(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> /// 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); }