Beispiel #1
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 #2
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 #3
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;
        }