コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Extensions.cs プロジェクト: OsmSharp/core
        /// <summary>
        /// Creates a complete relation.
        /// </summary>
        public static CompleteRelation CreateComplete(this Relation relation, IOsmGeoSource osmGeoSource)
        {
            if (relation == null)
            {
                throw new ArgumentNullException("relation");
            }
            if (relation.Id == null)
            {
                throw new Exception("relation.Id is null");
            }
            if (osmGeoSource == null)
            {
                throw new ArgumentNullException("osmGeoSource");
            }

            var completeRelation = new CompleteRelation();

            completeRelation.Id = relation.Id.Value;

            completeRelation.ChangeSetId = relation.ChangeSetId;
            if (relation.Tags != null)
            {
                completeRelation.Tags = new TagsCollection(relation.Tags);
            }
            if (relation.Members != null)
            {
                var relationMembers = new List <CompleteRelationMember>();
                for (var i = 0; i < relation.Members.Length; i++)
                {
                    var memberId = relation.Members[i].Id;
                    var role     = relation.Members[i].Role;
                    var member   = new CompleteRelationMember();
                    member.Role = role;
                    switch (relation.Members[i].Type)
                    {
                    case OsmGeoType.Node:
                        var memberNode = osmGeoSource.GetNode(memberId);
                        if (memberNode == null)
                        {
                            continue;
                        }
                        var completeMemberNode = memberNode;
                        if (completeMemberNode != null)
                        {
                            member.Member = completeMemberNode;
                        }
                        else
                        {
                            continue;
                        }
                        break;

                    case OsmGeoType.Way:
                        var memberWay = osmGeoSource.GetWay(memberId);
                        if (memberWay == null)
                        {
                            continue;
                        }
                        var completeMemberWay = memberWay.CreateComplete(osmGeoSource);
                        if (completeMemberWay != null)
                        {
                            member.Member = completeMemberWay;
                        }
                        else
                        {
                            continue;
                        }
                        break;

                    case OsmGeoType.Relation:
                        if (relation.Id == memberId)
                        {
                            continue;
                        }
                        var relationMember = osmGeoSource.GetRelation(memberId);
                        if (relationMember == null)
                        {
                            continue;
                        }
                        var completeMemberRelation = relationMember.CreateComplete(osmGeoSource);
                        if (completeMemberRelation != null)
                        {
                            member.Member = completeMemberRelation;
                        }
                        else
                        {
                            continue;
                        }
                        break;
                    }
                    relationMembers.Add(member);
                }
                completeRelation.Members = relationMembers.ToArray();
            }
            completeRelation.TimeStamp = relation.TimeStamp;
            completeRelation.UserName  = relation.UserName;
            completeRelation.UserId    = relation.UserId;
            completeRelation.Version   = relation.Version;
            completeRelation.Visible   = relation.Visible;
            return(completeRelation);
        }
コード例 #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;
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        /// <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);
        }