コード例 #1
0
        /// <summary>
        /// Adds a relation to this target.
        /// </summary>
        /// <param name="simpleRelation"></param>
        public override void AddRelation(Relation simpleRelation)
        {
            var re = new OsmSharp.Osm.Xml.v0_6.relation();

            re.idSpecified = false;
            if (simpleRelation.Id.HasValue)
            {
                re.idSpecified = true;
                re.id          = simpleRelation.Id.Value;
            }

            // set changeset.
            re.changesetSpecified = false;
            if (simpleRelation.ChangeSetId.HasValue)
            {
                re.changeset          = simpleRelation.ChangeSetId.Value;
                re.changesetSpecified = true;
            }

            // set visible.
            re.visibleSpecified = false;
            if (simpleRelation.Visible.HasValue)
            {
                re.visible          = simpleRelation.Visible.Value;
                re.visibleSpecified = true;
            }

            // set timestamp.
            re.timestampSpecified = false;
            if (simpleRelation.TimeStamp.HasValue)
            {
                re.timestamp          = simpleRelation.TimeStamp.Value;
                re.timestampSpecified = true;
            }

            // set uid
            re.uidSpecified = false;
            if (simpleRelation.UserId.HasValue)
            {
                re.uid          = simpleRelation.UserId.Value;
                re.uidSpecified = true;
            }

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

            // set tags.
            re.tag = this.ConvertToXmlTags(simpleRelation.Tags);

            // set members.
            if (simpleRelation.Members != null)
            {
                re.member = new OsmSharp.Osm.Xml.v0_6.member[simpleRelation.Members.Count];
                for (int idx = 0; idx < simpleRelation.Members.Count; idx++)
                {
                    var            mem         = new OsmSharp.Osm.Xml.v0_6.member();
                    RelationMember memberToAdd = simpleRelation.Members[idx];

                    // set memberid
                    mem.refSpecified = false;
                    if (memberToAdd.MemberId.HasValue)
                    {
                        mem.@ref         = memberToAdd.MemberId.Value;
                        mem.refSpecified = true;
                    }

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

                        case OsmGeoType.Way:
                            mem.type = OsmSharp.Osm.Xml.v0_6.memberType.way;
                            break;

                        case OsmGeoType.Relation:
                            mem.type = OsmSharp.Osm.Xml.v0_6.memberType.relation;
                            break;
                        }
                        mem.typeSpecified = true;
                    }

                    mem.role = memberToAdd.MemberRole;

                    re.member[idx] = mem;
                }
            }

            // set version.
            if (simpleRelation.Version.HasValue)
            {
                re.version          = simpleRelation.Version.Value;
                re.versionSpecified = true;
            }

            // serialize relation.
            _serRelation.Serialize(_writer, re);
            _writer.Flush();
            _textWriter.Write(_textWriter.NewLine);
        }
コード例 #2
0
        /// <summary>
        /// Adds a relation to this target.
        /// </summary>
        /// <param name="simpleRelation"></param>
        public override void AddRelation(Relation simpleRelation)
        {
            var re = new OsmSharp.Osm.Xml.v0_6.relation();

            re.idSpecified = false;
            if (simpleRelation.Id.HasValue)
            {
                re.idSpecified = true;
                re.id = simpleRelation.Id.Value;
            }

            // set changeset.
            re.changesetSpecified = false;
            if (simpleRelation.ChangeSetId.HasValue)
            {
                re.changeset = simpleRelation.ChangeSetId.Value;
                re.changesetSpecified = true;
            }

            // set visible.
            re.visibleSpecified = false;
            if (simpleRelation.Visible.HasValue)
            {
                re.visible = simpleRelation.Visible.Value;
                re.visibleSpecified = true;
            }

            // set timestamp.
            re.timestampSpecified = false;
            if (simpleRelation.TimeStamp.HasValue)
            {
                re.timestamp = simpleRelation.TimeStamp.Value;
                re.timestampSpecified = true;
            }

            // set uid
            re.uidSpecified = false;
            if (simpleRelation.UserId.HasValue)
            {
                re.uid = simpleRelation.UserId.Value;
                re.uidSpecified = true;
            }

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

            // set tags.
            re.tag = this.ConvertToXmlTags(simpleRelation.Tags);

            // set members.
            if (simpleRelation.Members != null)
            {
                re.member = new OsmSharp.Osm.Xml.v0_6.member[simpleRelation.Members.Count];
                for (int idx = 0; idx < simpleRelation.Members.Count; idx++)
                {
                    var mem = new OsmSharp.Osm.Xml.v0_6.member();
                    RelationMember memberToAdd = simpleRelation.Members[idx];

                    // set memberid
                    mem.refSpecified = false;
                    if (memberToAdd.MemberId.HasValue)
                    {
                        mem.@ref = memberToAdd.MemberId.Value;
                        mem.refSpecified = true;
                    }

                    // set type
                    mem.typeSpecified = false;
                    if (memberToAdd.MemberType.HasValue)
                    {
                        switch (memberToAdd.MemberType.Value)
                        {
                            case OsmGeoType.Node:
                                mem.type = OsmSharp.Osm.Xml.v0_6.memberType.node;
                                break;
                            case OsmGeoType.Way:
                                mem.type = OsmSharp.Osm.Xml.v0_6.memberType.way;
                                break;
                            case OsmGeoType.Relation:
                                mem.type = OsmSharp.Osm.Xml.v0_6.memberType.relation;
                                break;
                        }
                        mem.typeSpecified = true;
                    }

                    mem.role = memberToAdd.MemberRole;

                    re.member[idx] = mem;
                }
            }

            // set version.
            if (simpleRelation.Version.HasValue)
            {
                re.version = simpleRelation.Version.Value;
                re.versionSpecified = true;
            }

            XmlSerializerNamespaces emptyNamespace = new XmlSerializerNamespaces();
            emptyNamespace.Add(String.Empty, String.Empty);

            // serialize node.
            var memoryStream = new MemoryStream();
            XmlWriter writer = XmlWriter.Create(memoryStream, _settings);
            var serRel = new XmlSerializer(typeof(Osm.Xml.v0_6.relation), string.Empty);
            serRel.Serialize(writer, re, emptyNamespace);
            memoryStream.WriteTo(_stream);
            _stream.Flush();
            _streamWriter.WriteLine();
            _streamWriter.Flush();
        }
コード例 #3
0
        /// <summary>
        /// Adds a relation to this target.
        /// </summary>
        /// <param name="simpleRelation"></param>
        public override void AddRelation(Relation simpleRelation)
        {
            var re = new OsmSharp.Osm.Xml.v0_6.relation();

            re.idSpecified = false;
            if (simpleRelation.Id.HasValue)
            {
                re.idSpecified = true;
                re.id          = simpleRelation.Id.Value;
            }

            // set changeset.
            re.changesetSpecified = false;
            if (simpleRelation.ChangeSetId.HasValue)
            {
                re.changeset          = simpleRelation.ChangeSetId.Value;
                re.changesetSpecified = true;
            }

            // set visible.
            re.visibleSpecified = false;
            if (simpleRelation.Visible.HasValue)
            {
                re.visible          = simpleRelation.Visible.Value;
                re.visibleSpecified = true;
            }

            // set timestamp.
            re.timestampSpecified = false;
            if (simpleRelation.TimeStamp.HasValue)
            {
                re.timestamp          = simpleRelation.TimeStamp.Value;
                re.timestampSpecified = true;
            }

            // set uid
            re.uidSpecified = false;
            if (simpleRelation.UserId.HasValue)
            {
                re.uid          = simpleRelation.UserId.Value;
                re.uidSpecified = true;
            }

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

            // set tags.
            re.tag = this.ConvertToXmlTags(simpleRelation.Tags);

            // set members.
            if (simpleRelation.Members != null)
            {
                re.member = new OsmSharp.Osm.Xml.v0_6.member[simpleRelation.Members.Count];
                for (int idx = 0; idx < simpleRelation.Members.Count; idx++)
                {
                    var            mem         = new OsmSharp.Osm.Xml.v0_6.member();
                    RelationMember memberToAdd = simpleRelation.Members[idx];

                    // set memberid
                    mem.refSpecified = false;
                    if (memberToAdd.MemberId.HasValue)
                    {
                        mem.@ref         = memberToAdd.MemberId.Value;
                        mem.refSpecified = true;
                    }

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

                        case OsmGeoType.Way:
                            mem.type = OsmSharp.Osm.Xml.v0_6.memberType.way;
                            break;

                        case OsmGeoType.Relation:
                            mem.type = OsmSharp.Osm.Xml.v0_6.memberType.relation;
                            break;
                        }
                        mem.typeSpecified = true;
                    }

                    mem.role = memberToAdd.MemberRole;

                    re.member[idx] = mem;
                }
            }

            // set version.
            if (simpleRelation.Version.HasValue)
            {
                re.version          = simpleRelation.Version.Value;
                re.versionSpecified = true;
            }

            XmlSerializerNamespaces emptyNamespace = new XmlSerializerNamespaces();

            emptyNamespace.Add(String.Empty, String.Empty);

            // serialize node.
            var       memoryStream = new MemoryStream();
            XmlWriter writer       = XmlWriter.Create(memoryStream, _settings);
            var       serRel       = new XmlSerializer(typeof(Osm.Xml.v0_6.relation), string.Empty);

            serRel.Serialize(writer, re, emptyNamespace);
            memoryStream.WriteTo(_stream);
            _stream.Flush();
            _streamWriter.WriteLine();
            _streamWriter.Flush();
        }
コード例 #4
0
        /// <summary>
        /// Adds a relation to this target.
        /// </summary>
        /// <param name="simpleRelation"></param>
        public override void AddRelation(Relation simpleRelation)
        {
            var re = new OsmSharp.Osm.Xml.v0_6.relation();

            re.idSpecified = false;
            if (simpleRelation.Id.HasValue)
            {
                re.idSpecified = true;
                re.id = simpleRelation.Id.Value;
            }

            // set changeset.
            re.changesetSpecified = false;
            if (simpleRelation.ChangeSetId.HasValue)
            {
                re.changeset = simpleRelation.ChangeSetId.Value;
                re.changesetSpecified = true;
            }

            // set visible.
            re.visibleSpecified = false;
            if (simpleRelation.Visible.HasValue)
            {
                re.visible = simpleRelation.Visible.Value;
                re.visibleSpecified = true;
            }

            // set timestamp.
            re.timestampSpecified = false;
            if (simpleRelation.TimeStamp.HasValue)
            {
                re.timestamp = simpleRelation.TimeStamp.Value;
                re.timestampSpecified = true;
            }

            // set uid
            re.uidSpecified = false;
            if (simpleRelation.UserId.HasValue)
            {
                re.uid = simpleRelation.UserId.Value;
                re.uidSpecified = true;
            }

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

            // set tags.
            re.tag = this.ConvertToXmlTags(simpleRelation.Tags);

            // set members.
            if (simpleRelation.Members != null)
            {
                re.member = new OsmSharp.Osm.Xml.v0_6.member[simpleRelation.Members.Count];
                for (int idx = 0; idx < simpleRelation.Members.Count; idx++)
                {
                    var mem = new OsmSharp.Osm.Xml.v0_6.member();
                    RelationMember memberToAdd = simpleRelation.Members[idx];

                    // set memberid
                    mem.refSpecified = false;
                    if (memberToAdd.MemberId.HasValue)
                    {
                        mem.@ref = memberToAdd.MemberId.Value;
                        mem.refSpecified = true;
                    }

                    // set type
                    mem.typeSpecified = false;
                    if (memberToAdd.MemberType.HasValue)
                    {
                        switch (memberToAdd.MemberType.Value)
                        {
                            case OsmGeoType.Node:
                                mem.type = OsmSharp.Osm.Xml.v0_6.memberType.node;
                                break;
                            case OsmGeoType.Way:
                                mem.type = OsmSharp.Osm.Xml.v0_6.memberType.way;
                                break;
                            case OsmGeoType.Relation:
                                mem.type = OsmSharp.Osm.Xml.v0_6.memberType.relation;
                                break;
                        }
                        mem.typeSpecified = true;
                    }

                    mem.role = memberToAdd.MemberRole;

                    re.member[idx] = mem;
                }
            }

            // set version.
            if (simpleRelation.Version.HasValue)
            {
                re.version = simpleRelation.Version.Value;
                re.versionSpecified = true;
            }

            // serialize relation.
            _serRelation.Serialize(_writer, re);
            _writer.Flush();
            _textWriter.Write(_textWriter.NewLine);
        }