Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new relation from a SimpleRelation.
        /// </summary>
        /// <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");

            var relation = Create(table, simpleRelation.Id.Value);
            relation.ChangeSetId = simpleRelation.ChangeSetId;
            foreach (var pair in simpleRelation.Tags)
            {
                relation.Tags.Add(pair);
            }
            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:
                        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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a relation from a SimpleRelation.
        /// </summary>
        /// <param name="simpleRelation"></param>
        /// <param name="nodes"></param>
        /// <param name="ways"></param>
        /// <param name="relations"></param>
        /// <returns></returns>
        public static CompleteRelation CreateFrom(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(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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a relation from a SimpleRelation.
        /// </summary>
        /// <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");

            var relation = Create(simpleRelation.Id.Value);
            relation.ChangeSetId = simpleRelation.ChangeSetId;
            foreach (var 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:
                        var 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))
                        {
                            var 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;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a relation from a SimpleRelation.
        /// </summary>
        /// <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");
            }

            var relation = Create(simpleRelation.Id.Value);

            relation.ChangeSetId = simpleRelation.ChangeSetId;
            foreach (var 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:
                    var 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))
                    {
                        var 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);
        }