/// <summary> /// Modifies a the given node by adding it's modification to the current changeset. /// </summary> /// <param name="node"></param> public void NodeUpdate(Node node) { if (_current_changeset == null) { throw new InvalidOperationException("No open changeset found!"); } if (!node.Id.HasValue) { throw new ArgumentOutOfRangeException("Cannot update an object without an id!"); } // build a new node. node xml_node = node.ConvertTo(); xml_node.changeset = _current_changeset.id; xml_node.changesetSpecified = true; // encapsulate into an osm object. OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm(); osm.node = new Osm.Xml.v0_6.node[1]; osm.node[0] = xml_node; // 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/node/{0}", node.Id.Value), Method.PUT, put_data); }
/// <summary> /// Creates a new node by adding it's creation to the current changeset. /// </summary> /// <param name="node"></param> public Node NodeCreate(Node node) { if (_current_changeset == null) { throw new InvalidOperationException("No open changeset found!"); } // build a new node. node xml_node = node.ConvertTo(); xml_node.changeset = _current_changeset.id; xml_node.changesetSpecified = true; // encapsulate into an osm object. OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm(); osm.node = new Osm.Xml.v0_6.node[1]; osm.node[0] = xml_node; // 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/node/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 node: {0}", response_string)); } node.Id = id; return node; }