当前位置: 首页>>代码示例>>C#>>正文


C# Relation.ConvertTo方法代码示例

本文整理汇总了C#中Relation.ConvertTo方法的典型用法代码示例。如果您正苦于以下问题:C# Relation.ConvertTo方法的具体用法?C# Relation.ConvertTo怎么用?C# Relation.ConvertTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Relation的用法示例。


在下文中一共展示了Relation.ConvertTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RelationUpdate

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

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

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

            // 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/relation/{0}", relation.Id.Value),
                Method.PUT, put_data);
        }
开发者ID:UnifyKit,项目名称:OsmSharp,代码行数:38,代码来源:APIConnection.cs

示例2: RelationCreate

        /// <summary>
        /// Creates a new relation.
        /// </summary>
        /// <param name="relation"></param>
        /// <returns></returns>
        public Relation RelationCreate(Relation relation)
        {
            if (_current_changeset == null)
            {
                throw new InvalidOperationException("No open changeset found!");
            }

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

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

            // 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/relation/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 relation: {0}", response_string));
            }
            relation.Id = id;
            return relation;
        }
开发者ID:UnifyKit,项目名称:OsmSharp,代码行数:44,代码来源:APIConnection.cs


注:本文中的Relation.ConvertTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。