Example #1
0
        internal static ChangeSet ConvertToSimple(delete delete)
        {
            ChangeSet changeSet = new ChangeSet();
            Change    change    = new Change();

            change.Type   = ChangeType.Delete;
            change.OsmGeo = new List <OsmGeo>();
            if (delete.relation != null)
            {
                foreach (relation re in delete.relation)
                {
                    change.OsmGeo.Add((OsmGeo)XmlSimpleConverter.ConvertToSimple(re));
                }
            }
            if (delete.way != null)
            {
                foreach (way wa in delete.way)
                {
                    change.OsmGeo.Add((OsmGeo)XmlSimpleConverter.ConvertToSimple(wa));
                }
            }
            if (delete.node != null)
            {
                foreach (node nd in delete.node)
                {
                    change.OsmGeo.Add((OsmGeo)XmlSimpleConverter.ConvertToSimple(nd));
                }
            }
            changeSet.Changes = new List <Change>();
            changeSet.Changes.Add(change);
            return(changeSet);
        }
Example #2
0
        /// <summary>
        /// Move to the next item in the stream.
        /// </summary>
        /// <param name="ignoreNodes">Makes this source skip all nodes.</param>
        /// <param name="ignoreWays">Makes this source skip all ways.</param>
        /// <param name="ignoreRelations">Makes this source skip all relations.</param>
        /// <returns></returns>
        public override bool MoveNext(bool ignoreNodes, bool ignoreWays, bool ignoreRelations)
        {
            while (_reader.Read())
            {
                if (_reader.NodeType == XmlNodeType.Element &&
                    (_reader.Name == "node" && !ignoreNodes) ||
                    (_reader.Name == "way" && !ignoreWays) ||
                    (_reader.Name == "relation" && !ignoreRelations))
                {
                    // create a stream for only this element.
                    string    name        = _reader.Name;
                    string    nextElement = _reader.ReadOuterXml();
                    XmlReader reader      = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(nextElement)));
                    object    osmObj      = null;

                    // select type of element.
                    switch (name)
                    {
                    case "node":
                        osmObj = _serNode.Deserialize(reader);
                        if (osmObj is OsmSharp.Osm.Xml.v0_6.node)
                        {
                            _next = XmlSimpleConverter.ConvertToSimple(osmObj as OsmSharp.Osm.Xml.v0_6.node);
                            return(true);
                        }
                        break;

                    case "way":
                        osmObj = _serWay.Deserialize(reader);
                        if (osmObj is OsmSharp.Osm.Xml.v0_6.way)
                        {
                            _next = XmlSimpleConverter.ConvertToSimple(osmObj as OsmSharp.Osm.Xml.v0_6.way);
                            return(true);
                        }
                        break;

                    case "relation":
                        osmObj = _serRelation.Deserialize(reader);
                        if (osmObj is OsmSharp.Osm.Xml.v0_6.relation)
                        {
                            _next = XmlSimpleConverter.ConvertToSimple(osmObj as OsmSharp.Osm.Xml.v0_6.relation);
                            return(true);
                        }
                        break;
                    }
                }
            }
            _next = null;
            return(false);
        }
Example #3
0
 public override bool MoveNext(bool ignoreNodes, bool ignoreWays, bool ignoreRelations)
 {
     while (this._reader.Read())
     {
         if (this._reader.NodeType == XmlNodeType.Element && this._reader.Name == "node" && !ignoreNodes || (this._reader.Name == "way" && !ignoreWays || this._reader.Name == "relation" && !ignoreRelations))
         {
             string    name      = this._reader.Name;
             XmlReader xmlReader = XmlReader.Create((Stream) new MemoryStream(Encoding.UTF8.GetBytes(this._reader.ReadOuterXml())));
             if (!(name == "node"))
             {
                 if (!(name == "way"))
                 {
                     if (name == "relation")
                     {
                         object obj = this._serRelation.Deserialize(xmlReader);
                         if (obj is relation)
                         {
                             this._next = (OsmGeo)XmlSimpleConverter.ConvertToSimple(obj as relation);
                             return(true);
                         }
                     }
                 }
                 else
                 {
                     object obj = this._serWay.Deserialize(xmlReader);
                     if (obj is way)
                     {
                         this._next = (OsmGeo)XmlSimpleConverter.ConvertToSimple(obj as way);
                         return(true);
                     }
                 }
             }
             else
             {
                 object obj = this._serNode.Deserialize(xmlReader);
                 if (obj is node)
                 {
                     this._next = (OsmGeo)XmlSimpleConverter.ConvertToSimple(obj as node);
                     return(true);
                 }
             }
         }
     }
     this._next = (OsmGeo)null;
     return(false);
 }
Example #4
0
        internal static ChangeSet ConvertToSimple(Osm.Xml.v0_6.delete delete)
        {
            // create change set record.
            OsmSharp.Osm.ChangeSet change_set = new OsmSharp.Osm.ChangeSet();

            // create change record.
            OsmSharp.Osm.Change change = new OsmSharp.Osm.Change();
            change.Type   = OsmSharp.Osm.ChangeType.Delete;
            change.OsmGeo = new List <OsmGeo>();

            // add all relations to the list.
            if (delete.relation != null)
            {
                foreach (Osm.Xml.v0_6.relation osm_geo in delete.relation)
                {
                    change.OsmGeo.Add(XmlSimpleConverter.ConvertToSimple(osm_geo));
                }
            }

            // add all ways to the list.
            if (delete.way != null)
            {
                foreach (Osm.Xml.v0_6.way osm_geo in delete.way)
                {
                    change.OsmGeo.Add(XmlSimpleConverter.ConvertToSimple(osm_geo));
                }
            }

            // add all nodes to the list.
            if (delete.node != null)
            {
                foreach (Osm.Xml.v0_6.node osm_geo in delete.node)
                {
                    change.OsmGeo.Add(XmlSimpleConverter.ConvertToSimple(osm_geo));
                }
            }


            // add change to changeset
            change_set.Changes = new List <Change>();
            change_set.Changes.Add(change);

            return(change_set);
        }