當前位置: 首頁>>代碼示例>>C#>>正文


C# Way.ConvertTo方法代碼示例

本文整理匯總了C#中OsmSharp.Osm.Way.ConvertTo方法的典型用法代碼示例。如果您正苦於以下問題:C# Way.ConvertTo方法的具體用法?C# Way.ConvertTo怎麽用?C# Way.ConvertTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OsmSharp.Osm.Way的用法示例。


在下文中一共展示了Way.ConvertTo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: WayUpdate

        /// <summary>
        /// Updates the given way by adding it's changes to the current changeset.
        /// </summary>
        /// <param name="way"></param>
        public void WayUpdate(Way way)
        {
            if (_current_changeset == null)
            {
                throw new InvalidOperationException("No open changeset found!");
            }
            if (!way.Id.HasValue)
            {
                throw new ArgumentOutOfRangeException("Cannot update an object without an id!");
            }

            // build a new node.
            way xml_way = way.ConvertTo();
            xml_way.changeset = _current_changeset.id;
            xml_way.changesetSpecified = true;

            // encapsulate into an osm object.
            OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm();
            osm.way = new Osm.Xml.v0_6.way[1];
            osm.way[0] = xml_way;

            // serialize the changeset.
            XmlSerializer serializer = new XmlSerializer(typeof(OsmSharp.Osm.Xml.v0_6.osm));
            MemoryStream mem_stream = new MemoryStream();
            Stream stream = mem_stream;
            serializer.Serialize(stream, osm);
            stream.Flush();
            mem_stream.Flush();
            byte[] put_data = mem_stream.ToArray();

            // do the api call.
            this.DoApiCall(true, string.Format("api/0.6/way/{0}", way.Id.Value),
                Method.PUT, put_data);
        }
開發者ID:vcotlearov,項目名稱:OsmSharp,代碼行數:38,代碼來源:APIConnection.cs

示例2: WayCreate

        /// <summary>
        /// Creates a new way by adding it to the current changeset.
        /// </summary>
        /// <param name="way"></param>
        public Way WayCreate(Way way)
        {
            if (_current_changeset == null)
            {
                throw new InvalidOperationException("No open changeset found!");
            }

            // build a new node.
            way xml_way = way.ConvertTo();
            xml_way.changeset = _current_changeset.id;
            xml_way.changesetSpecified = true;

            // encapsulate into an osm object.
            OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm();
            osm.way = new Osm.Xml.v0_6.way[1];
            osm.way[0] = xml_way;

            // serialize the changeset.
            XmlSerializer serializer = new XmlSerializer(typeof(OsmSharp.Osm.Xml.v0_6.osm));
            MemoryStream mem_stream = new MemoryStream();
            Stream stream = mem_stream;
            serializer.Serialize(stream, osm);
            stream.Flush();
            mem_stream.Flush();
            byte[] put_data = mem_stream.ToArray();

            // do the api call.
            string response_string = this.DoApiCall(true, "api/0.6/way/create",
                Method.PUT, put_data);

            // get the id-response.
            long id;
            if (!long.TryParse(response_string, out id))
            { // invalid response!
                throw new APIException(string.Format("Invalid response when creating a new way: {0}", response_string));
            }
            way.Id = id;
            return way;
        }
開發者ID:vcotlearov,項目名稱:OsmSharp,代碼行數:43,代碼來源:APIConnection.cs


注:本文中的OsmSharp.Osm.Way.ConvertTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。