示例#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
        /// <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);
        }
示例#3
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);
        }
示例#4
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);
        }