Beispiel #1
0
        /// <summary>
        /// Converts an Xml way to an Osm domain model way.
        /// </summary>
        /// <returns></returns>
        public static Way ConvertFrom(this way xmlWay)
        {
            // create a new node and immidiately set the id.
            var way = new Way();

            way.Id = xmlWay.id;

            // set the nodes.
            way.Nodes = new List <long>(xmlWay.nd.Length);
            for (int i = 0; i < xmlWay.nd.Length; i++)
            {
                var xmlNode = xmlWay.nd[i];
                if (xmlNode.refSpecified)
                {
                    way.Nodes.Add(xmlNode.@ref);
                }
                else
                { // way cannot be converted; node was not found!
                    return(null);
                }
            }

            // set the tags.
            if (xmlWay.tag != null)
            {
                foreach (var tag in xmlWay.tag)
                {
                    way.Tags.Add(tag.k, tag.v);
                }
            }

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

            // set the changeset info.
            if (xmlWay.changesetSpecified)
            {
                way.ChangeSetId = xmlWay.changeset;
            }

            // set the timestamp flag.
            if (xmlWay.timestampSpecified)
            {
                way.TimeStamp = xmlWay.timestamp;
            }

            // set the visible flag.
            way.Visible = xmlWay.visible;
            return(way);
        }
Beispiel #2
0
        /// <summary>
        /// Converts an Xml way to an Osm domain model way.
        /// </summary>
        /// <param name="xml_obj"></param>
        /// <returns></returns>
        public static Way ConvertFrom(this way xml_obj)
        {
            // create a new node and immidiately set the id.
            Way new_obj = new Way();

            new_obj.Id = xml_obj.id;

            // set the nodes.
            new_obj.Nodes = new List <long>(xml_obj.nd.Length);
            for (int idx = 0; idx < xml_obj.nd.Length; idx++)
            {
                nd node = xml_obj.nd[idx];
                if (node.refSpecified)
                {
                    new_obj.Nodes.Add(node.@ref);
                }
                else
                { // way cannot be converted; node was not found!
                    return(null);
                }
            }

            // 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);
        }
Beispiel #3
0
        public static Way ConvertFrom(this way xmlWay)
        {
            Way way = new Way();

            way.Id    = new long?(xmlWay.id);
            way.Nodes = new List <long>(xmlWay.nd.Length);
            for (int index = 0; index < xmlWay.nd.Length; ++index)
            {
                nd nd = xmlWay.nd[index];
                if (!nd.refSpecified)
                {
                    return((Way)null);
                }
                way.Nodes.Add(nd.@ref);
            }
            if (xmlWay.tag != null)
            {
                way.Tags = (TagsCollectionBase) new TagsCollection();
                foreach (tag tag in xmlWay.tag)
                {
                    way.Tags.Add(tag.k, tag.v);
                }
            }
            if (xmlWay.uidSpecified)
            {
                way.UserId = new long?(xmlWay.uid);
            }
            way.UserName = xmlWay.user;
            if (xmlWay.changesetSpecified)
            {
                way.ChangeSetId = new long?(xmlWay.changeset);
            }
            if (xmlWay.timestampSpecified)
            {
                way.TimeStamp = new DateTime?(xmlWay.timestamp);
            }
            if (xmlWay.versionSpecified)
            {
                way.Version = new ulong?(xmlWay.version);
            }
            way.Visible = new bool?(xmlWay.visible);
            return(way);
        }
        /// <summary>
        /// Converts a domain model way to an Xml way.
        /// </summary>
        /// <param name="way"></param>
        /// <returns></returns>
        public static way ConvertTo(this OsmSharp.Osm.Way way)
        {
            way xmlWay = new way();

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

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

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

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

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

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

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

            // set the way-specific properties.
            xmlWay.nd = new nd[way.Nodes.Count];
            for (int i = 0; i < way.Nodes.Count; i++)
            {
                var n = new nd();
                n.@ref         = way.Nodes[i];
                n.refSpecified = true;
                xmlWay.nd[i]   = n;
            }

            return(xmlWay);
        }
Beispiel #5
0
        /// <summary>
        /// Converts an API v6 xml node to a SimpleWay object.
        /// </summary>
        /// <param name="xml_way"></param>
        /// <returns></returns>
        private Way Convertv6XmlWay(way xml_way)
        {
            Way way = new Way();
            way.Id = xml_way.id;

            if (xml_way.tag != null)
            {
                way.Tags = new TagsCollection();
                foreach (Osm.Xml.v0_6.tag xml_tag in xml_way.tag)
                {
                    way.Tags.Add(xml_tag.k, xml_tag.v);
                }
            }

            if (xml_way.nd != null)
            {
                way.Nodes = new List<long>();
                foreach (Osm.Xml.v0_6.nd xml_nd in xml_way.nd)
                {
                    way.Nodes.Add(xml_nd.@ref);
                }
            }

            way.ChangeSetId = xml_way.changeset;
            way.TimeStamp = xml_way.timestamp;
            way.UserName = xml_way.user;
            way.UserId = xml_way.uid;
            way.Version = xml_way.version;
            way.Visible = xml_way.visible;

            return way;
        }
Beispiel #6
0
        /// <summary>
        /// Converts a domain model way to an Xml way.
        /// </summary>
        /// <param name="dom_obj"></param>
        /// <returns></returns>
        public static way ConvertTo(this OsmSharp.Osm.Way dom_obj)
        {
            way xml_obj = new way();

            // 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.nd = new nd[dom_obj.Nodes.Count];
            for (int idx = 0; idx < dom_obj.Nodes.Count; idx++)
            {
                nd n = new nd();
                n.@ref          = dom_obj.Nodes[idx];
                n.refSpecified  = true;
                xml_obj.nd[idx] = n;
            }

            return(xml_obj);
        }
Beispiel #7
0
        public static way ConvertTo(this Way way)
        {
            way  way1 = new way();
            long?nullable;

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

            if (version.HasValue)
            {
                way way2 = way1;
                version = way.Version;
                long num = (long)version.Value;
                way2.version          = (ulong)num;
                way1.versionSpecified = true;
            }
            if (way.Visible.HasValue)
            {
                way1.visible          = way.Visible.Value;
                way1.visibleSpecified = true;
            }
            else
            {
                way1.visibleSpecified = false;
            }
            way1.nd = new nd[way.Nodes.Count];
            for (int index = 0; index < way.Nodes.Count; ++index)
            {
                way1.nd[index] = new nd()
                {
                    @ref         = way.Nodes[index],
                    refSpecified = true
                }
            }
            ;
            return(way1);
        }
Beispiel #8
0
        /// <summary>
        /// Converts a domain model way to an Xml way.
        /// </summary>
        /// <param name="dom_obj"></param>
        /// <returns></returns>
        public static way ConvertTo(this OsmSharp.Osm.Way dom_obj)
        {
            way xml_obj = new way();

            // 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.nd = new nd[dom_obj.Nodes.Count];
            for (int idx = 0; idx < dom_obj.Nodes.Count; idx++)
            {
                nd n = new nd();
                n.@ref = dom_obj.Nodes[idx];
                n.refSpecified = true;
                xml_obj.nd[idx] = n;
            }

            return xml_obj;
        }
Beispiel #9
0
        /// <summary>
        /// Converts a domain model way to an Xml way.
        /// </summary>
        /// <param name="dom_obj"></param>
        /// <returns></returns>
        public static way ConvertTo(this Way dom_obj)
        {
            way xml_obj = new way();

            // 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.nd = new nd[dom_obj.Nodes.Count];
            for(int idx = 0;idx < dom_obj.Nodes.Count;idx++)
            {
                nd n = new nd();
                n.@ref =  dom_obj.Nodes[idx].Id;
                n.refSpecified = true;
                xml_obj.nd[idx] = n;
            }

            return xml_obj;
        }
Beispiel #10
0
        /// <summary>
        /// Converts a domain model way to an Xml way.
        /// </summary>
        /// <param name="way"></param>
        /// <returns></returns>
        public static way ConvertTo(this OsmSharp.Osm.Way way)
        {
            way xmlWay = new way();

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

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

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

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

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

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

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

            // set the way-specific properties.
            xmlWay.nd = new nd[way.Nodes.Count];
            for (int i = 0; i < way.Nodes.Count; i++)
            {
                var n = new nd();
                n.@ref = way.Nodes[i];
                n.refSpecified = true;
                xmlWay.nd[i] = n;
            }

            return xmlWay;
        }