예제 #1
0
        /// <summary>
        /// Converts a domain model relation to an Xml relation.
        /// </summary>
        /// <returns></returns>
        public static relation ConvertTo(this OsmSharp.Osm.Relation relation)
        {
            relation xmlRelation = new relation();

            // set the changeset.
            if (relation.ChangeSetId.HasValue)
            {
                xmlRelation.changeset          = relation.ChangeSetId.Value;
                xmlRelation.changesetSpecified = true;
            }

            // set the id.
            if (relation.Id.HasValue)
            {
                xmlRelation.id          = relation.Id.Value;
                xmlRelation.idSpecified = true;
            }
            else
            {
                xmlRelation.idSpecified = false;
            }

            if (relation.Tags != null)
            {
                xmlRelation.tag = new tag[relation.Tags.Count];
                int idx = 0;
                foreach (var tag in relation.Tags)
                {
                    tag t = new tag();
                    t.k = tag.Key;
                    t.v = tag.Value;
                    xmlRelation.tag[idx] = t;
                    idx++;
                }
            }

            // set the timestamp.
            if (relation.TimeStamp.HasValue)
            {
                xmlRelation.timestamp          = relation.TimeStamp.Value;
                xmlRelation.timestampSpecified = true;
            }

            // set the user data.
            if (relation.UserId.HasValue)
            {
                xmlRelation.uid          = relation.UserId.Value;
                xmlRelation.uidSpecified = true;
            }
            xmlRelation.user = xmlRelation.user;

            // set the version.
            if (relation.Version.HasValue)
            {
                xmlRelation.version          = (ulong)relation.Version.Value;
                xmlRelation.versionSpecified = true;
            }

            // set the visible.
            if (relation.Visible.HasValue)
            {
                xmlRelation.visible          = relation.Visible.Value;
                xmlRelation.visibleSpecified = true;
            }
            else
            {
                xmlRelation.visibleSpecified = false;
            }

            // set the way-specific properties.
            xmlRelation.member = new member[relation.Members.Count];
            for (int i = 0; i < relation.Members.Count; i++)
            {
                var member = relation.Members[i];
                var m      = new member();

                if (member.MemberType.HasValue)
                {
                    switch (member.MemberType.Value)
                    {
                    case OsmGeoType.Node:
                        m.type          = memberType.node;
                        m.typeSpecified = true;
                        break;

                    case OsmGeoType.Relation:
                        m.type          = memberType.relation;
                        m.typeSpecified = true;
                        break;

                    case OsmGeoType.Way:
                        m.type          = memberType.way;
                        m.typeSpecified = true;
                        break;
                    }
                }
                else
                {
                    m.typeSpecified = false;
                }

                if (member.MemberId.HasValue)
                {
                    m.@ref         = member.MemberId.Value;
                    m.refSpecified = true;
                }
                else
                {
                    m.refSpecified = false;
                }
                m.role = member.MemberRole;

                xmlRelation.member[i] = m;
            }

            return(xmlRelation);
        }
예제 #2
0
        /// <summary>
        /// Converts an Xml relation to an Osm domain model relation.
        /// </summary>
        /// <param name="xml_obj"></param>
        /// <returns></returns>
        public static Relation ConvertFrom(this relation xml_obj)
        {
            // create a new node and immidiately set the id.
            Relation new_obj = new Relation();

            new_obj.Id = xml_obj.id;

            // set the members
            new_obj.Members = new List <RelationMember>(xml_obj.member.Length);
            for (int idx = 0; idx < xml_obj.member.Length; idx++)
            {
                member         member       = xml_obj.member[idx];
                RelationMember simpleMember = new RelationMember();
                simpleMember.MemberId   = member.@ref;
                simpleMember.MemberRole = member.role;
                if (member.refSpecified && member.typeSpecified)
                {
                    switch (member.type)
                    {
                    case memberType.node:
                        simpleMember.MemberType = OsmGeoType.Node;
                        break;

                    case memberType.relation:
                        simpleMember.MemberType = OsmGeoType.Relation;
                        break;

                    case memberType.way:
                        simpleMember.MemberType = OsmGeoType.Way;
                        break;
                    }
                }
                else
                { // way cannot be converted; member could not be created!
                    return(null);
                }
                new_obj.Members.Add(simpleMember);
            }

            // set the tags.
            if (xml_obj.tag != null)
            {
                foreach (Osm.Xml.v0_6.tag tag in xml_obj.tag)
                {
                    new_obj.Tags.Add(tag.k, tag.v);
                }
            }

            // set the user info.
            if (xml_obj.uidSpecified)
            {
                new_obj.UserId = xml_obj.uid;
            }
            new_obj.UserName = xml_obj.user;

            // set the changeset info.
            if (xml_obj.changesetSpecified)
            {
                new_obj.ChangeSetId = xml_obj.changeset;
            }

            // set the timestamp flag.
            if (xml_obj.timestampSpecified)
            {
                new_obj.TimeStamp = xml_obj.timestamp;
            }

            // set the visible flag.
            new_obj.Visible = xml_obj.visible;
            return(new_obj);
        }
예제 #3
0
        /// <summary>
        /// Converts a domain model relation to an Xml relation.
        /// </summary>
        /// <param name="dom_obj"></param>
        /// <returns></returns>
        public static relation ConvertTo(this OsmSharp.Osm.Relation dom_obj)
        {
            relation xml_obj = new relation();

            // set the changeset.
            if (dom_obj.ChangeSetId.HasValue)
            {
                xml_obj.changeset = dom_obj.ChangeSetId.Value;
                xml_obj.changesetSpecified = true;
            }

            // set the id.
            if (dom_obj.Id.HasValue)
            {
                xml_obj.id = dom_obj.Id.Value;
                xml_obj.idSpecified = true;
            }
            else
            {
                xml_obj.idSpecified = false;
            }

            if (dom_obj.Tags != null)
            {
                xml_obj.tag = new tag[dom_obj.Tags.Count];
                int idx = 0;
                foreach (var tag in dom_obj.Tags)
                {
                    tag t = new tag();
                    t.k = tag.Key;
                    t.v = tag.Value;
                    xml_obj.tag[idx] = t;
                    idx++;
                }
            }

            // set the timestamp.
            if (dom_obj.TimeStamp.HasValue)
            {
                xml_obj.timestamp = dom_obj.TimeStamp.Value;
                xml_obj.timestampSpecified = true;
            }

            // set the user data.
            if (dom_obj.UserId.HasValue)
            {
                xml_obj.uid = dom_obj.UserId.Value;
                xml_obj.uidSpecified = true;
            }
            xml_obj.user = xml_obj.user;

            // set the version.
            if (dom_obj.Version.HasValue)
            {
                xml_obj.version = (ulong)dom_obj.Version.Value;
                xml_obj.versionSpecified = true;
            }

            // set the visible.
            if (dom_obj.Visible.HasValue)
            {
                xml_obj.visible = dom_obj.Visible.Value;
                xml_obj.visibleSpecified = true;
            }
            else
            {
                xml_obj.visibleSpecified = false;
            }

            // set the way-specific properties.
            xml_obj.member = new member[dom_obj.Members.Count];
            for (int idx = 0; idx < dom_obj.Members.Count; idx++)
            {
                RelationMember dom_member = dom_obj.Members[idx];
                member m = new member();

                if (dom_member.MemberType.HasValue)
                {
                    switch (dom_member.MemberType.Value)
                    {
                        case OsmGeoType.Node:
                            m.type = memberType.node;
                            m.typeSpecified = true;
                            break;
                        case OsmGeoType.Relation:
                            m.type = memberType.relation;
                            m.typeSpecified = true;
                            break;
                        case OsmGeoType.Way:
                            m.type = memberType.way;
                            m.typeSpecified = true;
                            break;
                    }
                }
                else
                {
                    m.typeSpecified = false;
                }

                if (dom_member.MemberId.HasValue)
                {
                    m.@ref = dom_member.MemberId.Value;
                    m.refSpecified = true;
                }
                else
                {
                    m.refSpecified = false;
                }
                m.role = dom_member.MemberRole;

                xml_obj.member[idx] = m;
            }

            return xml_obj;
        }
예제 #4
0
        public static relation ConvertTo(this Relation relation)
        {
            relation relation1 = new relation();
            long?    nullable;

            if (relation.ChangeSetId.HasValue)
            {
                relation relation2 = relation1;
                nullable = relation.ChangeSetId;
                long num = nullable.Value;
                relation2.changeset          = num;
                relation1.changesetSpecified = true;
            }
            nullable = relation.Id;
            if (nullable.HasValue)
            {
                relation relation2 = relation1;
                nullable = relation.Id;
                long num = nullable.Value;
                relation2.id          = num;
                relation1.idSpecified = true;
            }
            else
            {
                relation1.idSpecified = false;
            }
            if (relation.Tags != null)
            {
                relation1.tag = new tag[relation.Tags.Count];
                int index = 0;
                foreach (Tag tag in relation.Tags)
                {
                    relation1.tag[index] = new tag()
                    {
                        k = tag.Key,
                        v = tag.Value
                    };
                    ++index;
                }
            }
            if (relation.TimeStamp.HasValue)
            {
                relation1.timestamp          = relation.TimeStamp.Value;
                relation1.timestampSpecified = true;
            }
            nullable = relation.UserId;
            if (nullable.HasValue)
            {
                relation relation2 = relation1;
                nullable = relation.UserId;
                long num = nullable.Value;
                relation2.uid          = num;
                relation1.uidSpecified = true;
            }
            relation1.user = relation1.user;
            ulong?version = relation.Version;

            if (version.HasValue)
            {
                relation relation2 = relation1;
                version = relation.Version;
                long num = (long)version.Value;
                relation2.version          = (ulong)num;
                relation1.versionSpecified = true;
            }
            if (relation.Visible.HasValue)
            {
                relation1.visible          = relation.Visible.Value;
                relation1.visibleSpecified = true;
            }
            else
            {
                relation1.visibleSpecified = false;
            }
            relation1.member = new member[relation.Members.Count];
            for (int index = 0; index < relation.Members.Count; ++index)
            {
                RelationMember member1 = relation.Members[index];
                member         member2 = new member();
                if (member1.MemberType.HasValue)
                {
                    switch (member1.MemberType.Value)
                    {
                    case OsmGeoType.Node:
                        member2.type          = memberType.node;
                        member2.typeSpecified = true;
                        break;

                    case OsmGeoType.Way:
                        member2.type          = memberType.way;
                        member2.typeSpecified = true;
                        break;

                    case OsmGeoType.Relation:
                        member2.type          = memberType.relation;
                        member2.typeSpecified = true;
                        break;
                    }
                }
                else
                {
                    member2.typeSpecified = false;
                }
                nullable = member1.MemberId;
                if (nullable.HasValue)
                {
                    member member3 = member2;
                    nullable = member1.MemberId;
                    long num = nullable.Value;
                    member3.@ref         = num;
                    member2.refSpecified = true;
                }
                else
                {
                    member2.refSpecified = false;
                }
                member2.role            = member1.MemberRole;
                relation1.member[index] = member2;
            }
            return(relation1);
        }
예제 #5
0
        /// <summary>
        /// Converts a domain model relation to an Xml relation.
        /// </summary>
        /// <param name="dom_obj"></param>
        /// <returns></returns>
        public static relation ConvertTo(this Relation dom_obj)
        {
            relation xml_obj = new relation();

            // set the changeset.
            if (dom_obj.ChangeSetId.HasValue)
            {
                xml_obj.changeset = dom_obj.ChangeSetId.Value;
                xml_obj.changesetSpecified = true;
            }

            // set the id.
            xml_obj.id = dom_obj.Id;
            xml_obj.idSpecified = true;

            if (dom_obj.Tags != null)
            {
                xml_obj.tag = new tag[dom_obj.Tags.Count];
                IList<KeyValuePair<string, string>> tags_list = dom_obj.Tags.ToList<KeyValuePair<string, string>>();
                for (int idx = 0; idx < tags_list.Count; idx++)
                {
                    KeyValuePair<string, string> tag_pair = tags_list[idx];
                    tag t = new tag();
                    t.k = tag_pair.Key;
                    t.v = tag_pair.Value;
                    xml_obj.tag[idx] = t;
                }
            }

            // set the timestamp.
            if (dom_obj.TimeStamp.HasValue)
            {
                xml_obj.timestamp = dom_obj.TimeStamp.Value;
                xml_obj.timestampSpecified = true;
            }

            // set the user data.
            if (dom_obj.UserId.HasValue)
            {
                xml_obj.uid = dom_obj.UserId.Value;
                xml_obj.uidSpecified = true;
            }
            xml_obj.user = xml_obj.user;

            // set the version.
            if (dom_obj.Version.HasValue)
            {
                xml_obj.version = (ulong)dom_obj.Version.Value;
                xml_obj.versionSpecified = true;
            }

            // set the visible.
            xml_obj.visible = dom_obj.Visible;
            xml_obj.visibleSpecified = true;

            // set the way-specific properties.
            xml_obj.member = new member[dom_obj.Members.Count];
            for (int idx = 0; idx < dom_obj.Members.Count; idx++)
            {
                RelationMember dom_member = dom_obj.Members[idx];
                member m = new member();

                switch(dom_member.Member.Type)
                {
                    case OsmType.Node:
                        m.type = memberType.node;
                        m.typeSpecified = true;
                        break;
                    case OsmType.Relation:
                        m.type = memberType.relation;
                        m.typeSpecified = true;
                        break;
                    case OsmType.Way:
                        m.type = memberType.way;
                        m.typeSpecified = true;
                        break;
                }

                m.@ref = dom_member.Member.Id;
                m.refSpecified = true;
                m.role = dom_member.Role;

                xml_obj.member[idx] = m;
            }

            return xml_obj;
        }