Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
 }
Exemplo n.º 4
0
        internal static Way ConvertToSimple(way wa)
        {
            Way way = new Way();

            if (wa.idSpecified)
            {
                way.Id = new long?(wa.id);
            }
            if (wa.changesetSpecified)
            {
                way.ChangeSetId = new long?(wa.changeset);
            }
            if (wa.visibleSpecified)
            {
                way.Visible = new bool?(wa.visible);
            }
            else
            {
                way.Visible = new bool?(true);
            }
            if (wa.timestampSpecified)
            {
                way.TimeStamp = new DateTime?(wa.timestamp);
            }
            if (wa.uidSpecified)
            {
                way.UserId = new long?(wa.uid);
            }
            if (wa.versionSpecified)
            {
                way.Version = new ulong?(wa.version);
            }
            way.UserName = wa.user;
            way.Tags     = XmlSimpleConverter.ConvertToTags(wa.tag);
            if (wa.nd != null && wa.nd.Length != 0)
            {
                way.Nodes = new List <long>();
                for (int index = 0; index < wa.nd.Length; ++index)
                {
                    way.Nodes.Add(wa.nd[index].@ref);
                }
            }
            return(way);
        }
Exemplo n.º 5
0
        internal static Node ConvertToSimple(node nd)
        {
            Node node = new Node();

            if (nd.idSpecified)
            {
                node.Id = new long?(nd.id);
            }
            if (nd.changesetSpecified)
            {
                node.ChangeSetId = new long?(nd.changeset);
            }
            if (nd.visibleSpecified)
            {
                node.Visible = new bool?(nd.visible);
            }
            else
            {
                node.Visible = new bool?(true);
            }
            if (nd.timestampSpecified)
            {
                node.TimeStamp = new DateTime?(nd.timestamp);
            }
            if (nd.latSpecified)
            {
                node.Latitude = new double?(nd.lat);
            }
            if (nd.lonSpecified)
            {
                node.Longitude = new double?(nd.lon);
            }
            if (nd.uidSpecified)
            {
                node.UserId = new long?(nd.uid);
            }
            if (nd.versionSpecified)
            {
                node.Version = new ulong?(nd.version);
            }
            node.UserName = nd.user;
            node.Tags     = XmlSimpleConverter.ConvertToTags(nd.tag);
            return(node);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        internal static Relation ConvertToSimple(relation re)
        {
            Relation relation = new Relation();

            if (re.idSpecified)
            {
                relation.Id = new long?(re.id);
            }
            if (re.changesetSpecified)
            {
                relation.ChangeSetId = new long?(re.changeset);
            }
            if (re.visibleSpecified)
            {
                relation.Visible = new bool?(re.visible);
            }
            else
            {
                relation.Visible = new bool?(true);
            }
            if (re.timestampSpecified)
            {
                relation.TimeStamp = new DateTime?(re.timestamp);
            }
            if (re.uidSpecified)
            {
                relation.UserId = new long?(re.uid);
            }
            if (re.versionSpecified)
            {
                relation.Version = new ulong?(re.version);
            }
            relation.UserName = re.user;
            relation.Tags     = XmlSimpleConverter.ConvertToTags(re.tag);
            if (re.member != null && re.member.Length != 0)
            {
                relation.Members = new List <RelationMember>();
                for (int index = 0; index < re.member.Length; ++index)
                {
                    member         member         = re.member[index];
                    RelationMember relationMember = new RelationMember();
                    if (member.refSpecified)
                    {
                        relationMember.MemberId = new long?(member.@ref);
                    }
                    relationMember.MemberRole = member.role;
                    if (member.typeSpecified)
                    {
                        switch (member.type)
                        {
                        case memberType.node:
                            relationMember.MemberType = new OsmGeoType?(OsmGeoType.Node);
                            break;

                        case memberType.way:
                            relationMember.MemberType = new OsmGeoType?(OsmGeoType.Way);
                            break;

                        case memberType.relation:
                            relationMember.MemberType = new OsmGeoType?(OsmGeoType.Relation);
                            break;
                        }
                    }
                    relation.Members.Add(relationMember);
                }
            }
            return(relation);
        }
Exemplo n.º 8
0
        internal static Relation ConvertToSimple(Osm.Xml.v0_6.relation re)
        {
            Relation relation = new Relation();

            // set id
            if (re.idSpecified)
            {
                relation.Id = re.id;
            }

            // set changeset.
            if (re.changesetSpecified)
            {
                relation.ChangeSetId = re.changeset;
            }

            // set visible.
            if (re.visibleSpecified)
            {
                relation.Visible = re.visible;
            }
            else
            { // if visible is not specified it is default true.
                relation.Visible = true;
            }

            // set timestamp.
            if (re.timestampSpecified)
            {
                relation.TimeStamp = re.timestamp;
            }

            // set uid
            if (re.uidSpecified)
            {
                relation.UserId = re.uid;
            }

            // set version
            if (re.versionSpecified)
            {
                relation.Version = re.version;
            }

            // set user
            relation.UserName = re.user;

            // set tags.
            relation.Tags = XmlSimpleConverter.ConvertToTags(re.tag);

            // set members.
            if (re.member != null && re.member.Length > 0)
            {
                relation.Members = new List <RelationMember>();
                for (int idx = 0; idx < re.member.Length; idx++)
                {
                    OsmSharp.Osm.Xml.v0_6.member mem = re.member[idx];
                    RelationMember relation_member   = new RelationMember();
                    // set memberid
                    if (mem.refSpecified)
                    {
                        relation_member.MemberId = mem.@ref;
                    }

                    // set role.
                    relation_member.MemberRole = mem.role;

                    // set type.
                    if (mem.typeSpecified)
                    {
                        switch (mem.type)
                        {
                        case OsmSharp.Osm.Xml.v0_6.memberType.node:
                            relation_member.MemberType = OsmGeoType.Node;
                            break;

                        case OsmSharp.Osm.Xml.v0_6.memberType.way:
                            relation_member.MemberType = OsmGeoType.Way;
                            break;

                        case OsmSharp.Osm.Xml.v0_6.memberType.relation:
                            relation_member.MemberType = OsmGeoType.Relation;
                            break;
                        }
                    }

                    relation.Members.Add(relation_member);
                }
            }

            return(relation);
        }
Exemplo n.º 9
0
        internal static Way ConvertToSimple(Osm.Xml.v0_6.way wa)
        {
            Way way = new Way();

            // set id
            if (wa.idSpecified)
            {
                way.Id = wa.id;
            }

            // set changeset.
            if (wa.changesetSpecified)
            {
                way.ChangeSetId = wa.changeset;
            }

            // set visible.
            if (wa.visibleSpecified)
            {
                way.Visible = wa.visible;
            }
            else
            { // if visible is not specified it is default true.
                way.Visible = true;
            }

            // set timestamp.
            if (wa.timestampSpecified)
            {
                way.TimeStamp = wa.timestamp;
            }

            // set uid
            if (wa.uidSpecified)
            {
                way.UserId = wa.uid;
            }

            // set version
            if (wa.versionSpecified)
            {
                way.Version = wa.version;
            }

            // set user
            way.UserName = wa.user;

            // set tags.
            way.Tags = XmlSimpleConverter.ConvertToTags(wa.tag);

            // set nodes.
            if (wa.nd != null && wa.nd.Length > 0)
            {
                way.Nodes = new List <long>();
                for (int idx = 0; idx < wa.nd.Length; idx++)
                {
                    way.Nodes.Add(wa.nd[idx].@ref);
                }
            }

            return(way);
        }
Exemplo n.º 10
0
        internal static Node ConvertToSimple(Osm.Xml.v0_6.node nd)
        {
            Node node = new Node();

            // set id
            if (nd.idSpecified)
            {
                node.Id = nd.id;
            }

            // set changeset.
            if (nd.changesetSpecified)
            {
                node.ChangeSetId = nd.changeset;
            }

            // set visible.
            if (nd.visibleSpecified)
            {
                node.Visible = nd.visible;
            }
            else
            { // if visible is not specified it is default true.
                node.Visible = true;
            }

            // set timestamp.
            if (nd.timestampSpecified)
            {
                node.TimeStamp = nd.timestamp;
            }

            // set latitude.
            if (nd.latSpecified)
            {
                node.Latitude = nd.lat;
            }

            // set longitude.
            if (nd.lonSpecified)
            {
                node.Longitude = nd.lon;
            }

            // set uid
            if (nd.uidSpecified)
            {
                node.UserId = nd.uid;
            }

            // set version
            if (nd.versionSpecified)
            {
                node.Version = nd.version;
            }

            // set user
            node.UserName = nd.user;

            // set tags.
            node.Tags = XmlSimpleConverter.ConvertToTags(nd.tag);

            return(node);
        }