Esempio n. 1
0
        /// <summary>
        /// Moves this source to the next object.
        /// </summary>
        /// <returns></returns>
        public override bool MoveNext()
        {
            while (_reader.Read())
            {
                if (_reader.NodeType == XmlNodeType.Element && (_reader.Name == "node" || _reader.Name == "way" || _reader.Name == "relation"))
                {
                    // 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);
        }
        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);
        }